9.6 Immutable Objects

GAP 4 supports ``immutable'' objects. Such objects cannot be changed, attempting to do so issues an error. Typically attribute values are immutable, and also the results of those binary arithmetic operations where both arguments are immutable, see Section Vectors and Matrices. For example, [ 1 .. 100 ] + [ 1 .. 100 ] is a mutable list and 2 * Immutable( [ 1 .. 100 ] ) is an immutable list, both are equal to the (mutable) list [ 2, 4 .. 200 ].

There is no way to make an immutable object mutable, one can only get a mutable copy by ShallowCopy. The other way round, MakeImmutable makes a (mutable or immutable) object and all its subobjects immutable; one must be very careful to use MakeImmutable only for those objects that are really newly created, for such objects the advantage over Immutable is that no copy is made.

More about immutability can be found in Sections Immutability in this tutorial and Mutability and Copyability in the Reference Manual.

[Top] [Previous] [Up] [Next] [Index]

GAP 4 manual
February 2000