octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

anonymous functions and name resolution


From: Mike Miller
Subject: anonymous functions and name resolution
Date: Wed, 24 Sep 2014 21:37:13 -0400
User-agent: Mutt/1.5.23 (2014-03-12)

Hi,

In investigating bug #43237, I found the following strange name
resolution behavior in Octave:

  >> x
  error 'x' undefined near line 1 column 1
  >> func = @(x) x(:);
  >> func ([1 2])
  ans =
     1
     2

So far so good. Now I introduce a function file named x:

  >> rename xfunc.m x.m;
  >> x
  ans =  3.1416
  >> func ([1 2])
  ans =
     1
     2
  >> func = @(x) x(:);
  >> func ([1 2])
  ans =  3.1416

And one more definition of x to confuse things further:

  >> x = 12;
  >> x
  ans =  12
  >> func = @(x) x(:);
  >> func ([1 2])
  ans =  3.1416

So normally, a workspace variable takes precedence over a function, but
in the body of an anonymous function, the name is looked up as a
function instead.

Bug or subtle interaction of scope and precedence?

-- 
mike



reply via email to

[Prev in Thread] Current Thread [Next in Thread]