### 14.4.1 Tables

A table is a map (associative container) used to store information associated to indices which are much more general than integers, such as strings or sequences. For example, use one to store a table of phone numbers indexed by names.

In Xcas, the indices in a table may be any kind of Xcas objects. Access is done by a binary search algorithm, where the sorting function first sorts by type and then uses an order for each type (e.g. < for numeric types, lexicographic order for strings, etc.)

The table command creates a table.

- table takes seq, a list or sequence of equalities of the form key=value.
- table(seq) returns a table. The elements of the table can be retrieved using index bracket notation. If T is the name of the table, then T[key] returns value.

Tables can also be created and the elements of a table can be changed by using the := assignment.

- If T is a symbolic variable, then T[key]:=value creates a table T with one element.
- If n is an integer, then the assignment T[n]:=obj will do the following:
  - If the variable T was assigned to a list or a sequence, then the nth element of T is modified.
  - If the variable T was not assigned, a table T is created with one entry (corresponding to the index n). Note that after the assignment T is not a list, despite the fact that n is an integer.

#### Example

T:=table(3=-10,"a"=10,"b"=20,"c"=30,"d"=40):;

T["b"]

20 |  |  |  |  |  |  |  |  |  |

T[3]

−10 |  |  |  |  |  |  |  |  |  |

T[3]:=-15:; T[3]

−15 |  |  |  |  |  |  |  |  |  |