From: Chris Carter Date: 2007-04-08T03:31:58+09:00 Subject: Re: about functional programming On 4/7/07, Joel VanderWerf wrote: > Rick DeNatale wrote: > > On 4/6/07, Joel VanderWerf wrote: > > > >> More generally, though, the only way to pass more than one block to a > >> method is to turn all but one of the blocks into procs, like this: > >> > >> meth_with_two_blocks(proc {...}) { ... } > > > > I generally recommend using Kernel#lambda instead of Kernel#proc the > > difference is subtle, but unless you want to allow non-local returns > > from a block lamba is almost always the right choice. > > > > Do you mean Proc.new? IIRC Kernel#proc and Kernel#lambda are aliases. > Proc.new is the one with non-local returns, at least as of 1.8.6.[1] > > There is another reason to not use #proc, which I have yet to resign > myself to: it is going away in some future ruby, and we will have to > type two more characters each time we want to use it. > > > > [1] > > def m > foo_lambda = lambda do > puts "foo_lambda" > return > end > > foo_proc = proc do > puts "foo_proc" > return > end > > foo_proc_new = Proc.new do > puts "foo_proc_new" > return # non-local return > end > > foo_proc.call > foo_lambda.call > foo_proc_new.call > puts "didn't get here" > end > > m > puts "done" > > __END__ > > Output: > > foo_proc > foo_lambda > foo_proc_new > done > > -- > vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407 > > Also, Proc.new (and proc in 1.9) do not check arguments strictly: >> mylam = Proc.new {|x,y,z| p 'hi' } => # >> mylam[1,2,3,4,5,6,7] "hi" => nil >> mylam[] "hi" => nil -- Chris Carter concentrationstudios.com brynmawrcs.com