File:  [Research Unix] / researchv10no / cmd / sml / doc / examples / awk / stringtab.sml
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Tue Apr 24 17:21:35 2018 UTC (8 years, 1 month ago) by root
Branches: belllabs, MAIN
CVS tags: researchv10, HEAD
researchv10 Norman

(* stringtab.sml *)

functor StringTable(type elem val default: elem) = 
struct

  type awkTable = elem ref Stringmap.stringmap

  fun new() = Stringmap.new(): awkTable

  fun set (t: awkTable) (s:string, x:elem) : unit =
      let val r = Stringmap.map t s in r := x end
      handle Stringmap.Stringmap => Stringmap.add t (s,ref x)

  fun get (t: awkTable) (s:string) : elem =
      !(Stringmap.map t s)
      handle Stringmap.Stringmap => default

  fun app (t: awkTable) (f: string * elem -> unit) =
      Stringmap.app (fn (s,ref e) => f(s,e)) t

end

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.