From: Johann Hibschman Date: 2001-03-14T13:10:02+09:00 Subject: [ruby-talk:12598] Re: FEATURE REQUEST: 'my' local variables Stephen White writes: > *** start of loony tunes proposal *** Understood. Start of relatively newbie comments. :-) > The "i" is protected because it's defined in the |i| parameter list. This > is a nice way of just using a name for the loop without trashing anything > else. All other variables are just there and used, like BASIC. :) Okay. This here is the biggest source of errors for me in irb. In real programs, I can avoid it, but in interactive use, I have trouble. Namely, I keep expected the variable in blocks to introduce a new local variable, like a function call. i.e. I type x = [1, 2, 3, 4, 5] y = x.collect{|x| x**2} And suddenly, I've overwritten x. Maybe this is my lispy heritage showing, but I just don't expect this behavior. The block looks like a function call, so I expect it to introduce a new local. Likewise, I expect variables inside the block to refer to the outer scopes by default, by analogy to scheme/lisp lexical scoping conventions. It would be nice to have the equivalent of Scheme's "let", i.e. a way to explicitly introduce new locals, but I don't really need it. How about a let-form like those of the ML languages? i.e. let x=10, y, z=27 in p x y = x*20 ... etc ... end where the intention is that all the variables named in the let form are taken as local variables which shadow any other similarly-named variables in scope. That just somehow seems cleaner to me. -- Johann Hibschman johann@physics.berkeley.edu