On Wed, Oct 31, 2012 at 1:53 AM, Mean L. <[email protected]> wrote:

> I can't say this makes sense to me.  Ruby otherwise is a dynamic
> language, but with respect to local vars it's suddenly static, and the
> parser wants to identify all local vars in one left to right parse pass,
> before the code is run.
>
> so even though at runtime
>
> (a if a = 1)
>
> local var 'a' already exists before it's read,

It could, but it doesn't - because of the current semantics. :-)

> the parser has statically
> bound the first 'a' to a method lookup path.
>
> So the question is, why in a dynamic language is local variable binding
> static?  Is it a perf optimization?

Just a guess: it's probably simpler to implement.  The decision when a
variable exists can be made solely based on textual order of the
source code and does not need to take into account how expressions are
evaluated which is a much more complicated thing to evaluate.  I
guess, Matz figured it's not worthwhile for the few corner cases.  And
the community has learned to live with it pretty well, I'd say.

Kind regards

robert


-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

-- You received this message because you are subscribed to the Google Groups 
ruby-talk-google group. To post to this group, send email to 
[email protected]. To unsubscribe from this group, send email 
to [email protected]. For more options, visit this 
group at https://groups.google.com/d/forum/ruby-talk-google?hl=en

Reply via email to