Print out demo1.txt. They should work exactly as shown. The same sequence steps will derive the equatios of motion for this new arm. The global variables were necessary because these derivations produce astonishingly large symbolic expressions. Passing them on the stack just didn't work.
Dynamic programming is used extensively.
For example, when the expression for the link transform from link 5 to link 3 is first referenced, the result is computed from the basic forward transforms. The result is then saved. Future references to this transform use the saved value, and do not re-compute the transform from scratch. Practically every expression on the LE and NE utilities use this dynamic programming technique. It precluded what would otherwise huge amounts of redundant symbolic computation.