7.5.1 Library Style

Dictionaries are supported directely by the Oz base library. They are implemented by hash tables that can be extended dynamically. The type of dictionary keys is

   type key = (atom + int)

Given this type, we can now define the type of a dictionary object:

unit(toRecord : -> record
     isEmpty  : -> bool
     entries  : -> list(key#value)
     items    : -> list(value)
     put      : key x value -> 
     get      : key -> value
     condGet  : key x value -> value
     member   : key -> bool
     toKeys   : -> list(key)
     remove   : key -> 
     removeAll: -> 
     collect  : key x value -> 
     ...)

A dictionary is created using NewDictionary. You can add new features using the := operator.

<Create Dictionary from Library>=
declare D={NewDictionary}
D.foo   := baz
D.hello := world
D.42    := fourtytwo

Now the dictionary contains the 3 features foo, hello and 42. You can look up the value associated with a feature using the dot notation and modify their association using := operator. The statement {CondSelect D Feature Default} performs a lookup of Feature in D much like the dot operation, but, if the Feature does not exist, it returns a Default instead. It is possible to check whether a feature exists using HasFeature:

<Test Dictionary from Library>=
{Inspect D.hello}
D.hello := universe(D)
{Inspect {CondSelect D foo fooNotFound}}
{Inspect {CondSelect D baz bazNotFound}}
{Inspect {HasFeature D foo}}
{Inspect {HasFeature D baz}}

The procedure CondSelect and HasFeature also work on records and arrays. You can find what features, items (i. e. values) , and entries (feature/item pairs) are in D using respectively:

{Dictionary.keys    D}  ==>  [hello 42 foo]
{Dictionary.items   D}  ==>  [universe(D) fourtytwo baz]
{Dictionary.entries D}  ==>  [hello#universe(D) 42#fourtytwo foo#baz]

A feature can be deleted using Dictionary.remove:

{Dictionary.remove D foo}


Denys Duchier, Claire Gardent and Joachim Niehren
Version 1.3.99 (20050412)