Unexpected behavior with built-in

Jaroslav Hajek highegg at gmail.com
Mon Jul 20 02:12:10 CDT 2009


On Fri, Jul 10, 2009 at 1:27 AM, Joel LeBlanc<jwleblan at gmail.com> wrote:
> I think we need some community input on this one, but here are some
> thoughts.
> 1)  Builtin is (as far as I know) the only way to call a function outside
> the order of precedence
> 2)  This is an essential feature in the language, with a common use case being the extension of a "builtin"
> function via overloading
> 3)  What one considers "builtin" is really not essential, what is essential
> is the ability to call functions out of precedence
> 4)  Visibility into the precedence chain is important, and thus "which"
> needs to be extended to accept a "-all" flag and return a cell array of
> paths to function.  This is almost a separate issue, but I think,
> sufficiently related to mention here.
> Thus I propose the following
> solution.  Have builtin call the "lowest" function in the precedence chain.
>  If a builtin exists, this will surely be it under any reasonable
> definition.  Furthermore, builtin should throw an error when the "lowest"
> function is also the caller.  This is because had the programmer intended
> recursion, they wouldn't use builtin.
> Finally, I suggest a flag along the lines of "-next", which causes builtin
> to call the next lowest function in the precedence chain.  To see why this
> could be important, consider altering a function to add a capability but not
> knowing if someone else (some other package) also wanted to do the same.
>  You want your code to run, but after that you'd like additional such
> extensions to run as well.
> Cheers,
> ~Joel
> On Thu, Jul 9, 2009 at 7:02 PM, Joel LeBlanc <jwleblan at gmail.com> wrote:
>>

>From Matlab docs:

builtin is used in methods that overload built-in functions to execute
the original built-in function...

and then the following important statement:

builtin(...) is the same as feval(...) except that it calls the
original built-in version of the function even if an overloaded one
exists.

actually, this is precisely what Octave's bultin does, and I think
it's good behavior. It seems nested functions and subfunctions are not
seen by feval in Matlab, hence the problem (can anyone confirm?). With
some effort, this could be probably fixed.

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



More information about the Bug-octave mailing list