Unexpected behavior with built-in
John W. Eaton
jwe at octave.org
Wed Jul 22 05:07:23 CDT 2009
On 22-Jul-2009, Jaroslav Hajek wrote:
| It's not just feval, but also str2func. Currently, feval(str,...)
| works like feval(str2func(str),...), which is OK, but leads to
| problems.
|
| This works OK with 3.2.x:
|
| function y = my_eval (x)
| y = sin(x) - 0.5;
| endfunction
|
| fzero ("my_eval", 0)
|
| but watch this seemingly innocent change:
|
| function y = guarded_eval (x)
| y = sin(x) - 0.5;
| endfunction
|
| fzero ("guarded_eval", 0)
|
| Surprise! This fails in an incomprehensible way. Your guess is right:
| guarded_eval is a subfunction in fzero.
| I don't stand by that making feval ignore subfunctions and private
| functions is the best solution. Thinking about this, it will actually
| bring a lot of trouble for Pytave and other embedded applications of
| Octave, which use feval to access functions that may be defined
| locally.
| But surely Octave should provide a way out of this, even if Matlab
| doesn't (does Matlab's str2func ignore subfunctions?).
I think the solution is to use function handles and avoid using simple
names to refer to functions. OO methods can cause trouble currently,
but I think using function handles should work properly for other
cases now.
jwe
More information about the Bug-octave
mailing list