Contents    Page-10    Prev    Next    Page+10    Index   


Suppose we have the following definition of a function power(x,n) that computes xn :

(defun power (x n)
  (if (= n 0)
      (if (evenp n)
          (square (power x (/ n 2)))
          (* x (power x (- n 1))))))

If this is used with a constant argument n, as is often the case, the function can be partially evaluated into more efficient code:

(gldefun t3 ((x real)) (power x 5))

(glcp 't3)
result type: REAL
The recursive function calls and interpretation ( if statements) have been completely removed; only computation remains. Note that the constant argument 5 is gone and has been converted into control.