[Scilab-users] Get back the name of a function given as argument
Pierre Vuillemin
contact at pierre-vuillemin.fr
Tue Oct 13 08:44:59 CEST 2015
Hi Samuel,
Thank you for the answer. I have finally came up with this routine :
function funName = sopi_retrieveFunName(f)
varList = who_user(%f);
for i = 2:size(varList,1) // "f" is the local copy of the function
and is the first one in the varList, it must be discarded
varName = varList(i);
execstr("var = "+varName);
if var == f then
funName = varName;
break;
end
end
endfunction
It retrieves the name of the function given as argument by comparing it
to the user's variables. It (very) far from being elegant, but it seems
to work.
Will there be a better way to achieve that with Scilab 6 ?
Pierre
Le 12.10.2015 21:02, Samuel Gougeon a écrit :
> Hi Pierre,
>
> Le 12/10/2015 16:46, Pierre Vuillemin a écrit :
>> Hi all,
>>
>> I am building some optimisation tools, and in this context, I was
>> wondering if it was possible to get back the name of a function given
>> as argument of another function.
>>
>> More specifically, consider the function 'fun' defined as
>>
>> deff('[f,g] = fun(x)','f = x^2;g = 2*x');
>>
>> and an optimisation routine "minimize" which first argument is a
>> function.
>>
>> Is there a way to get back the name of the function "fun" when calling
>> "minimize(fun)" ?
>
> I am afraid that, with 5.5.2, you have to use something like
> minimize("thefun") instead, with
>
> function argout = minimize(fun,...)
> execstr("fun="+fun);
> ...
> endfunction
>
> Samuel
>
> _______________________________________________
> users mailing list
> users at lists.scilab.org
> http://lists.scilab.org/mailman/listinfo/users
More information about the users
mailing list