Version 3.0 of T supports multiple return values. This makes procedure call and return uniform, in the sense that a procedure can be invoked with zero or more values and can return zero or more values.
(return {value}*)
{value}*
procedure
return returns its arguments as the value(s) of the current expression. In order to access the value(s) of a return expression the value(s) must be bound to identifiers using either receive or receive-values.
For example,
formula vobeyspaces : |
where `` 1 2 3'' denotes evaluates to the three values 1, 2, and 3.
Like procedures, continuations have certain expectations about the number of arguments (values) that will be delivered to them. It is an error if more or fewer values are delivered than expected. There are only a small number of ways to create continuations, thus one need only understand these cases:
formula vobeyspaces : |
but
formula vobeyspaces : |
return when invoked invoked with no arguments returns to the calling procedure with no value. Thus (return) will return to its caller with no value. It is an error to return no value to a value-requiring position. For example,
formula vobeyspaces : |
The idiom (return) is useful for procedures that return an undefined value and many of the system procedures whose value(s) is undefined now return no value. However, the procedure undefined-value may provide a more informative error message.
(receive-values receiver sender)
value(s) of receiver
procedure
receive-values returns the value of applying receiver, a procedure of n arguments, to the values returned by sender. sender is a thunk thunk , a procedure of no arguments, which returns n values.
For example,
formula vobeyspaces : |
(receive ({ident}*) expression {body}*)
value of body
syntax
In a receive form the expression is evaluated in the current environment and the values returned by the expression are bound to the corresponding identifiers. body, which should be a lambda body, i.e. a sequence of one or more expressions, is evaluated in the extended environment and the value(s) of the last expression in body is returned.
The expression
formula vobeyspaces : |
is equivalent to
formula vobeyspaces : |
Other forms have been extended in T3.0 to allow multiple return values:
(catch identifier {body}*)
value of body
syntax
The identifier is bound to the continuation continuation of the catch form, which is now an n-ary procedure. This means that catch forms can ruturn multiple values. The continuation can be invoked only during the dynamic extent of the catch form (see section ). In T2 the continuation was a procedure of one argument. For example,
formula vobeyspaces : |
(ret {value}*)
{value}*
procedure
Returns zero or more values as the value of the current read-eval-print loop.