From: Ross Bamford Date: 2006-01-04T06:22:58+09:00 Subject: Re: Implicit block parameter? On Tue, 03 Jan 2006 18:39:48 -0000, wrote: > Hi -- > > On Wed, 4 Jan 2006, Ross Bamford wrote: > >> [[1,2,3],[2,3,4],[3,4,5]].each { it.select { it % 2 == 0 } } >> >> (I've not tested that btw but you get the idea). However I guess with >> that it's also potentially confusing when using the implicit idea, >> since it has the same magic variable meaning two different things in >> the same line. I guess in this case I'd probably declare the argument >> in the select block anyway (as 'i' or something). > > That's actually another good argument against "it": you'd be trampling > the outer it with the inner it. And having to remember to declare the > inner argument to protect it from this really puts the whole thing in > the "added to the language as an afterthought" category. > Hmm, I know. As I was writing it I started thinking about that and all the other little subtleties it could create. Generally I'm never happy with a solution that requires me to do more thinking :D. Based on the C-side patch that was posted by Dominik Bathon the inner/outer it thing does actually work, but isn't ideal from a readability perspective I guess. (As an aside, with that patch the approach I suggested *doesn't* work, since it doesn't check whether 'it' is already declared so tramples the outer it even if you declare a block argument on the inner). I'm not sure I understand the afterthought thing, though - wouldn't any suggested enhancement that happened to be implemented now be an afterthought? But anyhow this has snowballed a bit - originally I really wanted a way to do it from the Ruby side, and more for fun than profit. I've not been here long enough to start suggesting changes in Ruby itself but I just wondered if it'd been considered before... Cheers, -- Ross Bamford - rosco@roscopeco.remove.co.uk