Module for overloading Scilab functions
April 2006.
What is it ?
Overloading means that, when a function is invoked with an object
as input argument, it is not the standard funtion which is applied
but a version specific to the considered object.
For example, a function func specific to a typ-object must be named
%typ_func (prefix %typ_). If x is a typ-object,
typing func(x) will invoke automatically %typ_func(x).
What is called "object" here consists of a Scilab mlist (see help mlist).
For example, a sym-object looks like
x = mlist(['sym','str1'],'xxxxxx'), x.str1 is equal to 'xxxxxx'.
A large number of Scilab built-in functions (not all unfortunately) take
overloading into account. Examples of such functions: size, real,
imag, abs, conj, log, exp, sqrt,
cos, sin, acos, asin....
This module permits the user to overload most non-built-in functions.
It is a complement to the Symbolic Toolbox and to the Linear Fractional
Representation Toolbox but it can also be used for any kinds of user-defined objects.
How does it work?
Two main files:
- updater.sce: Scilab script which generates automatically all the files required for
overloading. This script can be customized by defining a modified list of the functions which
must become overloadable. The default list is consistent with the Symbolic Toolbox and the Linear
Fractional Representation Toolbox.
- overloader.sci: Scilab function. This function checks the nature of the first input
argument of invoked functions (if in the list defined in the above script)
and invokes the relevant function (note that currently only the first input argument
is considered for this test).
The functions listed in updater.sce are treated as follows (three cases):
- Built-in functions are ignored.
- Existing Scilab function case: The original function is copied in OVLD/macros and renamed
with the prefix %old_, in addition, this prefix is also added to the function
name inside the file. A new file having the original name is created in OVLD/macros
but this new function just calls overloader.sci which selects the function
to be really invoked (add prefix %old_ or a prefix corresponding to the object class
of the first input argument).
- Non-existing Scilab function case: As above, except that the file with prefix %old_
only contains an error message.
Installation.
First time you use this module. After you have unzipped the file containing this module:
- If this module is used only as a complement of the Symbolic Toolbox
or of the Linear Fractional Representation Toolbox, skip this item. Otherwise,
open the file updater.sce in a text editor and modify the vector of strings
containing the names of the functions to be overloaded. Finally
From the 'file' menu of a Scilab window, navigate to the directory OVLD
where this module was unzipped and execute updater.sce.
-
From the 'file' menu of a Scilab window, navigate to the directory OVLD
where this module was unzipped and execute builder.sce and then,
loader.sce.
Next time you start Scilab, it suffices to execute the loader.sce scripts.
It is better to execute this script from the .scilab startup
file for automatic loading. This file should be in
<HOME DIRECTORY>\Scilab\scilab-x.x\
(Windows) or in ~/.Scilab/scilab-x.x/ (Unixes).
|