From: Wilson Bilkovich Date: 2007-09-10T05:27:32+09:00 Subject: Re: Bug in lambda? On 9/9/07, dblack@wobblini.net wrote: > Hi -- > > On Mon, 10 Sep 2007, Wilson Bilkovich wrote: > > > On 9/9/07, dblack@wobblini.net wrote: > >> Hi -- > >> > >> On Mon, 10 Sep 2007, Wilson Bilkovich wrote: > >> > >>> On 9/9/07, Logan Capaldo wrote: > >>>> On 9/9/07, Bernardo Monteiro Rufino wrote: > >>>>> On 9/9/07, dblack@wobblini.net wrote: > >>>>> > >>>>>> As far as remember, Guy Decoux and I are the only two people who think > >>>>>> that this makes perfect sense, once you learn it, and should not be > >>>>>> changed :-) > >>>>>> > >>> > >>> This one is my favorite. > >>> P.S. Don't use this in 'real' code or I will be forced to hunt you > >>> like a wild animal through the streets of your city. =( > >>> > >>> hydra>cat eye_of_terror.rb > >>> h = {} > >>> f = lambda {|h[:x]| } > >>> f[7] > >>> p h > >>> > >>> hydra>ruby eye_of_terror.rb > >>> {:x=>7} > >> > >> Hey, nothing wrong with that -- it's just like > >> > >> h[:x] = 7 > >> > >> but in slightly different form. But like I said, I'm one of the few > >> who think that there's nothing wrong with assignment semantics for > >> block parameters :-) > >> > >> > > > > I agree, except for the fact that assignments are relatively static, > > while 'yield' calls are variadic. Please tell me you don't use this > > feature, David. :) > > > > Hash#each do {|h[:x]| ... } is.. pretty strange. > > I've never used h[:x] as a block parameter. That is a bit exotic, and > a bit useless :-) But I think I've used an instance variable. Also > it's handy if, for example, you want to capture the last value passed > during an iteration. > > I would be OK-er with this if method arguments obeyed the same rules. e.g. def foo=(@foo);end foo = 5 would then automatically set the instance variable for you. I think I mostly don't like it because it is unique to block arguments, and even then is pretty significantly different in 'regular' blocks vs. lambdas.