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

Destructive operations



On p.78 of CLtL, in the description of the function EQ, is the
following paragraph:

``An additional problem with EQ is that the implementation is permitted
to "collapse" constants (or portions thereof) appearing in code to be
compiled if they are EQUAL.  An object is considered to be a constant
in code to be compiled if it is a self-evaluating form or is contained
in a QUOTE form.  This is why (EQ "Foo" "Foo") might be true or false;
in interpreted code it would normally be false, because reading in the
form (EQ "Foo" "Foo") would construct distinct strings for the two
arguments to EQ, but the compiler might choose to use the same
identical string or two distinct copies as the two arguments in the
call to EQ.  Similarly, (EQ '(A . B) '(A . B)) might be true or false,
depending on whether the constant conses appearing in the QUOTE forms
were collapsed by the compiler.  However, (EQ (CONS 'A 'B) (CONS 'A
'B)) is always false, because every distinct call to the CONS function
necessarily produces a new and distinct cons.''

Because the compiler is permitted to share structure with constants in
compiled code, it follows that modifying such a constant is illegal.
Some systems place such constants in a read-only region of memory.