From: Robert Klemme Date: 2005-01-21T17:25:58+09:00 Subject: Re: Confused about variable "declarations" "Mark Hubbart" schrieb im Newsbeitrag news:de63abca0501201148776c2e49@mail.gmail.com... > On Fri, 21 Jan 2005 02:31:00 +0900, Robert Klemme wrote: > > > > "Mark Hubbart" schrieb im Newsbeitrag > > news:de63abca050120090877cc9971@mail.gmail.com... > > > On Thu, 20 Jan 2005 21:01:01 +0900, Graham Nicholls > > > wrote: > > > > No worries, and thanks, but I think that the problem was that offset > > is > > > > being set inside an iterator (they still confuse me - any pointers to > > a > > > > good explanation would be nice!), which means that it is out of scope > > > > outside the iterator. > > > > > > A short explanation: Blocks have a sort of "leaky scope", where > > > variables from outside the scope can leak in and out, but those that > > > are from the inside don't leak out. for example: > > > > While I completely agree with your explanation the word "leaky" strikes me > > as odd as it seems to suggest uncommon or defective behavior: > > It wasn't meant to, though I now see why one might take it that way. I > was using a picture from my mental image of block scope. Not > everything that leaks is defective; some things are supposed to. I > would consider a tightly sealed sieve or funnel to be defective :) But you wouldn't describe a functioning funnel as "leaky", would you? Because a leaking funnel is something different - and dangerous, too. :-) > > it's very > > common in programming languages, that variables are visible in nested > > scopes but not surrounding scopes: [...] > > I know, but in Ruby, blocks are the only exception to the rule, that I > know of. Excepting blocks, all scopes are clearly defined, and you > have to use tricks to access the variables in other scopes. IMHO that's only true in Ruby 2.x - not in current versions. The rule for blocks is the usual rule for nested scopes: if it is defined (in Ruby "assigned") in a scope then it's visible in all nested scopes from the definition ("assignment") on but not surrounding scopes. > But I'll concede the word "leaky". Perhaps there is a better term for it :) IMHO the usual term of "nested scopes" describes perfectly well, what's happening here. Kind regards robert