From: Mike Gold Date: 2009-01-12T07:57:37+09:00 Subject: Re: functional programming Brian Candler wrote: > > Yes, a variable holding a lambda is a different beast to a method. As > you said, methods are associated with objects, and lambdas are not. > Usually one suits the usage case better than the other. > > I find the distinct behaviours of both to be very useful in practice. Can you give an example of where the difference is "very useful"? In every case I've encountered, it has been a hassle. Because programmers can and should always be refactoring and changing their mind, this entails the drudgework of adding/removing the '.call()'s or the '[]'s or (in ruby 1.9) the '.()'s. The worst outcome is when a programmer doesn't bother to refactor because of the hassle. By the way, since locals are determined at parse time, I don't see any particular reason why this cannot work: bisect = lambda { |x, y| (x + y)/2.0 } # ... bisect(5, 6) Whether or not that _should_ work is a different story. The pro is that I can swap lambdas and methods without changing syntax. The con is, at least, that the meaning of existing code could change (when a bisect method already exists). -- Posted via http://www.ruby-forum.com/.