I was playing with code generation outside macro being inspired by corrected version of nif
https://letoverlambda.com/index.cl/guest/chap3.html#sec_5
When I replace the usual gensym with my interned-gensym I can skip the eval and have more noob friendly version of the code that I can easily copy to REPL for further experiments with macro code creation.
When it’s done, will I be able to replace with defmacro?
Why the usual gensym in macro is not interned?
Besides the eval is evil, what are other pitfalls of writing code this way?
(defun interned-gensym ()
"More suitable variant of gensym for macro experiments"
;; file:~/Programming/sbcl/src/code/symbol.lisp::593
(values (intern (format nil "Z~A"
(let ((old *gensym-counter*))
(setq *gensym-counter* (1+ old))
old)))))
;;; nif
(eval (apply (lambda (expr pos zero neg)
(let ((gexpr (interned-gensym)))
`(let ((,gexpr ,expr))
(cond
((plusp ,gexpr) ,pos)
((zerop ,gexpr) ,zero)
(T ,neg)))))
;; args for the lambda
((- 5 2) :positive :zero :negative)))
You must log in or register to comment.