From: Paul Brannan Date: 2004-08-05T22:44:55+09:00 Subject: Re: Macros in Ruby On Thu, Aug 05, 2004 at 12:31:30PM +0900, Jesse Jones wrote: > In article <161164987028.20040805090540@soyabean.com.au>, Gavin > Sinclair wrote: > > > Which do you prefer? > > > > (1..10).map { |n| n ** 2 } > > > > (1..10).map( lambda { |n| n ** 2 } ) > > I prefer a light-weight syntax for something as commonly used as > anonymous functions. On the other hand, I still don't know why {|n| n > ** 2} can't simply create a proc object. Remember how the lambda method works: it takes a block parameter and creates an object out of it. IMO this is very clean; blocks are the basic building block and procs and bindings are built on top of them. As to why we cannot remove the call to the lambda method, consider: 1. Ruby does have blocks, and 2. Ruby does not require parens for method calls. If I write: (1..10).map { |n| n ** 2 } Should this be interpreted as: (1..10).map(lambda { |n| n ** 2 }) or as: (1..10).map do |n| n ** 2; end If it were possible to merge blocks and proc objects without introducting ambiguity and without losing backward compatibility, it might not be a bad idea. I do not think this is possible, though. Paul