From: Mike Gold Date: 2009-01-14T05:32:09+09:00 Subject: Re: functional programming Pascal J. Bourguignon wrote: > Mike Gold writes: > >> Why is func.call() or func[] or func.() "very useful" compared to >> func()? As I mentioned, in every case I've found it to be a >> hassle, for the reasons previously stated. > > The reason is because Ruby is a lisp-2. The same name can be used to > designate both a method and a variable. So you need two syntaxes, to > make reference to the method of a name, or to the variable. No, that's not the reason. It is because Ruby allows method invocation without parens. Therefore parens cannot be used to unambiguously "dereference" a function. The case in point is Python, class X: def f(self): return "foo" x = X() g = x.f g() #=> "foo" triple = lambda z: 3*z triple(2) #=> 6 We all know the Ruby version, but just for good measure -- class X def f "foo" end end x = X.new g = x.method(:f) g.call #=> "foo" triple = lambda { |z| 3*z } triple.call(2) #=> 6 -- Posted via http://www.ruby-forum.com/.