On Mon, 29 Dec 2003 00:04:19 +0900, Gavin Sinclair
<gsinclair / soyabean.com.au> wrote:
[snip]
> However, this one does not (again, free of all context):
> 
>   x = x
>   x         # nil
> 
> This, to me, is inconsistent and undesirable behaviour.  I would
> prefer this:
> 
>   x = x     # NameError: undefined local variable or method `x' ...
> 
> I haven't given it much thought, but the existing behaviour cost me 15
> minutes debugging, and I:
>  * don't see a benefit of the existing behaviour;
>  * do see a benefit (consistency) of changing the behaviour.
> 
> Any comments?


Just recently there was a discussion on using procs that referenced
methods not yet defined:

  even = proc{|x| x == 0 ? true  :  odd[x-1]}
  odd  = proc{|x| x == 0 ? false : even[x-1]}
  p even[5]

and we get an error because 'odd' is undefined when 'even' was defined.
One way around this is to simply set 'odd' to nil first:

  odd = nil
  even = proc{|x| x == 0 ? true  :  odd[x-1]}
  odd  = proc{|x| x == 0 ? false : even[x-1]}
  p even[5]

But, as a result of current behavior, the extra nil assignment can be
avoided via:

  even, odd = proc {|x| x == 0 ? true  :  odd[x-1]},
              proc {|x| x == 0 ? false : even[x-1]}
  p even[5]

I'm sure opinions will vary greatly on whether this is a benefit :-)

regards,
andrew