zak.wilson / gmail.com wrote: >This looks like first class functions to me: > >def accgen (n) > lambda {|i| n += i } >end > >foo = accgen(5) >foo.call(5) # returns 10 >foo.call(5) # returns 15 > >accgen function borrowed from http://www.paulgraham.com/accgen.html > > Perhaps we need a new term. According to Google, "First class hooberglobbers" seems to mean hooberglobbers can be assigned to variables, parameters, and return values, and then, though the assignee, can be manipulated in all the ways that hooberglobbers can be manipulated. Under this definition, yes, Ruby has first class functions. I have a stricter definition. Let's call it "patrician hooberglobbers." Patrician hooberglobbers, to me, have the additional quality that the syntax for manipulating a hooberglobber is the same whether it is referred to statically or by evaluation/substitution (as through a variable, or return value of a function call). In this sense, Ruby has patrician classes: a = String.new b = String c = b.new However, while Lisp, Python (from the examples I've seen), and Unlambda have patrician functions, Ruby does not. I can think of two simple enough reasons for this: 1. Because Ruby has a "poetry mode," there is no way to refer to a function by reference -- simply referring to it invokes it. The closest you can get is to refer to the Symbol representing its name, or to create a Method object, which really just wraps an invocation of the method inside a class. This could be "fixed" by creating a syntax to "thunk" function names, and to later apply them. So that, given some function 'foo', you could say: foo "hello"; ^foo("hello"); a = ^foo; a("hello"); But then ^ is just syntactic sugar for self.method, and () sugar for Method#call. This doesn't escape the fact that a can't be treated the same as foo. 2. Actually, when I was writing reason #2, I wrote some example code to show that a method is just a way for an object to receive messages in Ruby, but got a surprising result, so there is no #2. Here's the code, though: class Foo; def thing; nil end end f = Foo.new; f.thing #=> nil m = f.method :thing; m.call #=> nil class Foo; def thing; 5 end end f.thing #=> 5 m.call #=> nil Heh, it seems that Ruby really does have first class functions. ;) (Why is this happening, btw? Does this have something to do with continuations?) Now, does a language need patrician functions? I dunno, I seem to be enjoying Ruby, and my opinion is pretty much all anybody needs to concern themselves with. Devin