bugGNU Octave - Bugs: bug #37179, isequal(@XXX,@XXX) is not...


bug #37179: isequal(@XXX,@XXX) is not compatible

Submitted by:  None
Submitted on:  Fri 24 Aug 2012 09:24:02 AM UTC  
Category:  Interpreter Severity:  3 - Normal
Priority:  3 - Low Item Group:  None
Status:  Fixed Assigned to:  None
Originator Name:  Paul Söderlind Originator Email:  -email is unavailable-
Open/Closed:  Closed Release:  dev
Operating System:  Any

Add a New Comment (Rich Markup)

You are not logged in

Please log in, so followups can be emailed to you.


( Jump to the original submission)

Fri 27 Mar 2020 09:16:22 PM UTC, comment #7: 

This is fixed in Octave version 6, with lazy resolution of function handles.

Mike Miller <mtmiller>
Project Administrator
Thu 12 Mar 2020 02:49:43 AM UTC, comment #6: 

The original incompatible behavior is still present in Octave 5.2.0 and Matlab 2019a

Nicholas Jankowski <nrjank>
Sat 19 Nov 2016 01:47:32 PM UTC, comment #5: 

This behavior is still present in Octave 4.2.0.

Hartmut <hardy>
Mon 27 Aug 2012 07:19:31 PM UTC, comment #4: 

I don't necessarily want to duplicate Matlab's behavior if it is a lot of work.  But, they do seem to have chosen a reasonable strategy.  For example, the Octave parser also defers symbol table lookups when we are processing subfunctions in the same .m file.  I'm thinking of the following:

In file manyfuncs.m

function y = manyfuncs (x)
  tmp = @func1;
  y = tmp (x);

function y = func1 (x)
  tmp = @func2;
  y = tmp (x);

function y = func2 (x)
  y = @sin (x);

The parser encounters @func1 before it has been defined so it has to treat it as a generic reference until the rest of the file has been parsed.  I don't see why, on the command line, Octave should require the object behind the function handle to exist if we are not actually using the object.  When you do need the object, such as to evaluate the function handle with some input and produce an output, then it is required for the object to exist, but not before that point.

More possible example code, typed at the command line.

clear all
function y = func1 (x)
  y = @func2 (x);
## This completes okay even though func2 does not exist
func1 (1)
error: @func2: no function and no method found
error: evaluating argument list element number 1
error: called from:
error:   func1 at line 2, column 5
## This errors out as expected because the object is undefined
## Now define func2
function y = func2 (x)
  y = sin (x);
func1 (1)
ans =  0.84147
## Now it completes as expected.

It seems like it would be nice to me to allow this kind of code where the handle to the object is used early before the definition of the object behind it.

clear all
myfcn = @func2;  # Currently this errors out, but imagine it continuing
function y = func2 (x)
  y = sin (x);
myfcn (1)  # Only here, when I ask for an evaluation of the object behind the
           # reference should I check and get an error if func2 is undefined.

Rik <rik5>
Project Administrator
Mon 27 Aug 2012 02:45:40 AM UTC, comment #3: 


I think it is actually a little more complicated. I created two directories temp and temp2. I put foo.m inside of temp. foo.m is defined as follows
function x = foo (); x = 5;

In matlab R2010a

% First case:
>> cd temp
>> a = @foo;
>> cd ../temp2
>> a ()

ans =


% Second case:
>> cd temp2
>> a = @foo;
>> cd ../temp
>> a ()

ans =


>> cd ../temp2
>> a ()
??? Undefined function or variable 'foo'.

So it looks like matlab looks up the function just like Octave does, but if it can't find the function it does not error. Instead the function handle goes into a state where it is looked up on every invocation.

This behavior seems nonsensical to me. Do we want to consider this a matlab bug?

Max Brister <fisheater>
Mon 27 Aug 2012 02:20:05 AM UTC, comment #2: 

The problem isn't even with isequal.  The issue is that the parser immediately tries to find the function handle @XXX in the symbol table and when it fails it reports an error.  You can verify this by setting a breakpoint in the function isequal and you will find that the breakpoint is never reached. 

Perhaps the answer is to delay the lookup on a function handle unless a value is requested.  Thus,

y = @sin;  # Assign the function handle @sin to y without looking it up
y = @sin(1); # This would cause the function handle lookup.

Rik <rik5>
Project Administrator
Sun 26 Aug 2012 02:45:31 AM UTC, comment #1: 

I can confirm that this is a problem on the development branch (rev 44d6ffdf9479). It also isn't mingw/windows specific.


Max Brister <fisheater>
Fri 24 Aug 2012 09:24:02 AM UTC, original submission:  

in 3.6.2 (mingw), executing


generates an error message "@XXX: no function and no method found"

True enough, there is no XXX in the path. However, ML generates the answer 1 ("True") in this case.



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

Attach Files:

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 nrjank (Posted a comment)
  • -email is unavailable- added by hardy (Posted a comment)
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by fisheater (Posted a comment)
  • -email is unavailable- added by None (Submitted the item)

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.




    Follow 7 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2020-03-27 mtmiller Carbon-CopyRemoved 80942 => -
    2020-03-27 mtmiller StatusConfirmed => Fixed
        Open/ClosedOpen => Closed
    2016-01-18 mtmiller Priority5 - Normal => 3 - Low
        Release3.6.2 => dev
    2012-08-26 fisheater StatusNone => Confirmed
        Operating SystemMicrosoft Windows => Any

    Back to the top

    Powered by Savane 3.5