up previous next
return

exit from a function

Syntax
return
return E

where E is an expression.

Description
This function is used to exit from a procedure/function. The latter form (function) returns the value of the expression E to the user. As a safety measure all return s in a function/procedure must be of the same kind: either they all return a value (function) or none returns a value (procedure). To exit from a loop see break .

Example
  Define Rev(L) -- reverse a list
    If Len(L) < 2 Then Return L; EndIf;
    M := Rev(Tail(L)); -- recursive function call
    Append(ref M, L[1]);
    Return M;
  EndDefine;

/**/  Rev([1,2,3,4]);
[4, 3, 2, 1]

  -- mixing function/procedure returns is not allowed
  Define AFailingExample(X)
    If X=1 Then Return 123456;
    Else Return; -- .....
 ERROR: Inside a function definition all Return statements must be
  either with or without an expression
    Else Return;
         ^^^^^^^

See Also