| 156 | | * Sequences, sets, maps, and relations are immutable. An assignment using objects of this type creates a new copy of the object, just as with primitive types like `int`. |
| 157 | | * The main difference between the array type and the sequence type is that elements of an array are addressable, i.e., one can form a pointer such as `&a[i]`. This is not possible with sequences, sets, maps, or relations---there is no way to have a pointer to any component of such a type. |
| | 156 | * Sequences, sets, maps, relations, and `$mem` objects are immutable. An assignment using objects of this type creates a new copy of the object, just as with primitive types like `$int`. |
| | 157 | * Arrays are similar to sequences. The main differences are as follows: |
| | 158 | * An object (i.e., a variable or component of an object) of array type is initialized once, then will never be assigned to again. Hence there cannot be a statement of the form `a=...` where `a` has array type. |
| | 159 | * After initialization, an object or array type can appear only as the first (left) argument to the subscript operator `[]` or as the argument to the `$length` operator. |
| | 160 | * Arrays are mutable. As in C, the left hand size of an assignment may have the form `a[i]`, where `a` is an object of array type. Sequences are immutable. |
| | 161 | * Elements of an array are addressable, i.e., one can form a pointer such as `&a[i]`. This is not possible with sequences, sets, maps, or relations---there is no way to have a pointer to any component of such a type. |
| | 162 | * A function may neither consume nor return an object of array type. There is no such restriction for sequences. |
| 280 | | <T> $seq<T> $seq_set( $seq<T> a, $int i, T x ); // seq obtained by replacing element i of a with x |
| 281 | | <T> $seq<T> $seq_subseq( $seq<T> a, $int start, $int stop ); // subsequence from start to stop-1 |
| 282 | | <T> $seq<T> $seq_add( $seq<T> a, T e ); // sequence obtained by adding element e to the end of a |
| 283 | | <T> $seq<T> $seq_append( $seq<T> a1, $seq<T> a2 ); // sequence obtained by concatenating a1 and a2 |
| 284 | | <T> $seq<T> $seq_remove( $seq<T> a, $int i ); // sequence obtained by removing element at position i from a |
| 285 | | <T> $seq<T> $seq_insert( $seq<T> a, $int i, T x ); // sequence obtained by inserting element x at position i in a |
| | 287 | <T> $seq<T> $seq_set( $seq<T> a, $int i, T x ); // seq obtained by replacing element `i` of `a` with `x` |
| | 288 | <T> $seq<T> $seq_subseq( $seq<T> a, $int start, $int stop ); // subsequence from `start` to `stop-1` |
| | 289 | <T> $seq<T> $seq_add( $seq<T> a, T x ); // sequence obtained by adding element `x` to the end of `a` |
| | 290 | <T> $seq<T> $seq_append( $seq<T> a1, $seq<T> a2 ); // sequence obtained by concatenating `a1` and `a2` |
| | 291 | <T> $seq<T> $seq_remove( $seq<T> a, $int i ); // sequence obtained by removing element at position `i` from `a` |
| | 292 | <T> $seq<T> $seq_insert( $seq<T> a, $int i, T x ); // sequence obtained by inserting element `x` at position `i` in `a` |
| | 293 | <T> void $seq_write( $int n, T * ptr, $seq<T> a ); // write the first `n` elements of `a` to `ptr`, `ptr+1`, ..., `ptr+n-1`. |
| | 294 | <T> $seq<T> $seq_read( $int n, T * ptr ); // form a sequence by reading `ptr`, `ptr+1`, ..., `ptr+n-1`. |