bugGNU Octave - Bugs: bug #59521, 'end' expression and anonymous...

 
 

bug #59521: 'end' expression and anonymous functions

Submitter:  None
Submitted:  Mon 23 Nov 2020 06:59:23 PM UTC
   
 
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Works For Me Assigned to:  None
Originator Name:  Originator Email:  -email is unavailable-
Open/Closed:  * Closed Release:  * 6.0.92
Operating System:  * Any Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Tue 24 Nov 2020 01:46:38 AM UTC, comment #1: 

Regardless of expectations, Matlab returns 4 for the sample code.  Since Octave desires to be Matlab-compatible, we also need to return 4.

The issue is that the anonymous function is not a transparent passthrough of the input to the output.


f = @(x) x;


It looks like a passthrough for ordinary values like 1.1 or "string".  But it is not, or you could write a while loop like this:


f(while i < 5)
  i++;
endwhile


In this case, while the interpreter doesn't throw an error, "f(end)" always returns the value 1.

Rik <rik5>
Group administrator
Mon 23 Nov 2020 06:59:23 PM UTC, original submission:  

In version 6.0.92 it is possible to pass 'end' as an argument to an anonymous function:


f = @(x)x;
f(end)


It seems that 'f' is treated as one element array and 'end' in this case returns 1. In Octave 5.2.0 it results in error.

Another example:


a = [4 5 6];
f = @(x)x;
a(f(end))


I think it should return 6 but it returns 4.

Anonymous

 

(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

Items that depend on this one: None found

 

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

    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 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2020-11-24 rik5 Item GroupIncorrect Result Matlab Compatibility
        StatusNone Works For Me
        Open/ClosedOpen Closed

    Back to the top

    Powered by Savane 3.13-4b48.
    Corresponding source code