[comp.lang.lisp] scoping

wagner@bnrmtv.UUCP (03/04/87)

ExperTelligence's common lisp produces a bug with the following
code.  I *believe* that it's a bug but the nuances of common lisp
scoping, extent, etc are sometimes confusing.  If anyone can
provide additional insight I would appreciate it.

;a function for summing the results of applying a function
;to each element of a list.

(defun sum (fn lst) 
   (apply #'+ (mapcar fn lst)))


;calls sum with a function which multiplies i by the argument (n)

(defun test (i)
   (sum #'(lambda (n) (* i n)) '(1 2 3)))

;call test with 2

(test 2) => error, i is bound to nil inside the unnamed lambda

It seems to me that i should be bound to 2.  Thanx in advance,
Mark Wagner @ BNR