<<<<<<<<<<<<<<<<<

procedure(prog_tools) Programming Tools procedure(prog_tools)

NAME

procedure - procedure objects for LYMB scripts

DESCRIPTION

The procedure object defines a set of actions and parameters to those actions that give the LYMB script writer a code packaging capability similar to functions in C. Arguments can be passed by value (in_args= and out_args=) or passed by reference (ref_args=). All instances created within a procedure are local to the procedure. These instances can be made global, that is available outside the procedure, by specifying their names as arguments to a make_global: message to the class msg.

SUPERCLASS

object

MESSAGES

in_args= (arg1,arg2,...) Declares the arguments to be copied into the in_formals of the procedure at the beginning of the next call! message. If an argument is a number, a scalar object will be instantiated when the procedure is sent a call! message. If the argument is a string, it is assumed to be the name of an object unless the string begins with the character "", in which case the "" is stripped and the rest of the string is assumed to be a string literal. A local string object will be instantiated with the literal as its value when the procedure is sent a call! message. To insert a literal "" as a leading character in an argument, use two "" characters. The in_args will need to be set each time a call! message is sent, as they are overridden on recursive calls to the procedure.

out_args= (arg1,arg2,...) Declares the names of the objects to be modified from the out_formals of the procedure at the end of the next call! message. All out_args must exist at the time the call! message is sent. The out_args will need to be set each time a call! message is sent, as they are overridden on recursive calls to the procedure.

ref_args= (arg1,arg2,...) Declares the names of the objects to be passed by reference to the procedure.

in_formals= (formal1,formal2,...) Declares the names of the input parameters as they are referred to in the procedure's call_actions.

out_formals= (formal1,formal2,...) Declares the names of the output parameters as they are referred to in the procedure's call_actions.

ref_formals= (arg1,arg2,...) Declares the names of the by-reference parameters as they are referred to in the procedure's call_actions.

call_actions= LYMB statements defines the body of the procedure.

call_actions+ LYMB statements appends statements to the body of the procedure.

return_value=(val1,val2,...) associates a list of values with the return value of the procedure. These can be set from anywhere, although they will most often be set from inside the procedure's call_actions.

return_value? returns the current return value(s) of the procedure.

break! stop parsing the call_actions block after completion of the current group of LYMB staments.

call! Executes the call_actions of the procedure. Before the actions are executed, a new symbol table is pushed on the symbol table stack and it is populated by executing (effectively) "arg new: formal;" for each in_arg/in_formal and out_arg/out_formal pair. After the actions are executed, any output arguments object pointers are swapped with their corresponding output formal object pointer (which may have been destroyed and recreated during the call_actions). The symbol table is then freed, implicitly freeing all in_formals, local objects created by the call_actions, and now defunct out_args.

EXAMPLES

The following procedure recursively computes the factorial of its input argument.

procedure new: `fact' in_formals=(`i') call_actions=` logic new! less:(i,2) false:` i - 1; fact in_args=(`i') call!;

i + 1; i * [fact return_value?]; fact return_value= i; ' true:` fact return_value= 1; ' free! ; ' ;

The following procedure creates a motif_label that will exist beyond the scope of the procedure call. The name is generated using a string object thats life is limited to the life of the procedure call. The name of the motif_label is available to the caller using the procedure's return_value? message.

procedure new: `create_label' ref_formals=(`parent', `index') call_actions=` string new: name float_format= `label_0.000' = index; msg enable_globals!; motif_label new: name parent= parent create!; create_label return_value= name; ' ;

SEE ALSO

actions, msg, metaclass, reference

NOTES AND BUGS

Note that the length of the in_args and in_formals lists, the out_args and out_formals lists, and the ref_args and ref_formals lists must match at the time the call! message is sent. Objects can appear in both in_args and out_args lists, in which case they will be copied in at the start and replaced at the end.

Internally, each ref_formal is represented by a reference object. Instances of the reference class forward all messages except does_not_understand, name=, free!, and referent= to the objects they reference.


Please send comments and suggestions to
consult@rpi.edu