I'd like to address two common misconceptions I keep seeing in discussions of programming languages.
Ruby doesn't have first-class functions
I see this one a lot. The source of the misconception is that Ruby has separate namespaces for function names and ordinary variables. Most languages that are usually thought of as functional, such as Scheme, ML and Haskell do not. When a function is assigned to an ordinary variable in such a language, calling it looks just like any other function call. Here's an example in Python:
>>>foo = lambda x: 2 * x
>>>foo(6)
12
But in Ruby, it looks like this:
foo = lambda {|x| 2 * x}
foo.call(6)
=> 12
foo.call seems to be the source of confusion. In Ruby, the .call method is implicit for functions defined with the def keyword, but not for functions assigned to variables using the = operator. Having a special namespace and extra syntax doesn't mean Ruby lacks first class functions. Common Lisp is the same way.
Scheme is not Lisp
This one seems to be dying, fortunately, but I still see it on occasion. The original argument appears to be that Scheme has lexical scoping, while older Lisps have dynamic scoping. With lexical (static) scope, a variable always refers to the binding given to it in the nearest enclosing context. With dynamic scope, the variable refers to the most recent binding.
Common Lisp also uses lexical scope by default, though it allows the use of dynamic scope as well. I haven't seen anybody claim that Common Lisp isn't Lisp. Perhaps somebody would like to make that claim, and explain what CL and Scheme are if they're not Lisp.
last updated 2 years ago #
