next up previous contents index
Next: 3.3 Definition of Operations Up: 3.2 Defining and Using Previous: 3.2.3 Global and Local

3.2.4 Special Function Commands

Scilab has several special commands which are used almost exclusively in functions. These are the commands

The following example runs the following foo function which illustrates these commands.

function [z]=foo(x,y)
[out,in]=argn(0);
if x=0 then,
     error('division by zero');
end,
slope=y/x;
pause,
z=sqrt(slope);
s=resume(slope);
 
--> z=foo(0,1)
error('division by zero');
                          !--error 10000 
division by zero                                                                
at line       4 of function    foo      called by :  
 z=foo(0,1)
 
 
--> z=foo(2,1)
 
-1-> resume
 z         =
 
    0.7071068  
 
--> s
 s         =
 
    0.5
In the example, the first call to foo passes an argument which cannot be used in the calculation of the function. The function discontinues operation and indicates the nature of the error to the user. The second call to the function suspends operation after the calculation of slope. Here the user can examine values calculated inside of the function, perform plots, and, in fact perform any operations allowed in Scilab. The -1-> prompt indicates that the current environment created by the pause command is the environment of the function and not that of the calling environment. Control is returned to the function by the command return. Operation of the function can be stopped by the command quit or abort. Finally the function terminates its calculation returning the value of z. Also available in the environment is the variable s which is a local variable from the function which is passed to the global environment.


next up previous contents index
Next: 3.3 Definition of Operations Up: 3.2 Defining and Using Previous: 3.2.3 Global and Local
Scilab Group