[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Side effecting constants inside functions



>(defmacro compute-once (form)
>   `(let ((value '(,nil . ,nil)))
>      (cond ((car value) (cdr value))
>              (t (setf (car value) t)
>                 (setf (cdr value) ,form))))

But wouldn't it be more reasonable to do something more like:

(defmacro compute-once (form)
  (let ((var (gensym)))
    `(if (boundp ',var)
	 ,var
	 (setf ,var ,form))))

This lacks the self-modifying-ness of the original example.

    
-------