Skip to main content

3.7 Destructive Operations

3.7.1 Modification of Literal Objects

The consequences are undefined if literal objects are destructively modified. For this purpose, the following operations are considered destructive:

random-state

Using it as an argument to the function random.

cons

Changing the car 1 or cdr 1 of the cons, or performing a destructive operation on an object which is either the car 2 or the cdr 2 of the cons.

array

Storing a new value into some element of the array, or performing a destructive operation on an object that is already such an element.

Changing the fill pointer , dimensions, or displacement of the array (regardless of whether the array is actually adjustable).

Performing a destructive operation on another array that is displaced to the array or that otherwise shares its contents with the array.

hash-table

Performing a destructive operation on any key.

Storing a new value4 for any key, or performing a destructive operation on any object that is such a value.

Adding or removing entries from the hash table.

structure-object

Storing a new value into any slot, or performing a destructive operation on an object that is the value of some slot.

standard-object

Storing a new value into any slot, or performing a destructive operation on an object that is the value of some slot.

Changing the class of the object (e.g., using the function change-class).

readtable

Altering the readtable case.

Altering the syntax type of any character in this readtable.

Altering the reader macro function associated with any character in the readtable, or altering the reader macro functions associated with characters defined as dispatching macro characters in the readtable.

stream

Performing I/O operations on the stream, or closing the stream.

All other standardized types

[This category includes, for example, character, condition, function,

method-combination, method, number, package, pathname, restart, and symbol.] There are no standardized destructive operations defined on objects of these types.

3.7.2 Transfer of Control during a Destructive Operation

Should a transfer of control out of a destructive operation occur (e.g., due to an error) the state of the object being modified is implementation-dependent.

3.7.2.1 Examples of Transfer of Control during a Destructive Operation

The following examples illustrate some of the many ways in which the implementation-dependent nature of the modification can manifest itself.

(let ((a (list 2 1 4 3 7 6 ’five)))

(ignore-errors (sort a #’<))

a)

→ (1 2 3 4 6 7 FIVE)

or (2 1 4 3 7 6 FIVE)

or (2)

(prog foo ((a (list 1 2 3 4 5 6 7 8 9 10)))

(sort a #’(lambda (x y) (if (zerop (random 5)) (return-from foo a) (> x y))))) → (1 2 3 4 5 6 7 8 9 10)

or (3 4 5 6 2 7 8 9 10 1)

or (1 2 4 3)