To define a function recursively, refer to it within the function body by the pseudo-identifier $$.
If the function is assigned to an identifier NAME using this syntax:
function NAME(FORMAL_IDFIER, ..., FORMAL_IDFIER) STATEMENTS end function;
instead of:
NAME := function(FORMAL_IDFIER, ..., FORMAL_IDFIER) STATEMENTS end function;
then the function may also be referred to by its own name within the function body.
The parser understands these two forms to be the same, except that any textual reference to NAME inside STATEMENTS is changed to the pseudo-identifier $$.
> Fibonacci := func< n | n le 2 select 1 else $$(n-1) + $$(n-2) >; > print Fibonacci(8); 21> function Lucas(n) function> if n eq 1 then function|if> return 1; function|if> elif n eq 2 then function|if> return 3; function|if> else function|if> return Lucas(n-1)+Lucas(n-2); function|if> end if; function> end function;
OR
> Lucas := function(n) function> if n eq 1 then ... function|if> return $$(n-1)+$$(n-2); function|if> end if; function> end function;
[Next] [Prev] [_____] [Left] [Up] [Index] [Root]