9.3 Dictionaries

The module Dictionary contains procedures operating on dictionaries. If a dictionary contains an item under some key LI, we say LI is a valid key. Whenever a dictionary access is indexed with an invalid key, a type error is raised.

IsDictionary

{Dictionary.is +X ?B}

tests whether X is a dictionary.

NewDictionary

{Dictionary.new ?Dictionary}

returns a new empty dictionary.

put

{Dictionary.put +Dictionary +LI X}

sets the item in Dictionary under key LI to X.

get

{Dictionary.get +Dictionary +LI X}

returns the item X of Dictionary under key LI.

condGet

{Dictionary.condGet +Dictionary +LI X Y}

returns the item Y of Dictionary under key LI, if LI is a valid key of Dictionary. Otherwise, returns X.

keys

{Dictionary.keys +Dictionary ?LIs}

returns a list of all currently valid keys of Dictionary.

entries

{Dictionary.entries +Dictionary ?Ts}

returns the list of current entries of Dictionary. An entry is a pair LI#X, where LI is a valid key of Dictionary and X the corresponding item.

items

{Dictionary.items +Dictionary ?Xs}

returns the list of all items currently in Dictionary.

isEmpty

{Dictionary.isEmpty +Dictionary ?B}

tests whether Dictionary currently contains an entry.

remove

{Dictionary.remove +Dictionary +LI}

removes the item under key LI from Dictionary if LI is a valid key. Otherwise, does nothing.

removeAll

{Dictionary.removeAll +Dictionary}

removes all entries currently in Dictionary.

member

{Dictionary.member +Dictionary +LI ?B}

tests whether LI is a valid key of Dictionary.

clone

{Dictionary.clone +Dictionary1 ?Dictionary2}

returns a new dictionary Dictionary2 containing the currently valid keys and corresponding items of Dictionary1.

toRecord

{Dictionary.toRecord +L +Dictionary ?R}

returns a record R with label L whose features and their fields correspond to the keys and their entries of Dictionary.


Denys Duchier, Leif Kornstaedt and Christian Schulte
Version 1.0.1 (19990218)