[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: anonymous functions and name resolution
From: |
Mike Miller |
Subject: |
Re: anonymous functions and name resolution |
Date: |
Thu, 25 Sep 2014 08:24:48 -0400 |
User-agent: |
Mutt/1.5.23 (2014-03-12) |
On Thu, Sep 25, 2014 at 07:56:37 -0400, Ben Abbott wrote:
>
> On Sep 24, 2014, at 9:37 PM, Mike Miller <address@hidden> wrote:
>
> > 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?
>
> Your example works as you'd expect in Matlab. Also if "fun = @(x) x;", then
> Octave works as expected.
>
> Looks like a bug.
Thanks for confirming, reported as http://savannah.gnu.org/bugs/?43299.
--
mike