Hi,

In message "Re: || explanation in ruby... in pseudolanguage"
    on Wed, 11 Oct 2006 00:09:57 +0900, ara.t.howard / noaa.gov writes:

|hmmm.  it's kinda like 'scope coercion'.  seems kinda slippery - like
|
|   ' "1" + 41 '
|
|in perl...

I think I get the analogy here.

|plus it gets tricky when one meant to go 'up' a scope, but it went 'down' one
|instead:
|
|   i = 42
|
|   # 1000 lines of code
|
|   n.times do |i|
|     m.times do |i|
|     end
|   end
|
|   p i  # goes down or up depending on 'i = 42' line way above...
|
|on the otherhand, if all vars in block are local it's tough to get one out!

Yes, this is a problem.

|would a block local var be declared using something like
|
|   local x
|
|??

No, it's like

  n.times do |i; j,k|  # j and k only available within the block
     ...
  end

|another thing which springs to mind is an objectified stack - it could solve
|this problem too, working similarly for stack and scope:
|
|stack:
|
|   def foo()
|     context = callstack.first  # list of objectified stack objects
|     context['a'] = 42          # set local var 'a' in binding of caller
|   end
|
|scope:
|
|   def foo()
|     4.times do
|       context = scope.first   # list of objectified scope objects
|       context['a'] = 42       # set local var 'a' in first outer scope
|     end
|   end
|
|not too mention skinning a bunch of other cats too...

Interesting idea, but it seems to hinder the performance very
severely.  There may be a good trick to accomplish performance with
this feature.

|> Consider block parameters are block local even when you're using 1.8.
|> It's a good thing in general, I think.
|
|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?

The latter.  There's no "which" in the block parameters, nor explicit
block local variables.  If you'd like to omit previous assignment
(it's bit ugly), and still want to access "which" after the block, you
need the local variable propagation, that I tried to explain here.

							matz.