From: Kristof Bastiaensen Date: 2004-05-03T19:29:05+09:00 Subject: Re: Lazy evaluation (evil) On Mon, 03 May 2004 10:21:07 +0200, Niklas Frykholm wrote: > (2) functions as first class values > > You can write a function that takes a function and returns a new > modified function with reasonable syntax. > > C fails on both accounts. In C you can return a pointer to a function. Of course it totally fails the "reasonable syntax". > In C++ you can sort of do (2) with templates, > but that fails the "reasonable syntax" test. > > Ruby, and indeed all object-oriented languages, fail (1) since the main > thing they do is to pass around mutable objects. (2) is a bit harder to > call. But I would say Ruby fails this too. Mainly because of the fact > that "methods" have a different calling syntax than "method objects" and > "procs". > > So I wouldn't say that Ruby is a functional language. > I agree on everything except point (2). Just because there are also methods, which are different things as procs, doesn't mean that there are no first class functions. Take the following code: add = lambda { |x| lambda { |y| y + x }} add2 = add.call(2) add2.call(5) => 7 add2.call(7) => 9 This works just like it does in scheme. I would say it fits very nicely in (2). The "reasonable syntax" is a bit subjective, and I admit there is an extra level of indirection. But this is just the way in Ruby to perform an action on an object, so that's rather a confirmation of the fact that functions (proc objects) have an equal status as all other values (objects). Kristof