On Tue, 10 Oct 2006, Yukihiro Matsumoto wrote:
> > |is there a reccomended approach that will work in both 1.8 and 1.9 so as
> > |to smooth the transition?
> >
> > Consider block parameters are block local even when you're using 1.8.
> > It's a good thing in general, I think.

This seems like a no-brainer to me (it hadn't even occurred to me that
they might not be local), because I always image block vars in a
Scheme-y way, where variable scope is very strictly defined:
 container.each{(lambda (elem) ... )}
 # no elem out here at all

But Ara raises a good point about the best way to export variables from blocks:

On 10/10/06, ara.t.howard / noaa.gov <ara.t.howard / noaa.gov> wrote:
> but, if we also consider block locals as, well, local, what's the prefered
> method for getting them 'out'?  for example,
>
>    which = nil
>    container.each{|elem| break(which = elem) if predicate[elem]}
>
> are there two 'which' vars here (local and top-level)?  or will 'which' still
> successfully be exported?

Pre-defining a variable is always the way I go, tho it feels a little
ugly, just to make the scope explicit. So, I'd imagine that by
pre-defining which, you're allowed to get elem out by assignment, just
as you have.

That said, I'm no language designer, and perhaps I'm totally wrong.


Keith