[Contents] · [Home] · [Mail]

SALIERI Language - function (Object Type)

Objects of type function represent user-defined functions in SALIERI. They are created using the constructor FUNC and can be assigned, copied, modified or deleted just as objects of any other type in SALIERI.

Functional objects can be executed by using either the standard function call syntax (as for built-in SALIERI function, cf. Section User-defined Functions) or the apply function. Function definitions can be recursive, i.e., a function can call itself from within its function body. However, when working with recursive functions, one should be carefull to avoid too deep or endless recursions which might lead to system crashes.

Functions have a local workspace, i.e., all objects created or modified within a function body are local to that function and exist only while the function body is executed. Function parameters are evaluated and stored as local objects $1, $2, etc. before a function body is executed. To quit a function body and possible return a function result (which might be an object of arbitrary type), the return function is used.

Macros represent a subtype of functions, they are only different from functions in that they have no local workspace and consequently can be used to manipulate objects in the global workspace.

Blocks are special, parameter-less functional objects which are used to realise function bodies and bodies of control functions, such as loops and conditionals.

Internal functions are objects representing the predefined functions of SALIERI; they make it possible to copy built-in functions, to pass them as function parameters and to execute them using apply.

Example:
> f := FUNC(1, `res := $1+$1; write(res)')
> f(3)
6
> f([c1/4 d])
[c1/4 d1/4 c1/4 d1/4]
> f2 := FUNC(1, `return(retro($1))')
> s := f2([c1/4 d]
> s
Result= [d1/4 c1/4]
> f3 := FUNC(-1, `write(length($1)); return($1)')
> f3([c#1/2],[f#1/4])
2
Result= LIST([c#1/2],[f#1/4])

See also: User-defined Functions, FUNC, apply, return, Macros, Blocks, internal function (Object Type).


[Contents] · [Home] · [Mail]
© sic!systems, page frame designed by hh; this page has been automatically generated from the SALIERI Documentation Database.