From: Pit Capitain Date: 2009-01-11T09:58:54+09:00 Subject: Re: functional programming 2009/1/10 Pascal J. Bourguignon : > Brian Candler writes: >> I guess you rob Peter to pay Paul. In Ruby, a bareword like "biggest" >> can be a method name (in which case it invokes the method, and evaluates >> to its return value), or a variable name (in which case it evaluates to >> the content of that variable). > > In Lisp, it can be both, and you always know which you refer. > > (defun foo (x) > (1+ x)) > > (let ((foo 41)) > (foo foo)) > --> 42 Nothing special. In Ruby, that's: def foo(x) x + 1 end foo = 41 foo(foo) # => 42 > And if you happen to store functions in a variable, you have the > operators FUNCTION and FUNCALL to switch from one namespace to the > other: > > (let ((foo (lambda (x) (1- x)))) > (list (funcall (function foo) 0) ; calls the function foo > (foo 0) ; idem > (funcall foo 0))) ; calls the function bound to the variable foo. > --> (1 1 -1) Can be done as well in Ruby: foo = lambda { |x| x - 1 } [ send(:foo, 0), foo(0), foo.call(0), ] # => [1, 1, -1] BTW: Why would I write (1- x) if I want x - 1 ? Regards, Pit