[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Side effecting constants inside functions
Actually, my earlier suggestion compiles inefficiently since it uses
a special variable in a way a compiler might not be able to catch and
simplify. A slightly better solution (more patterned after the original
suggestion) would be:
(defmacro compute-once (form)
(let ((cell (cons nil nil)))
`(if (car ',cell) (cdr ',cell)
(setf (car ',cell) ,form))))
The main difference between this and the original is that the let is done
at expansion time rather than at execution time. This code does modify
itself (although I had to try it out to make sure that it actually worked
the way I thought it would), but it doesn't run into the problem with
read-only areas that as inherent in the other one.
-------