On Apr 17, 2008, at 6:47 PM, Marc Heiler wrote:
> My problem with lambda's is that I have a hard time to find a
> real use case for them. I am not sure of some use case with
> lambda {} that brings a definite advantage over i.e. just
> using some special object or simple method.

a lambda is a special object - on that knows about every variable in  
scope.  have fun maintaining code that populates that object by hand ;-)

the entire point of lambdas is that the language already *has* a  
scope.  so, sure, you can cherry pick the required variables and  
populate an object, but you can also make loops with GOTO - lambda is  
merely an abstraction.

the 'definite' bit comes in because you don't HAVE to do ANYTHING.   
you simply write this code


sum = 0

list.each do |i|

   sum += i

end

and you don't have to write anything special, the environment is  
captured, the code is evaulated in the captured context, but you don't  
have to build a special summing function that take i and a sum var.

so it 'definitely' is an advantage - that is unless you don't happen  
to think less code is advantageous over more...

cheers.


a @ http://codeforpeople.com/
--
we can deny everything, except that we have the possibility of being  
better. simply reflect on that.
h.h. the 14th dalai lama