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

Re: Side effecting constants inside functions



    Date: Tue 3 Sep 85 02:37:29-PDT
    From: Evan Kirshenbaum <evan@SU-CSLI.ARPA>

    (defmacro compute-once (form)
      (let ((cell (cons nil nil)))
	`(if (car ',cell) (cdr ',cell)
	     (setf (car ',cell) ,form))))

This has a bug too: if the form returns NIL, it will be computed more
than once.

However, the more interesting point is that it returns a form that has
internal sharing of list structure.  It seems quite possible to me that
some Common Lisp implementation out there might not handle this
properly.  For example, if a function using this compute-once were
written in a file, and the file were compiled with compile-file, and the
resulting bin file were loaded, the resulting compiled function might
end up having three different copies of the cell.

Another way to look at it is that the expansion of a function that
uses compute-once will be a piece of list structure that has no
readable printed representation.  That is, the macro lets you build
programs that are impossible to type in directly.

In my opinion, a Common Lisp implementation should not be required to
deal with cases such as this, just as it is not required to deal with
iteration implemented out of circular CONDs.