1implement Dictionary; 2 3# 4# This is intended to be a simple dictionary of string tuples 5# It is not intended for large data sets or efficient deletion of keys 6# 7 8include "dict.m"; 9 10Dict.add( d: self ref Dict, e: (string, string) ) 11{ 12 if (d.entries == nil) 13 d.entries = e::nil; 14 else 15 d.entries = e::d.entries; 16} 17 18Dict.delete( d: self ref Dict, k: string ) 19{ 20 key : string; 21 newlist : list of (string, string); 22 temp := d.entries; 23 24 while (temp != nil) { 25 (key,nil) = hd temp; 26 if (key != k) 27 newlist = (hd temp)::newlist; 28 temp = tl temp; 29 } 30 d.entries = newlist; 31} 32 33Dict.lookup( d: self ref Dict, k: string ) :string 34{ 35 key, value :string; 36 temp := d.entries; 37 while (temp != nil) { 38 (key,value) = hd temp; 39 if (key == k) 40 return value; 41 temp = tl temp; 42 } 43 return nil; 44} 45 46Dict.keys( d: self ref Dict ) :list of string 47{ 48 key: string; 49 keylist : list of string; 50 temp := d.entries; 51 while (temp != nil) { 52 (key, nil) = hd temp; 53 keylist = key::keylist; 54 temp = tl temp; 55 } 56 return keylist; 57} 58