From: Eric Mahurin Date: 2005-10-03T01:18:15+09:00 Subject: Re: ideas for an RCR: variable locality --- Bob Hutchison wrote: > >> (a_1=x;b_2=(a_3=y;b_4=z;a_3 : > >> b_2) > >> > > Yes, something like this would work (using your Gensym > module): > > > > min2 = lambda { |a,b| > > v1 = Gensym.gensym > > v2 = Gensym.gensym > > "(#{v1}=#{a};#{v2}=#{b};#{v1}<#{v2} ? #{v1} : #{v2})" > > } > > > > Here are the disadvantages of this compared to having ruby > do > > local variables: > > > > - not as natural/uglier > > No argument there at all, I agree. However a little syntactic > sugar > would make all the difference. I made a suggestion off the > top of my > head as to what that might look like, but I've got no doubt > that that > can be improved. > > You might be able to make an argument that local variables > are more > fundamental and that a macro system shouldn't be the way to > solve the > problem. Though, the problem that motivated this discussion, > which I > believe amounted to a problem with in-lining functions, is > probably > better solved by the macro system. For my exact situation (parser generator), I don't think the lisp-style macros would help me. My "macros" are more object-oriented and dynamic in nature. But, I would like to think about it a little more to see if there would be a general-purpose macro system that could encompass the usage I have. > > - clutters the namespace/variable table > > Actually it doesn't in the current ruby. In the example I > gave > earlier the gensymed names are not visible outside the eval. Maybe you are thinking of blocks. Looks like eval uses/makes variables in the surrounding scope: x,y,z = 1,-2,3 # => [1, -2, 3] local_variables # => ["_", "x", "y", "z"] eval "(a_1=x;b_2=(a_3=y;b_4=z;a_3 > - prevents GC from freeing objects that these variables > > reference > > Not if they don't exist (as I think they don't) Looks like they do. __________________________________ Yahoo! Mail - PC Magazine Editors' Choice 2005 http://mail.yahoo.com