[Small-cl-src] with-carry
Peter Lewerin
peter.lewerin at swipnet.se
Tue Sep 28 09:12:47 UTC 2004
#|
In a reply to me in c.l.l., Adam Warner suggested a control structure for the
cases when a computation is made in stages, with the result of each stage used
somewhere in the next stage. The following is basically his code; I added a
SYMBOL-MACROLET wrapper to be able to name the carry-over variable.
See c.l.l. thread "Which style do you prefer?"
|#
(defmacro with-carry (c stages &body body)
(symbol-macrolet ((_ c))
`(let* (,@(loop for item in stages collect (list _ item)))
, at body)))
;; (with-carry x ((+ 2 3) (* x 10)) (print x))
;; => 50
;; expands to: (LET* ((X (+ 2 3)) (X (* X 10))) (PRINT X))
More information about the Small-cl-src
mailing list