[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Side effecting constants inside functions
Whoops! I didn't look at the function I sent. I inserted it from a file,
and of course it was the wrong file (a first attempt). The final version
is of course:
(defmacro compute-once (form)
(let ((cell (cons nil nil)))
`(if (car ',cell) (cdr ',cell)
(progn
(setf (car ',cell) t)
(setf (cdr ',cell) ,form)))))
Which uses the car as a valuep flag and the cdr as a value field.
As to typing it in directly, could you do something like (this hasn't been
tested):
(if (car '#1:(nil)) (cdr '#1#)
(progn (setf (car '#1#) t) (setf (cdr '#1#) <form>)))
This notation has come in handy more than once. Unfortunately, unless
there is another way to do things like caching, Common Lisp should have
some concrete definition of what we can and can't expect the semantics of
code which is self modifying or contains shared structure to be.
evan
-------