News flash: I'm going to Australia in February, so this Web site may be switched off at any time.


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[3]'' would produce the string "Tue".

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 ``dayNumbers'' so that ``dayNumbers["Tue"]'' will produce the value 3. Another term for this kind of structure is associative array.


Next: Creating an Icon table
See also: Using the Icon programming language
Previous: Sorting an Icon list

John W. Shipman, john@nmt.edu