From: pjb@... (Pascal J. Bourguignon) Date: 2009-01-14T19:44:11+09:00 Subject: Re: functional programming Mike Gold writes: > 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. It wouldn't matter if we had not to distinguish calling a named function from calling a function stored in a variable. So we could say that we're in violent agreement. > 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 -- __Pascal Bourguignon__