From: "Guy N. Hurst" Date: 2001-05-05T15:15:04+09:00 Subject: [ruby-talk:14704] Re: local/nonlocal block vars "Hal E. Fulton" wrote: > ... > Here's how I would do it. > > 7. Use a Symbol constant to represent a variable from > the outer scope. This has the advantages of the "prefix" > idea without reusing a prefix like * or &. > > 8. If you have a Symbol, you use a variable from the > outer scope. If not, it's local. > > 9. Disadvantage: Break old code? Waaahhh! No, > I don't like this part either. > Actually, I think the problem, from matz's point of view, is that block-locals are created by default if they do not already exist in the outer scope. So the solution he has is to flatten the scope more to not let that happen (potentially breaking some code), and then making some way to allow block-locals to be made by choice - hence the possible < > notation. (Right matz?) But maybe the symbol notation can be used in place of the < > for signaling vars which should be block-local. (Note: this is the opposite of the above proposal). x=99 5.times {|:x| print x } # here, :x indicates it *should* be block-local 3.times {|y| print y } # here, y would be used or 'created' puts x # 99 puts y # 3 > ... > ======== > OK, that's probably at least two cents there. As Bill Shakespeare > said, "Cry havoc, and let slip the dogs of war!" In this case I am reversing your proposal, such that parameters *without* the ':' will access/create outer scope vars, and with the ':', will ensure block-local ones. After all, Ruby's notion of closure *is* different from other languages (except for CLU, whence it originates, IIRC). Guy N. Hurst -- HurstLinks Web Development http://www.hurstlinks.com/ Norfolk, VA 23510 (757)623-9688 FAX 623-0433 PHP/MySQL - Ruby/Perl - HTML/Javascript