Code from Section 10.6 of
Kenneth C. Louden, Programming Languages
Principles and Practice 2nd Edition
Copyright (C) Brooks-Cole/ITP, 2003

This file is in the stylized format of
the text, suitable for cutting and pasting
into an actual Smalltalk system.

Figure 10.16, page 449:

Class name: LinkableObject
Superclass: Object
Instance variables: link
Methods: next
           ^ link
         linkTo: anObject
           link _ anObject
Class Method:
    new: aLinkableObject
       ^ (self new) linkTo: aLinkableObject

Figure 10.17, page 450:

Class name: Queue
Superclass: Object
Instance variables: rear
Methods: empty
           ^ rear == nil
         front
           ^ rear next
         enqueue: aLinkableObject
           self empty
             ifTrue: [ rear <- aLinkableObject.
                       rear linkTo: rear ]
             ifFalse: [ aLinkableObject linkTo: rear next.
                         rear linkTo: aLinkableObject.
                         rear <- aLinkableObject ]
         dequeue
           | temp |
           temp <- self front.
           (rear == temp) 
              ifTrue: [ rear <- nil ]
              ifFalse: [ rear linkTo: (temp next) ]

Test code for Queue, page 451:

q <- Queue new.
x <- LinkableObject new.
y <- LinkableObject new.
q enqueue: x.
q enqueue: y.
y <- q front.
"now y == x"
q dequeue.
q dequeue.
"now q is empty"

Figure 10.18, page 451:

Class name: Complex
Superclass: Object
Instance variables: re im
Methods:
  realPart
    ^ re
  imagPart
    ^ im
  setReal: x
    re <- x
  setImag: y
    im <- y
  + y
    ^ (Complex new setReal: (re + (y realPart)))
                   setImag: (im + (y imagPart))

Test code for Complex, page 452:

x <- (Complex new setReal: 1.0) setImag: 1.0.
y <- (Complex new setReal: 1.0) setImag: -1.0.
z < - x + y.
