Any equate can be called from within an equate. It can be passed
arguments and any value returned can be assigned to a variable or
used in an expression. An equate is called by simply
giving its name (with optional brackets). If the equate matches the name of a
local variable then the value of the variable will be returned else the equate
will be called to return a value. An equate need not take any arguments nor
return any value although they commonly do. Arguments are passed to an equate
as a comma separated list of expressions between brackets that immediately
follow the equate name. If the equate returns one argument this can be simply
assigned to a variable, or used in an expression. If the equate returns
multiple arguments then the @(...)
operator sequence should be used to
assign the results to multiple variables. Some examples of equate calls are
shown below.
%%EQUATE test "hello" >> s "b" + substr(s,1,1+3) + "ws" >> s
Using the previously defined equate substr()
the above would result in
"bellows"
being assigned to s
.
Arguments to an equate are defined using the inputs(...)
keyword
sequence. Between the brackets there can be nothing or there should be a comma
separated list of variable names to which the arguments passed into the equate
will be assigned (the variables will be created with the data type of the
argument passed in). Instead of using the inputs
keyword it is also
possible to put the bracket sequence immediately following the definition
of the equate name. The return values from an equate are similarly defined
using the outputs(...)
keyword sequence. This takes a comma separated
list of expressions (normally just one) the values of which are returned to the
calling equate. Both the inputs
and outputs
keyword sequences are
optional but if they are used the inputs
must be the first line of
the equate and the outputs
must be the last line of the equate (or at
least the last executed expression) - the outputs
keyword cannot be used
as a return escape. The example below shows the definition of an equate that
takes two arguments and swaps the values around while also adding 10 to each
value returning the two swapped arguments and then an example of that equate
being called.
%%EQUATE swap inputs(a,b) outputs(b+10,a+10) %%EQUATE test 5 >> x 7 >> y swap(x,y)@(x,y)
The test
equate will result in x
equaling 17 and y
equaling
15. Note the use of the @
operator to handle the passing back of multiple
arguments. Note that swap(x,y) >> y >> x
would be equivalent to the above
but the assignments must be put in reverse order to the arguments sent back.
Go to the first, previous, next, last section, table of contents.