|
|
|
|
|
by lispm
3552 days ago
|
|
That's not too far away from Lisp. But in Lisp we would be using some quasiquote templates for this simple macro: (defmacro debug-it (&body expressions)
`(progn
,@(mapcar (lambda (expression)
`(format t "~%~a: ~a" ',expression ,expression))
expressions)))
Example: CL-USER 8 > (pprint (macroexpand-1 '(debug-it (+ 1 2) (* 3 4))))
(PROGN
(FORMAT T "~%~a: ~a" '(+ 1 2) (+ 1 2))
(FORMAT T "~%~a: ~a" '(* 3 4) (* 3 4)))
CL-USER 9 > (debug-it (+ 1 2) (* 3 4))
(+ 1 2): 3
(* 3 4): 12
NIL
|
|
There is one key difference between my code and yours: in mine, the functions, values, and symbols referenced in the macro are automatically renamed, thus guaranteeing no namespacing conflicts. Due to the way the CL package system works (IIRC), CL provides almost the same guarantees, at least in this case. But it is an important semantic difference.
And it is the Common Lisp. Despite how you may feel, Scheme, Clojure, PicoLisp, NewLisp, Racket, Interlisp, LeLisp, EuLisp, and others are as much a Lisp as CL.