bugGNU Octave - Bugs: bug #43299, anonymous function arguments may...

 
 

bug #43299: anonymous function arguments may be shadowed by function names

Submitter:  Mike Miller <mtmiller>
Submitted:  Thu 25 Sep 2014 12:23:34 PM UTC
   
 
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Fixed Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Wed 25 Nov 2015 03:49:36 PM UTC, comment #2: 

Agree, working now.

Mike Miller <mtmiller>
Group Member
Wed 25 Nov 2015 12:46:28 AM UTC, comment #1: 

@Mike: I think this bug may have been fixed somewhere in the last year.  I tried the three examples you posted and they all work.  This is with cset 74cc8ae4e2b0 from 11/24/15.

Rik <rik5>
Group administrator
Thu 25 Sep 2014 12:23:34 PM UTC, original submission:  

This seems to be a subtle bug in the way that names are resolved in the definition of an anonymous function. If the name of an anonymous function argument is also the name of a function (command-line, m-file, or oct-file), the name may resolve to the function rather than the argument.

Some examples:


fn = @(x) x;
fn (1)


This seems to work fine even if x is defined as a function.


fn = @(x) x(:);
fn (1)


This anon function definition attempts to resolve x as a function first, and only if it doesn't exist does it work as the argument to the anon function. The name lookup happens when the function is defined, not when it is called. So if I create an invalid oct-file for example,


system ("echo > x.oct");
fn = @(x) x(:);
error: caught execution error in library function


the error is thrown when the function is being defined.

This can break code in Octave itself if an anonymous function is defined with an arg like "x" and the user creates a function also named "x". See for example bug #43237.

According to Ben, Matlab correctly handles this case, the anonymous function argument name always takes precedence.

Mike Miller <mtmiller>
Group Member

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Digest:
   bug dependencies.

 

Carbon-Copy List
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by mtmiller (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2015-11-25 mtmiller StatusWorks For Me Fixed
        Open/ClosedOpen Closed
    2015-11-25 rik5 StatusNone Works For Me
    2014-09-25 mtmiller Dependencies- bugs #43237 is dependent

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code