[scilab-Users] generation function by function call

Antoine Monmayrant antoine.monmayrant at laas.fr
Mon Aug 29 11:32:11 CEST 2011


I think it is a problem of variable scope: your function C1 only exists 
while you are in the function re().
As any local variable it is discarded once the call to re() is finished.
One way to check that is to add a pause before re() returns:


function re()

if(isempty(co(1))==%F) then

function [y]=C1(x)
y=evstr(co(1))
return(evstr(co(1)))
endfunction

else

function [y]=C1(x)
y=0;
endfunction

end;
pause
endfunction

Now if you execute re(), you'll get a prompt at the pause, ie inside re():

-->re()

Type 'resume' or 'abort' to return to standard level prompt.

-1->C1(1)
  ans  =

     7.    2.

As you can see C1 exists.
Why are you wrapping the creation of C1 inside another function?
Why don't you execute directly something like:

co="4*x(1)+3*x(2)";
deff("[y]=C1(x)",["y="+co+";"]);
C1([1,2])


Antoine


Le 29/08/2011 11:12, alex G a écrit :
> Sorry for my english, i'm beginner in english ...
>
> Hello,
> I wish convert a string to a function when I press a button graphic. For
> that, I call a function when pressing the button.
>
> I don't have a function in out of my call, why ?
>
> Here is an excerpt of the code I use:
>
> //on souhaite transformer une chaine de caractère en fonction
> co=['4*x(1)+3(2)'];
>
> function re()
>
> if(isempty(co(1))==%F) then
>
> function [y]=C1(x)
> y=evstr(co(1))
> return(evstr(co(1)))
> endfunction
>
> else
>
> function [y]=C1(x)
> y=0;
> endfunction
>
> end;
> pause
> endfunction
>
> --
> View this message in context: http://mailinglists.scilab.org/generation-function-by-function-call-tp3292242p3292242.html
> Sent from the Scilab users - Mailing Lists Archives mailing list archive at Nabble.com.
>





More information about the users mailing list