From: "Ara.T.Howard" Date: 2004-08-05T23:11:27+09:00 Subject: Re: Macros in Ruby On Thu, 5 Aug 2004, Paul Brannan wrote: > 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 perhaps a shorthand: lambda{ puts 'lambda' } => Proc:0xb74041a0 &{ puts 'lambda too' } => Proc:0xb74041a1 i'm probably missing something, but i don't think the syntax '&{' occurs anywhere now and '&' is already synomynous with blocks/procs/etc. -a -- =============================================================================== | EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov | PHONE :: 303.497.6469 | A flower falls, even though we love it; | and a weed grows, even though we do not love it. | --Dogen ===============================================================================