TOC PREV NEXT

9  Folding

Ptolemy II supports a fold function, which can be used to program a loop in an expression.
The fold function is invoked in the form of fold(f, x, l), where f is a function itself, x is the starting value, and l is a collection of values.
The pseudocode for computing the result of the fold function fold(f, x, l) is as follows:
  1. let y = x
  2. for each element e in l
  3.     let y = f(y, e)
  4. return y
Examples:
TOC PREV NEXT