bugGNU Octave - Bugs: bug #31821, Function handles for nonexisting...


bug #31821: Function handles for nonexisting functions

Submitter:  jkirby <jkirby>
Submitted:  Wed 08 Dec 2010 02:10:54 AM UTC
Category:  Interpreter Severity:  3 - Normal
Priority:  1 - Later Item Group:  Feature Request
Status:  Fixed Assigned to:  None
Originator Name:  jkirby Open/Closed:  * Closed
Release:  * dev Operating System:  * Other
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup

Jump to the original submission

Tue 05 Mar 2019 11:58:31 PM UTC, comment #8: 

Only thing I might do is change the error message.

I added file blah.m in the directory above where I started Octave.

function y = blah ()
  disp ('executing blah');
  y = 5;

Now, I run the following sequence

octave:1> f = @blah
f = @blah
octave:2> f()
error: blah: no longer valid function handle
octave:2> cd ..
octave:3> f()
executing blah
ans =  5

The message is incorrect because @blah was not a valid function handle at the time it was created.  It wasn't the case that it was valid, and then became invalid.

I think it would be enough to just say "blah: invalid function handle".

Rik <rik5>
Group administrator
Tue 05 Mar 2019 10:59:52 PM UTC, comment #7: 

As of the following changeset, I believe lazy evaluation of function handles works as it does in Matlab:


John W. Eaton <jwe>
Group administrator
Tue 20 Mar 2018 02:10:12 PM UTC, comment #6: 

I think this issue indeed requires a little bit more attention. Maybe it is sane to leave the bug open, and change the "wont fix".

Juan Pablo Carbajal <juanpi>
Group Member
Tue 20 Mar 2018 01:18:36 PM UTC, comment #5: 

I would encourage you to please reconsider... It may be a Matlab bug, depending how you feel about it, but please note that it can certainly affect negatively to Octave users (http://savannah.gnu.org/bugs/?53363):

If a matlab user saves one of those function handles in a mat file together with other relevant data, an octave user will not be able to access that data because octave fails to load the mat file due to this problem with function handles.

avlas <kupiqu>
Wed 23 May 2012 11:26:55 AM UTC, comment #4: 

Give that this bug has been marked as "Won't fix for 18 months" I'm closing this bug


David Bateman <dbateman>
Group Member
Sun 12 Dec 2010 08:25:25 PM UTC, comment #3: 

That would be fine with me. I still think it's a useless Matlab quirk, though. If for whatever reason you want to defer resolving the name reference, why not pass just the name?
In any case, feel free to try (and please cc me the patch), but I think my scarce time for Octave is better spent on something else.

Jaroslav Hajek <highegg>
Fri 10 Dec 2010 09:38:30 PM UTC, comment #2: 

Even if it was hidden behind one of the compatibility flags?

jkirby <jkirby>
Fri 10 Dec 2010 08:35:46 PM UTC, comment #1: 

I strongly advise against such a change. This "feature" (IMHO it was originally a Matlab bug) is almost useless and the rules in Matlab are quite obscure. Octave's behavior, on the other hand is much better in that if you misspel a function name, it errors at construction of the handle, which is where the bug actually is, instead of waiting until it's used, which may be completely elsewhere.
I'm changing this to won't fix for the time being.

Jaroslav Hajek <highegg>
Wed 08 Dec 2010 02:10:54 AM UTC, original submission:  

This is a direct copy from a discussion a few years ago:  http://octave.1599824.n4.nabble.com/Function-handles-for-nonexisting-functions-td1654944.html

"In Matlab, I can create function handles to nonexisting functions
using str2func or the @ operator. Only when I try to call the
function, an error like the following occurs:

??? Undefined function or method 'blabla' for input arguments of type 'double'.

In Octave, it seems that existance of the function is checked already
upon creation of the function handle. This means that the str2func or
@ call can fail with something like

error: error creating function handle "@blabla"

which would not happen in Matlab."

It would be nice to have this lazy-evaluation in Octave.

jkirby <jkirby>


(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

   bug dependencies.


Carbon-Copy List
  • -email is unavailable- added by jwe (Posted a comment)
  • -email is unavailable- added by juanpi (Posted a comment)
  • -email is unavailable- added by kupiqu (Posted a comment)
  • -email is unavailable- added by dbateman (Posted a comment)
  • -email is unavailable- added by rik5 (Updated the item)
  • -email is unavailable- added by highegg (Posted a comment)
  • -email is unavailable- added by jkirby (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 5 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2019-03-05 rik5 StatusWont Fix Fixed
    2018-03-18 siko1056 Dependencies- bugs #53363 is dependent
    2012-05-23 dbateman Open/ClosedOpen Closed
    2011-09-28 rik5 Priority5 - Normal 1 - Later
    2010-12-10 highegg StatusNone Wont Fix

    Back to the top

    Powered by Savane 3.13-1277.
    Corresponding source code