help-octave
[Top][All Lists]
Advanced

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

Re: referencing subfunctions


From: Christian Böhme
Subject: Re: referencing subfunctions
Date: Thu, 11 Jun 2009 23:54:48 +0200
User-agent: Mozilla/5.0 (X11; U; Linux ppc; en-US; rv:1.8.1.19) Gecko/20081204 Iceape/1.1.14 (Debian-1.1.14-1)

Jaroslav Hajek wrote:

> Can you provide an example of what does not work for you?

Please see the attached files (map() is the algorithm invoked
by either broken() or working() both of which accept an arbitrary
number as their sole argument).

It appears that - even though section 12.7.2 of the current Octave
docs does not rule it out per se, ie, that subfunctions may indeed
reference other subfunctions - there is some sort of function
definition/visibility nesting level involved with the way function
files are parsed, which is majorly disturbing to say the least.
Syntactically, all functions including the one whose name is
identical to the file's name are on one and the same level yet
f() does not appear to be visible to any function (including the
anonymous ones) other than broken().

>                                                           AFAIK,
> there are no such special tricks in fsolve (note that it is reimplemented
> in 3.2.0),

Turns out that it has nothing to do with fsolve() but with the way
symbols are made available to other scopes/translation/interpretation
units.

>            so most likely you either see a bug or you're doing
> something wrong.

Maybe, depending on your definition of "wrong" ;)


Cheers,
Christian
function [ y ] = broken( a );

y = h(a);

endfunction


function [ y ] = h( a );

p_1 = a;
p_2 = 3;

x = 1;

F = @(x) f(p_1, x);
G = @(x) g(p_2, x);
y = map(F, G, x);

printf('y = %f\n', y);

endfunction


function [ r ] = f( p, x );

printf('p = %f, x = %f\n', p, x);

r = p + x;

endfunction


function [ r ] = g( p, x );

printf('p = %f, x = %f\n', p, x);

r = p - x;

endfunction
function [ y ] = working( a );

p_1 = a;
p_2 = 3;

x = 1;

F = @(x) f(p_1, x);
G = @(x) g(p_2, x);
y = map(F, G, x);

printf('y = %f\n', y);

endfunction


function [ r ] = f( p, x );

printf('p = %f, x = %f\n', p, x);

r = p + x;

endfunction


function [ r ] = g( p, x );

printf('p = %f, x = %f\n', p, x);

r = p - x;

endfunction
function [ r ] = map( f, g, x );

r = f(x) + g(x);

endfunction

reply via email to

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