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

How constant are defconstants?



Jim,

The following is my own view on this issue.  If anyone out there in
net-land disagrees, speak up.

The concept of enforced read-only data structures is not included in
Common Lisp, because implementations on some machines and on some
operating systems just couldn't hack that without an unacceptable
penalty in performance.

It "is an error" to mess with something declared to be a constant, which
means that the compiler can play various tricks, but doesn't have to.  An
implemenations could build such a structure in some sort of read-only
space and signal an error if you try to alter it, but again it doesn't
have to.  The same is true with :READ-ONLY slot options in Defstruct --
all this really guarantees is that no SETF form is created for this
slot.

So if you want to create a read-only structure that guarantees to signal
an error if you touch it, there may be a way to do this in some
implemenations, but there's no way to do this in portable Common Lisp.
You might just as well create your structure with DEFVAR.

-- Scott