next up previous
Next: External Functions and Parentheses Up: Variables and Recursive Functions Previous: Special Variables

Recursion

Having variables allows us to write recursive functions. ccli provides the keyword fun for declaring recursive functions. Here's the hoary chestnut
fun fact n .
  if n <= 0
    then 1
    else n * fact (n-1)
  end;

fact 5;
that you see in every programming language manual. The code above sets the variable fact to a representation of the factorial function and then applies it to the value 5 to give 120.

Note, you can't do

fact := lambda n .
  if n <= 0
    then 1
    else n * fact (n-1)
  end;
because ccli will complain that fact is an unbound variable (which it is in this case: the right hand side of an assignment is always evaluated before the left hand side unless you use the fun keyword).



Eric Klavins 2003-12-03