Using the table type in Icon
An Icon table is a container where you can store and retrieve things using a key value. This is often used in situations where you want to look up something.
For example, suppose you want to translate the number of the day of the week (e.g., 3 for Tuesday) to a string giving the name of the day (e.g., "Tue"). You could do this with a list like so:
dayNames := ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];so that a reference to ``
dayNames'' would produce the string
But what if you want to do the opposite translation---from a
day name to a day number? For this you'd use
an Icon table. You can set up a table called ``
so that ``
dayNumbers["Tue"]'' will produce the value 3.
Another term for this kind of structure is associative array.
John Shipman, email@example.com
Last updated: 1996/04/24 00:03:51 UT