On Thu, 19 Oct 2000, ts wrote: > >>>>> "H" == Hugh Sasse Staff Elec Eng <hgs / dmu.ac.uk> writes: > > H> for lhs... in expr [do] > H> expr.. > H> end > [...] > H> (expr).each `{' `|' lhs..`|' expr.. `}' > > H> Which rather suggests new scope *is* created... > > H> I would advocate the simplest (in terms of number of different cases) > H> rules of scope possible, and that block parameters should have scope > H> for that block only. Principle of least to remember? :-) > > If you look in ruby-man you'll see that 'for' is defined in 'Ruby syntax' > like `while'. The above text I quoted was from ruby-man-1.4/syntax.html#for > > You don't have a dynamic scope for while, this is the same for 'for' > > 'each' is a method which "yield" a block. > But the manual page states they are the same: "for is the syntax sugar for:" etc. That was my point. If they are not equivalent, but they are so near that the author of the manual could confuse the two, then it is not as clear as one would like. Given that a little further up that page it says: Braces introduce the nested local scopes, that is newly declared local variables in the braces are valid only in the blocks. For example: foobar { i = 20 # local variable `i' declared in the block. ... } print defined? i # `i' is not defined here. foobar a, b { .. } # it is not valid outside of the block then I would suggest the following patch to clear matters up: --- syntax.html.orig Thu Jun 22 16:18:36 2000 +++ syntax.html Wed Oct 18 17:00:04 2000 @@ -1555,7 +1555,7 @@ </P> <PRE> - (expr).each `{' `|' lhs..`|' expr.. `}' + (expr).each `do' `|' lhs..`|' expr.. `end' </PRE> <H4><A NAME="yield"><code>yield</code></A></H4> if 'do' and 'end' do not introduce new scope, whereas the braces do. But actually trying this: irb(main):001:0> [1..4].each do irb(main):002:1* i = 20 irb(main):003:1> end [1..4] irb(main):004:0> print defined? i nilnil irb(main):005:0> which seems to be the same as braces to me. Hmmm. I thought I understood the difference between braces and do...end. > Guy Decoux > Hugh hgs / dmu.ac.uk