[Scilab-users] How to replicate what "load" does (aka creating variable in the current workspace from inside a function)

Samuel Gougeon sgougeon at free.fr
Mon Feb 22 12:44:25 CET 2016


Le 22/02/2016 12:12, Antoine Monmayrant a écrit : Le Lundi 22 Février 
2016 12:04 CET, "Antoine Monmayrant" <amonmayr at laas.fr> a écrit:
>>   Le Lundi 22 Février 2016 11:51 CET, Serge Steer <Serge.Steer at inria.fr> a écrit:
>>> The following function does the job:
>>>
>>> function myload()
>>>     txt=["a=1";"b=2"];
>>>     ncur= size(who("local"),"*")
>>>     execstr(txt);
>>>     vars=who("local");
>>>     vars=vars(1:size(vars,'*')-ncur-1)
>>>     args=strcat(vars,",")
>>>     execstr("["+args+"]=resume("+args+")")
>>> endfunction
>> Thank you Serge!
>> It does work on 5.5.0, but it does not work on 6.6.0-beta1.
>> It might be due to the way variables are ordered when calling "who".
> OK, it seems that "who" no longer list variables with the most recent at the top, but in alphabetical order.
.
You can use setdiff() to get the names of the new variables, knowing the 
former set, whatever is their order.
Then, you will need to the same before and after calling the function, 
to get the unknown names of returned variables.

Samuel




More information about the users mailing list