OM# Documentation

Recursion

Recursion consists in calling a function in the body of this same function. It provides a powerful and elegant way to solve certain kinds of problems.

A typical example is the mathematical function factorial (also noted with !): 5! = 5 x 4 x 3 x 2 x 1.
The function factorial can be defined as:
factorial(n) - n x factorial(n-1).
It is important however, that the recursion have a termination condition. In the case of factorial, we need to complement the definition with:
factorial(0) = 1
In Common Lisp, factorial can be implemented as follows:

(defun factorial (n)     
  (if (<= n 0) 1 (* n (factorial (- n 1)))))

Note: Recursion is also a useful and powerful means to handle recursive data structures like trees.

In OM#, visual programs can be recursive as well, as long as they are set as global abstractions. Global (or “external”) abstractions are stored on the disk and referenced in the document manager, and therefore can be used from anywhere (not only locally in the patch where they have been placed — this is the case for “local”, or internal abstractions), including inside themselves.

→ Insert a global abstraction in itself as you would insert another global abstraction, that is, using one of the following options:

See more on “how to use global/external abstractions”.