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); endfunction
--> 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.