Testing an Icon table for the presence of a key |
|
If you try to retrieve an item from a table using a particular key value, and nothing has ever been stored under that value, the result depends on how you created the table (see `Creating an Icon table').
table(x)'',
you will get the value x.
table()'' with no arguments to create
the table, you will get a null value. You can use the
``/'' and ``\'' operators to test for this
value (see
`How does the null value work in Icon?').
For example, if you have created the ``dayNumbers''
array (see
`Storing items in an Icon table'),
this code would stop the program if there is no entry for the
day with name ``today'':
if / dayNumbers[today] then
stop ( "Argh! There's no such day as ",
today, "!" );