[Scilab-users] Multiple files of functions with the same name

Antoine Monmayrant antoine.monmayrant at laas.fr
Thu Jul 3 09:23:51 CEST 2014


On 07/03/2014 04:14 AM, Llelan D. wrote:
> A common task I've coded is to run multiple implementations of the 
> same function head-to-head to profile their effectiveness. An example 
> would be a competition in which each of two implementations provide a 
> response for each match. The usual way in other interpreted languages 
> is to have the implementers write a source file implementing the same 
> function prototype (same name, arguments, and return type). You load 
> each one in their own namespace and run each for each match.
>
> Is there a way to load the functions in two .sci files so that the 
> second does not clobber the first. I can find no system for qualifying 
> function names or creating namespaces in Scilab. The files can not be 
> run in-place (without persisting in the session) since the exec() 
> function only loads the functions and does not run any. Using 
> statements outside of any function does no good as additional function 
> definitions might be required in the file to implement their algorithm.
>
> I've thought of using exec() on one file, qualifying the loaded 
> function names with <unique competitor name>_<function name> with 
> assignments and clearing the original function variables (which works 
> manually), and doing the same for the second file but I can find no 
> way of getting a list of functions loaded by the last exec().
>
> I'm either missing something really obvious or am stymied. Any help 
> would be greatly appreciated.
> _______________________________________________
> users mailing list
> users at lists.scilab.org
> http://lists.scilab.org/mailman/listinfo/users
>

I am not sure that I truly understand your problem, but maybe what 
follows can be helpful if you can run your two implementation sequentially:
- functions are first class citizens in scilab which mean you can copy 
them like normal variables:
myfunc=sin;
disp("myfunc(pi/2)="+string(myfunc(%pi/2)));
myfunc=cos;
disp("myfunc(pi/2)="+string(myfunc(%pi/2)));

Could this be used to solve your problem by renaming the implementation 
to test on the fly?

Antoine



More information about the users mailing list