Recursive programs can be designed in OM by inserting the reference of a blue patch in its own editor – that is, putting a patch within itself. If this patch has inputs and outputs, they will also appear on the patch box, so that the patch can be "called from inside itself".
A termination condition is absolutely necessary to call a recursive patch. Otherwise, a succession of infinite calls will be triggered at the evaluation. Remind to save all your material before calling a recursive patch.
We have renamed the recursive patch as "fact". We will use it to create a recursive function that actually corresponds to the factorial function. The function has one input, n, which calculates fact(n) = n * fact(n-1). This function has no termination condition. If it is called in its current state, it will never end.
| ![]() |
The resulting patch means : if n = 1, then fact(n) = 1 else, fact(n) = n * fact(n-1)
When omif is evaluated, it evaluates the = predicate.
The = predicate returns "nil" if n ≠ 1 and "t" if n = 1. This is the termination condition of the patch.
Do not ever build recursive programs with internal – red – patches, or with OMLoop boxes. A function has to be global to apply within itself.