On Monday 12 March 2001 05:59, ts wrote:
> >>>>> "W" == W Kent Starr <elderburn / mindspring.com> writes:
>
> W> x = 5; loop { |y| x = 3; x * y }; puts x ->5
>
>  You break all old scripts with this
>
> W> x = 5; loop { |y| _x = 3; _x * y }; puts x -> 3

Not exactly.

old: x = 5; loop { |y| x = 3; x * y}; puts x -> 3
This is the old behavior, and in many cases a desired one.

new: x = 5 loop { |y| _x = 3; x * y}; puts x; -> 5  

Now, the thing is, olde behavior is unaffected. With _new_ behavior you can 
_force_ a variable local to loop. Or not, if you _wnat_ to get a new value 
for x, or if you have older code.

Also, this could be a "convention" rather than any change to the core. Just 
something we, as a group, sorta "do", kind of in the best practices category.
Or, that was my thinking at the time, anyway.

>  Perhaps to easy to make the confusion between x and _x

Yes, I agree with you here. It is not confiusing to me because that is sort 
of the convention I used in another (proprietory) scripting language (for a 
visual chat environment)  where the scope structure  was somewhat the same as 
Ruby and Proc, thought not as safe; if you defined a function to EXEC, and 
the argument ariable was the same as the next level up, the latter changed, 
as in:

def myfunc { x x SAY } would result in (the syntax was RPN)

5 x =  3 myfunc EXEC  -> x now equals 3 :-)

So, since I was providing "libraries" for users to write to, and the users 
may have their own scripts defining x, I started using _x to be argument 
variables for my "library" functions. So, it is not confusing to _me_ but I 
can see how it might be to others :-)

"Best practice" IMO would be to use weirdo variable names within Procs that 
have little possibility of stepping over your variables names at the next 
level up, _unless_ that is _desired_ behavior, in which case I document it as 
such, so _you_ can make a choice.

Messing with the core in Ruby for this case IMO is _not_ wise. Like I said, 
sometimes the stepping over variables names is _desirable_ behavior, as long 
as _you_ are aware of that possibility and _you_ make that choice.

At any rate, that is how I view it now; I am up to being persuaded otherwise 
:-)

Regards,

Kent Starr
elderburn / mindspring.com