From: "David A. Black" Date: 2008-05-25T19:55:43+09:00 Subject: Re: lambda, ->, haskell, and so on Hi -- On Sun, 25 May 2008, Phlip wrote: >> assert_yin_yang -> { q += 0 }, 'it broke!', -> { q == 42 } > > Props! I was hoping that's what -> was for! > > About _{}, I meant making a global identifier out of _ was dangerous. Of > course we sometimes use it as a private identifier, in a Prolog kinda way, > such as |a,_,c|, to identify a variable we don't want anyone to access. My > library should not collide with anyone doing that, so I did not put _{} in > it; it's just a recommendation in the documentation. My advice, in passing, would be not to recommend it. As you say, _ is usually used (though I don't tend to use it myself) as a throwaway, precisely because it's non-communicative. So having it do something where someone looking at the code might actually want to know what it's doing is probably not ideal. > The "in the way" alternative was: > > assert_yin_yang proc{ q += 0 }, 'it broke!', > proc{ q == 42 } > > That sorta obviates my standard advertizing jingle - more assert bang for > less coding buck! 'proc' ain't DRY there... I don't think I'd describe those two 'proc's as a case of repeating yourself, since each of them is serving the minimal purpose that 'proc' can serve. Or, to put it another way, proc { q == 42 } is in no way a repetition of proc { q += 0 }. David -- Rails training from David A. Black and Ruby Power and Light: INTRO TO RAILS June 9-12 Berlin ADVANCING WITH RAILS June 16-19 Berlin INTRO TO RAILS June 23-26 London (Skills Matter) See http://www.rubypal.com for details and updates!