isa (x, "inline function") DOES NOT WORK

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

isa (x, "inline function") DOES NOT WORK

Rik-4
I happened to stumble upon some bad code in core Octave today.

sparse/spfun.m:38:  if (isa (f, "function_handle") || isa (f, "inline
function"))

The problem is that isa compares the CLASS of the object to the string
provided.  Inline functions are octave_value objects which share the class
"function_handle" so it is incorrect to use isa() to test for an inline. 
Instead, one needs to use typeinfo which does produce a different result.
As an example,

plot/draw/fplot.m:92:  if (strcmp (typeinfo (fn), "inline function"))

This has got to be exceedingly rare--I know most people aren't using inline
functions anymore--but I still thought I would remark on it in case it
appears in any Octave Forge packages.

I'm in the midst of replacing the isa (f, "function_handle") usage with
just is_function_handle (f) which is clearer and faster.  This is also
something that could be done in the Octave Forge packages.

--Rik