What would be the reasonable way to create a function-local variable with indefinite extent; i.e. that keeps its value between invocations of the function? The "function-local" part isn't really critical, of course, as long as it doesn't dirty the namespace otherwise. My naive implementation, I guess, would look something like this:
Code: Select all
(defmacro let-indef (var init-form &body body)
(let ((real-var (gensym)))
`(locally
(declare (special ,real-var))
(unless (boundp ,real-var) (setf ,real-var ,init-form))
(symbol-macrolet ((,var ,real-var))
,@body))))