This section demonstrates how higher-order root code works, how root is created with Scheme, and more about how it is displayed graphically.

The following Scheme procedure:

is equivalent to the root program created by the following Scheme code:

make-closure, unmake-closure, and call are Scheme procedures used to simplify writing higher-order code:

(make-closure code-name save-locals result-name)
(unmake-closure restore-locals closure)
(call closure args)

code-rec makes the small changes required to convert sexpr syntax into code structures. It's most important task is to ease building recursive procedures by replacing names of codes with the actual values.

The above Scheme code expands into the following code structure. Compose creates and returns a closure (ag) made of apply-g and f and g. [more?]

Graphically it appears:


Dotted lines link jump instructions to any code structures passed as arguments, generally they are continuations or closures.