From: Dominik Bathon Date: 2005-08-07T12:19:10+09:00 Subject: Re: new block notation (was: Re: ruby-dev summary 26468-26661) On Sun, 07 Aug 2005 02:11:07 +0200, Trans wrote: > > IIUC the point is that arguments given to a (future) lambda will act >> like in a method definition, while in a block they behave slightly >> differently > > Please continue. I think somewhere in this thread I read that block/current lambda arguments are handled like multiple assignment and this seems to be true: >> b = lambda { |a| p a } => # >> b[] (irb):1: warning: multiple values for a block parameter (0 for 1) from (irb):2 nil => nil >> b[nil] nil => nil >> b[1,2,3] (irb):1: warning: multiple values for a block parameter (3 for 1) from (irb):4 [1, 2, 3] => nil >> a = nil => nil >> a = 1,2,3 => [1, 2, 3] So you get warnings that there is the wrong number of arguments but it works nonetheless. If I understood this thread correct the future lambdas won't allow a wrong number of arguments (like methods today), while blocks will still do. So, I think (-> (a) { p a })[] and (-> (a) { p a })[1, 2, 3] would give errors instead of warnings. I just experimented and found the following: >> d = lambda { |a,b| b ||= "default"; p a, b } => # >> d[1] ArgumentError: wrong number of arguments (1 for 2) from (irb):8 from (irb):8:in `[]' from (irb):9 but: >> [1,2].each { |a,b| b ||= "default"; p a, b } 1 "default" 2 "default" => [1, 2] This is in 1.8. So some of those checks are there already. Dominik