## 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 ill-typed key, a type error is raised. For a missing but well-typed key, a system exception 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``` `DefVal``` `X``}`

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

`exchange`

  > `{Dictionary.exchange` `+Dictionary``` `+LI``` `OldVal``` `NewVal``}`

  returns the current value of `Dictionary` under key `LI` as item `OldVal` and updates the value of `Dictionary` under key `LI` to be `NewVal`.

`condExchange`

  > `{Dictionary.condExchange` `+Dictionary``` `+LI``` `DefVal``
  > ` `OldVal``` `NewVal``}`

  If `LI` is a valid key of `Dictionary` then returns the current value of `Dictionary` under key `LI` as item `OldVal` otherwise, returns `DefVal` as item `OldVal`. Sets the value of `Dictionary` under key `LI` to be `NewVal`.

`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`.

`weak`

  another way to access module `WeakDictionary` (see Section 9.4).