# A Data and Code Fragments

This appendix contains code fragments left out in the text's chapters.

## A.1 Application Development

<Body for DB.oz>=
  `define
  Data = {Dictionary.new}
  Ctr = {New class $
  prop locking
  attr i:0
  meth init(I <= 0)
  lock i := I end
  end
  meth get($)
  lock @i end
  end
  meth inc($)
  lock I=@i+1 in i := I I end
  end
  end init()}
  proc {Add X}
  I={Ctr inc($)}
  in
  {Dictionary.put Data I X}
  end
  fun {Get ID}
  {Dictionary.get Data ID}
  end
  fun {GetAll}
  {Map {Dictionary.keys Data}
  fun {$ K}
  {AdjoinAt {Dictionary.get Data K} key K}
  end}
  end
  proc {Remove ID}
  {Dictionary.remove Data ID}
  end`

<Implementation of Book>=
  `T ={New Tk.toplevel tkInit}
  F1={New Tk.frame tkInit(parent:T relief:sunken bd:2)}
  V ={New Tk.variable tkInit(Fs.1.key)}
  {Tk.batch
  grid(b({Map ['' 'From' 'To' 'Price']
  fun {$ A}
  {New Tk.label tkInit(parent:F1 text:A
  relief:raised bd:1)}
  end})
  padx:1 pady:1 sticky:ew) |
  {Map Fs
  fun {$ F}
  grid({New Tk.radiobutton tkInit(parent:F1 var:V
  value:F.key)}
  b({Map ['from' to price]
  fun {$ A}
  {New Tk.label tkInit(parent:F1 text:F.A)}
  end}))
  end}}
  F2={New Tk.frame tkInit(parent:T)}
  [FN LN EM] =
  {Map ['First name' 'Last name' 'E-Mail']
  fun {$ S}
  E={New Tk.entry tkInit(parent:F2 width:20 bg:wheat)}
  in
  {Tk.send grid({New Tk.label
  tkInit(parent:F2 text:S#':' anchor:w)}
  E
  sticky:ew)}
  fun {$}
  {E tkReturnAtom(get $)}
  end
  end}
  B={New Tk.button
  tkInit(parent:T text:'Okay'
  action: proc {$}
  Get=form(first: {FN}
  last: {LN}
  email: {EM}
  key: {V tkReturnInt($)})
  {T tkClose}
  end)}
  in
  {Tk.send pack(F1 F2 B padx:1#m pady:2#m)}`

<Sample flights>=
  `[f('from':'Paris' to:'Stockholm' price:234)
  f('from':'Saarbrücken' to:'Paris' price:345)
  f('from':'New York' to:'Saarbrücken' price:567)
  f('from':'New York' to:'Bruxelles' price:363)
  f('from':'Paris' to:'Saarbrücken' price:834)
  f('from':'Stockholm' to:'Bruxelles' price:333)
  f('from':'London' to:'Saarbrücken' price:523)
  f('from':'Saarbrücken' to:'London' price:457)
  f('from':'Bruxelles' to:'New York' price:324)
  f('from':'Boston' to:'Stockholm' price:765)
  f('from':'Stockholm' to:'New York' price:344)
  f('from':'Sydney' to:'Saarbrücken' price:3452)
  f('from':'Sydney' to:'Stockholm' price:2568)]`