Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Yes...sort of. Ruby lacks a reasonable construct to enforce immutability. (<code>Object#freeze</code> doesn't count) Immutability is really the cornerstone of functional languages. Further, Ruby's core libraries are highly oriented toward imperative design. Its <code>Array</code> and <code>Hash</code> classes are both mutable by nature, even <code>String</code> has methods which make non-immutable (e.g. <code>gsub!</code>). Ironically, Java is more "functional" than Ruby in this respect.</p> <p>With that said, it is possible to do functional-like programming in Ruby. Any time you use a block/proc/lambda, you are using a feature that comes from functional programming. Likewise, collection methods like <code>map</code> and <code>zip</code> are also higher-order constructs which find their roots in languages like Lisp, ML and Haskell.</p> <p>If you really want to do functional programming, you will want to use a language which is more geared toward that genre. Some suggestions:</p> <ul> <li><a href="http://clojure.org" rel="nofollow noreferrer"><strong>Clojure</strong></a> - Since you phrased the question using Ruby, I'm guessing you're of the dynamically typed persuasion. Clojure is like a strictly-functional Lisp that runs on the JVM.</li> <li><a href="http://research.microsoft.com/fsharp/fsharp.aspx" rel="nofollow noreferrer"><strong>F#</strong></a> - Basically OCaml on the CLR. Very nice, very clean</li> <li><a href="http://www.scala-lang.org" rel="nofollow noreferrer"><strong>Scala</strong></a> - Not a <em>strictly</em> functional language, but much better for it than Ruby</li> <li><a href="http://www.haskell.org/" rel="nofollow noreferrer"><strong>Haskell</strong></a> - Everybody's favorite!</li> </ul> <p>You'll notice that three of these four languages are statically typed. In fact, in the case of Scala and Haskell, these are <em>very</em> statically typed languages (much stronger type systems than, say, Java). I'm not sure why this is a trend in functional languages, but there you have it.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload