From: Eric Mahurin Date: 2005-09-29T00:29:27+09:00 Subject: Re: creating independent lambdas in loops --- Gavin Kistner wrote: > On Sep 28, 2005, at 7:47 AM, Eric Mahurin wrote: > >> Completely true. If a variable of that name is already > >> defined it is > >> used (and no local variables are created). > > > > Does anyone else find this "feature" useful? > > All the time! I would say that at least half the programs I > write use > this feature of the blocks-as-closures. I'm talking about specifically block arguments (the only variables in a block that can be local to the block). i.e. this: x = 0 [1,2,3,4].each {|x|} x # => 4 # block argument changed x compared to: [1,2,3,4].each {|x|} x # undefined local variable or method 'x' I find this dual behavior annoying - that a local variable is created only if the variable doesn't exist in the current scope already. I would have rather it always be created so that if you did want an argument to be assigned to a variable outside the block, you'd have to do it explicitly: x = 0 [1,2,3,4].each {|y| x = y } x # => 4 __________________________________ Yahoo! Mail - PC Magazine Editors' Choice 2005 http://mail.yahoo.com