Hello --


On Sat, 23 Dec 2000, Dave Thomas wrote:

> David Alan Black <dblack / candle.superlink.net> writes:
> 
> > The behavior I find most surprising -- even given the underlying
> > principle of defining a variable upon seeing an assignment to it -- is
> > illustrated by this:
> > 
> >    irb(main):003:0> if m then m = 123 end
> >    NameError: undefined local variable or method `m' for #<Object:0x4017fc90>
> >    (irb):3:in `irb_binding'
> >    irb(main):004:0> if m then m = 123 end
> >    nil
> 
> Let's play Ruby during the parsing stage (remember, we're not
> executing code at this point)
> 
>    if                        <keyword, I'm looking for some
>                               kind of expression>
>       m                      <name. I haven't seen an assignment,
>                               so it's a method call>

OK... my question here is: how expensive/illogical/whatever would it
be to be able to say, at exactly this point: it's a method call, but
there's no method defined with that name, so it's an error?

In which case this:

>         then                 <keyword>
>              m = 123         <assignment to m. remember the fact that
>                               m is a variable for future reference> 

would never be reached or parsed at all (which is what I had
expected), so m would not be defined.

I have no doubt there are answers to my question (probably beginning
with the word "very" :-)  -- among other things, I imagine that having
to make that kind of decision at parse-time would wreak havoc with a
large number of dynamic constructs.  At the very least, I would
certainly agree that some kind of warning would be helpful in such a
case.


David

-- 
David Alan Black
home: dblack / candle.superlink.net
work: blackdav / shu.edu
Web:  http://pirate.shu.edu/~blackdav