function command order
A class is allowed to have any number of functions.
A function is similar to a routine, except that a function
returns a result. This makes the Function command somewhat
different than the Routine command, because it has to
specify what type(int, real or bool) or what class(Str, ...)
the function will be returning. Another difference between
functions and routines is that functions require the first
Box or Boxes command to be a Box command, and the name
for this box must be result.
The final difference between a routine and a function is that
functions are not allowed to have side effects. The
purpose of a function is to computer a result, based on the
values of the slots passed into the function. Since routines
are allowed to have side effects, functions are not allowed to
call routines.
Here is a list of the command order requirements for a function:
- Function command (required)
- Slot commands (if any)
- Box command for the result (required)
- Box and Boxes commands (if any)
-- Does: a description goes here (required)
- action commands (at least one command must assign to the result box)
- EndFunction command (required)
A function starts with a Function command.
This is followed by any number of Slot commands.
A function could accept values passed into slots.
If this is the case, you need one slot command for each
slot (in which the function is expecting a value to be passed into it).
These slot commands, if any,
are followed by a Box command for the result
(which are only seen within this function, so
you do not specify is public or
is private).
This is followed by any number of Boxes and Box commands
(which are only seen within this function, so
you do not specify is public or
is private). This is followed by an optional
comment describing what this function does.
This is followed by any number of action commands.
At least one of these action commands must be
a Set command which sets the value of the result box.
The function concludes with an EndFunction command.