octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

FYI: function handles


From: Jaroslav Hajek
Subject: FYI: function handles
Date: Thu, 4 Feb 2010 08:41:05 +0100

hi all,

the changeset
http://hg.savannah.gnu.org/hgweb/octave/rev/14d5fee02b3b

implements basic support for comparing function handles. Two handles
can now be compared using the == operator, as well as the isequal
function (Matlab-compatible).
Two handles compare equal if they refer to the same subfunction /
private function, or to the same globally visible name. Anonymous
handles are always unique.
Currently there is no check for matching overloads because octave
supports no local overloads, so if both functions refer to the same
global names, their overloads must also match.

Subtleties regarding relative lookup are ignored, i.e. if you create
@myfun, cd to different directory and create @myfun which sees
different overloads, the handles still compare equal. This is the
simplest way to do things, and Matlab 2007 seems to do the same.

This feature can be used to specialize some operations that take a
general function handle for built-ins.

if (h == @sum)
   ... special case
else
   ... general case
endif

strcmp (func2str (h), "sum") is unreliable since it can be a handle to
a local "sum" function.

regards

-- 
RNDr. Jaroslav Hajek, PhD
computing expert & GNU Octave developer
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz


reply via email to

[Prev in Thread] Current Thread [Next in Thread]