The basic operations for lists are element access (see List Elements), assignment of elements to a list (see List Assignment), fetching the length of a list (see Length), the test for a hole at a given position, and unbinding an element at a given position (see IsBound and Unbind for Lists).
The term basic operation means that each other list operation can be formulated in terms of the basic operations. (But note that usually a more efficient method than this one is implemented.)
Any GAP object list in the category IsList (see IsList) is regarded
as a list, and if methods for the basic list operations are installed for
list then list can be used also for the other list operations.
For internally represented lists, kernel methods are provided for the basic list operations. For other lists, it is possible to install appropriate methods for these operations. This permits the implementation of lists that do not need to store all list elements (see also Enumerators); for example, the elements might be described by an algorithm, such as the elements list of a group. For this reduction of space requirements, however, a price in access time may have to be paid (see ConstantTimeAccessList).
\[\]( list, pos ) O
IsBound\[\]( list, pos ) O
\[\]\:\=( list, pos, val ) O
Unbind\[\]( list, pos ) O
These operations implement element access, test for element boundedness, list element assignment, and removal of the element at position pos. In all cases, the index pos must be a positive integer.
Note that the special characters [, ], :, and = must be escaped with
a backslash \ (see Symbols);
so \[\] denotes the operation for element access in a list,
whereas [] denotes an empty list.
(Maybe the variable names involving special characters look strange,
but nevertheless they are quite suggestive.)
\[\]( list, pos ) is equivalent to list[ pos ],
which clearly will usually be preferred;
the former is useful mainly if one wants to access the operation itself,
for example if one wants to install a method for element access in a
special kind of lists.
Similarly, IsBound\[\] is used explicitly mainly in method installations.
In other situations, one can simply call IsBound, which then delegates to
IsBound\[\] if the first argument is a list, and to IsBound\. if the
first argument is a record.
Analogous statements hold for \[\]\:\= and Unbind\[\].
[Top] [Previous] [Up] [Next] [Index]
GAP 4 manual