Scilab プロシージャおよび Scilab オブジェクト
functions は Scilab プロシージャ ("macro", "function" および "procedure" have the save meaning)です.
通常,これらはエディタによりファイルで定義され, exec関数またはライブラリ (lib または genlib参照) によりScilabにロードされます. しかし,オンライン定義 (deff または function参照) することも可能です. 関数は以下の2つの要素により定義されます::
以下のような "構文定義" 部:
一連のScilab命令.
"構文定義" 行はこの関数の"完全な"呼び出し手順を指定します.
yi は,入力変数xiと
その関数が実行された際にScilabに存在する変数の関数として
計算される出力変数です.
通常,関数の呼び出し手順は
[y1,...,yn]=foo(x1,...,xm)となります.
入力または出力引数の一覧を定義より短くすることができます.
このような場合,
左辺の先頭のいくつかの変数のみが使用され設定されます.
呼び出し時の引数の実際の数は, argn により取得することができます.
It is possible to define function with indeterminate number of input or output maximum number of arguments. This can be done using the varargin and varargout keywords. See the given links for details.
It is also possible to use "named argument" to specify input
arguments: suppose function fun1 defined as
function y1=fun1(x1,x2,x3) then it can be
called with a syntax like y=fun1(x1=33,x3=[1 2
3]) within fun1 x2 will be
undefined,
it can also be called with a syntax like
y=fun1(x1=33,y='foo'). In such a case the
y variable will be available in the context
of the function fun1. Note that the maximum
number of argument must be less or equal to the number of
formal input argument used in the function syntax part.
It is possible to check for defined variables with the exists function.
When a function has no left hand side argument and is called only with character string arguments, the calling syntax may be simplified:
is equivalent to:
fun a toto 'a string' | ![]() | ![]() |
Functions are Scilab objects (with type numbers 13 or 11). They and can be manipulated (built, saved, loaded, passed as arguments,..) as other variable types.
Collections of functions can be collected in libraries. Functions
which begin with % sign
(e.g. %foo) are often used to overload (see overloading
) operations or functions for new data type.