From: "Ara.T.Howard" Date: 2005-07-26T12:17:02+09:00 Subject: Re: Lisp on Lines On Tue, 26 Jul 2005, Devin Mullins wrote: > 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. harp:~ > irb irb(main):001:0> a = lambda{ p 42 } => # irb(main):002:0> a () 42 => nil irb(main):003:0> a() 42 => nil irb(main):004:0> b = a => # irb(main):005:0> b() 42 => nil harp:~ > ruby -v ruby 1.9.0 (2005-05-16) [i686-linux] harp:~ > irb -v irb 0.9.5(05/04/13) getting pretty close... cheers. -a -- =============================================================================== | email :: ara [dot] t [dot] howard [at] noaa [dot] gov | phone :: 303.497.6469 | My religion is very simple. My religion is kindness. | --Tenzin Gyatso ===============================================================================