Avoiding Variable Capture with Scope
(defmacro sum-squares-w (x y)
`(let* ((x0 ,x) ; WRONG (X0 captured)
(y0 ,y) ; problem occurs in this line
(x2 (* x0 x0)) ;; if form y refers
(y2 (* y0 y0))) ;; to x0
(+ x2 y2)))
(defmacro sum-squares-r (x y)
`(let ((x0 ,x) ; RIGHT
(y0 ,y))
(let ((x2 (* x0 x0))
(y2 (* y0 y0)))
(+ x2 y2))))
Previous slide
Next slide
Back to first slide
View graphic version