From: Trans Date: 2005-08-07T09:11:07+09:00 Subject: Re: new block notation Daniel Brockman wrote: > "Trans" writes: > > > I'm confused myself b/c I don't see any difference between > > a block and a lambda. I was trying to understand what it > > is, and for a moment I thought somone one saying that > > 'self' was different in the two cases, but its not. > > Let me back up. What is the difference? > > Lambdas (or procs) are anonymous functions. Blocks are what > you pass to methods using `foo {...}' or `foo(&...)'. > > Blocks are more primitive than lambdas; you can create a > lambda by passing a block to the Kernel#lambda method. > > You can convert a lambda to a block by using the `&' syntax > (as in `&lambda {...}'), and the other way around by calling > Proc.new or using the `def foo(&block)' syntax. > > So, to rehash: Blocks are what go in between `{' and `}', > while procs, or lambdas, or (anonymous) functions, are > objectified blocks (instances of the Proc class). Thanks. And yep as I said I know all that. Here's my problem: there's no substatial difference. All the "differencs" you site are simply a matter of human syntatical interaction, eg. block _appear_ here, lambda _appear_ there. This may seem incorrect by the fact they we "convert" between them using &, but that is really nothing more then a convetion required by the way the method handle blocks, i.e. they are unary, optional and are not passed in among the other parameters. In other words, the & really just tells the method that "hey this lamdba is going into your block slot. It doesn't make block and lambda different entities. I think this statement really gives it away. > Blocks are more primitive than lambdas; you can create a > lambda by passing a block to the Kernel#lambda method. Nothing new has gone into the creation. Its a one for one translation, and you can go back and forth between the two without limit. So...unless someone still has someting I am yet unaware of, lets stop thinking about them as if they were actually something different. A block is simply a _lambda_ that fulfills a specific roll for a method. T.