]>
The Table constructor provides a general structure for associative storage. This type provides hash tables in which data objects can be saved according to keys of any type. For a given table, specific types must be chosen for the keys and entries.
In this example the keys to the table are polynomials with integer coefficients. The entries in the table are strings.
To save an entry in the table, the seteltseteltTable operation is used. This can be called directly, giving the table a key and an entry.
Alternatively, you can use assignment syntax.
Entries are retrieved from the table by calling the elteltTable operation.
This operation is called when a table is ``applied'' to a key using this or the following syntax.
Parentheses are used only for grouping. They are needed if the key is an infixed expression.
Note that the elteltTable operation is used only when the key is known to be in the table---otherwise an error is generated.
You can get a list of all the keys to a table using the keyskeysTable operation.
If you wish to test whether a key is in a table, the searchsearchTable operation is used. This operation returns either an entry or "failed".
The return type is a union so the success of the search can be tested using case.
The removeremoveTable operation is used to delete values from a table.
If an entry exists under the key, then it is returned. Otherwise removeremoveTable returns "failed".
The number of key-entry pairs can be found using the # #Table operation.
Just as keyskeysTable returns a list of keys to the table, a list of all the entries can be obtained using the membersmembersTable operation.
A number of useful operations take functions and map them on to the table to compute the result. Here we count the entries which have ``Hard'' as a prefix.
Other table types are provided to support various needs. \indent