From: Brian Candler Date: 2003-02-21T07:47:11+09:00 Subject: Re: Lexical scope and closures On Mon, Feb 17, 2003 at 12:05:01AM +0900, Tom Sawyer wrote: > On Sunday 16 February 2003 06:06 am, dblack@candle.superlink.net wrote: > > As one of the two or three people in the world who think that Ruby's > > scoping rules are actually fine, I have to say that after all this > > debate, people had better use whatever the new thing is, whether it's > > necessary or not! :-) > > honestly, i probably have to agree. the more i think about it the more i see > that the way it is might be best after all. > > > And I suspect people will, which means that if we have "local {}" or > > "let x = ", we're going to see *lots* of them. > > good point. Just a random thought which occurred to me: Suppose Ruby did introduce a declaration for local variables as discussed, say 'let x=' for the sake of argument. It has already been asked what happens if you used this outside a block. Suppose you made 'let x=' the _only_ way to get a local variable? And without it, 'x=' defaults to a method call, self.x= ? It seems to me that a number of inconsistencies would vanish: 'x' always refers to the object method 'x' or 'x=', unless you have previously introduced it as a local variable with 'let x='. And then inside blocks, x would continue to be bound to the same method or variable, unless you introduce a new variable with another 'let x='. Declarations for local variables would be clunky, same as Perl's "my". You'd have to remember to use them, and take care when reordering lines that only the first assignment of a variable said "let" (same as Perl). And there's very little chance of backwards compatibility. But it would be very logical and consistent :-) But it's also not Ruby... Regards, Brian.