rec.name := obj;
The record assignment assigns the object obj, which may be an object of arbitrary type, to the record component with the name name, which must be an identifier, of the record rec. That means that accessing the element with name name of the record rec will return obj after this assignment. If the record rec has no component with the name name, the record is automatically extended to make room for the new component.
gap> r := rec( a := 1, b := 2 );; gap> r.a := 10;; r; rec( a := 10, b := 2 ) gap> r.c := 3;; r; rec( a := 10, b := 2, c := 3 )
IsBound (see IsBound) can be used to test if a record
has a component with a certain name, the function
Unbind (see Unbind)
can be used to remove a component with a certain name again.
Note that assigning to a record changes the record. The ability to Identical Records).
- = obj;
This construct is similar to the above construct. The difference is that the second operand name is evaluated. It must evaluate to a string or an integer otherwise an error is signalled. The construct then assigns obj to the record component of the record rec whose name is, as a string, equal to name.
If rec does not evaluate to a record, name does not evaluate to a
string, or obj is a call to a function that does not return a value,
quit;. On the other hand
you can continue the assignment by returning a record in the first case,
a string in the second, or an object to be assigned in the third, using
Previous Up Top Next