previous chapterthe pico pagenext chapter


Factorials

Let us try and repeat this approach in order to compute factorials:

This recurrence relationship can again readily be transformed into a Pico function:

In the above transcript, the function application fac(10) will result in 9 recursive applications, ending when n reaches 1. Backtracking from this level, the necessary arithmetic is performed to compute 10! = 3628800.

Trying this out for other values of the argument, we eventually run into trouble:

We must never forget that in the physical world, somewhere in our tower of REP-machines there is a level at which we will encounter constraints on the values that we use in our programs. In this case we violated a rule stating that numbers cannot exceed the range [-1073741824, 1073741823].


previous chapterthe pico pagenext chapter