next up previous contents index
Next: Class `book' Up: 3rd example of object Previous: Class `author'   Contents   Start

Class `reader'


(define make-reader
  (lambda(aname)
    (define name aname)
    (define books nil)
    (define super (make-person aname))
;
    (define get-name
      (lambda()
        name))
;
    (define purchase-book
      (lambda(nm atitle library)
        (define nbook ((library 'sell-book) nm atitle self))
        (if (equal nbook false)
            false
            ((lambda()
              (define books (cons nbook books))
              nbook)))))
;
    (define borrow-book
      (lambda(nm atitle library)
        (define nbook ((library 'lend-book) nm atitle self))
        (if (equal nbook false)
            false
            ((lambda()
               (define books (cons nbook books))
               nbook)))))
;
    (define return-book
      (lambda(abook library)
        (if ((library 'take-back-book) abook self)
            ((lambda()
               (define books (remove abook books))
               true))
            false)))
;
    (define show-books
      (lambda()
        (for-each (lambda(x) ((x 'display))) books)))
;
    (define who-are-you
      (lambda()
        (print (super 'get-name))))
;
    (define self
      (lambda(msg)
        (if (equal msg 'purchase-book)
            purchase-book
            (if (equal msg 'borrow-book)
                borrow-book
                (if (equal msg 'return-book)
                    return-book
                    (if (equal msg 'show-books)
                        show-books
                        (if (equal msg 'who-are-you)
                            who-are-you
                            (super msg))))))))
     self))



Georg P. Loczewski 2004-03-05


Impressum und Datenschutz