matz / zetabits.com (Yukihiro Matsumoto) writes:

> Hi,
> 
> In message "[ruby-talk:12369] Re: FEATURE REQUEST: 'my' local variables"
>     on 01/03/10, Kevin Smith <sent / qualitycode.com> writes:
> 
> |>  loop {<a, b, c|d, e, f>
> |>    ...
> |>  }
> |
> |Hmmmm. At a glance, that looks pretty confusing. 
> |I'm so used to | x | that it's jarring having < a 
> || b > instead. Slight changes to the symbols used 
> |might make it better. 
> 
> So, which symbols are better for them?

Perhaps there's another way to look at this. Rather than making scope
an attribute of individual variables and parameters, why not make it
an attribute of the block? For now, ignore the notation and consider
the idea :)

   loop { |a,b,c|
     # stuff
   }

Block has access to existing locals. Locals created in the block are
lost on block exit. Parameters may alias locals.


New construct:

   loop {{ |a,b,c|

   }}

'{{' introduces a block with local scope. No changes to variables or
parameters inside the block are visible outside. If a variable inside
the block has the same name as an existing local, it is initialized to 
that local's value, but is otherwise independent.

  n = 123
  3.times {{
    puts n
    n += 2
  }}

  puts n

will output '123, 125, 127, 123'


Dave