[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Lexical closures (bug?)

We were working thru the exercises in Charniak, Riesbeck & McDermot, 
Artificial Intelligence Programming, and tried the following:

(defun compose (&rest functions)
  #'(lambda (x)
      (do ((fns functions (cdr fns))
	   (value x (funcall (car fns) value)))
	  ((null fns) value))))

This should return the composition of the functions passed as
arguments; e.g. (compose #'1+ #'1+) should return a closure which should
increment its argument by 2:

(setq 2+ (compose #'1+ #'1+))
(funcall 2+ 4) => 6

However, when I try this on my 36xx, with either Genera 7.1 or 7.2, the
control stack overflows.  In fact if I print the "(car fns)" it is
apparnet that in each iteration what is being funcalled is not the next
function, but the entire closure!

Any ideas?

Larry Baum