next up previous contents index
Next: Class `library' part 3 Up: 3rd example of object Previous: Class `library' part 1   Contents   Start

Class `library' part 2


\begin{lstlisting}[language=Scm]{}
    (define new-book
      (lambda(abook)
        ((abook 'change-owner) self)
        ((abook 'change-holder) self)
        (define books (cons abook books))
        abook))
;
    (define sell-book
      (lambda(author atitle reader)
        (define abook (search-book author atitle))
        (if (equal abook false)
            false
            ((lambda()
               (if (equal ((abook 'get-holder)) self)
                   ((lambda()
                      (define xreader 
                              (locate (lambda(x) 
                                        (equal reader x)) readers))
                      (if (equal xreader false)
                          (define readers (cons reader readers))
                          false)
                      ((abook 'change-owner) reader)
                      ((abook 'change-holder) reader)
                      abook))
                   false))))))
;
    (define lend-book
      (lambda(author atitle reader)
        (define abook (search-book author atitle))
        (if (equal abook false)
             false
             ((lambda()
                (if (equal ((abook 'get-holder)) self)
                    ((lambda()
                       (define xreader 
                               (locate (lambda(x) 
                                         (equal reader x)) readers))
                       (if (equal xreader false)
                           (define readers (cons reader readers))
                           false)
                       ((abook 'change-holder) reader)
                       abook))
                    false))))))
;
    (define take-back-book
      (lambda(abook reader)
        (define xreader (locate (lambda(x) (equal reader x)) readers))
        (if (equal xreader false)
            false
            ((lambda()
               (if (equal reader ((abook 'get-holder)))
                   ((lambda()
                      (define xbook 
                              (locate (lambda(x) (equal abook x)) 
                                      books))
                      (if (equal xbook false)
                          false
                          (if (equal ((abook 'get-owner)) self) 
                              ((lambda()
                                 ((abook 'change-holder) self)
                                 true))
                              false))))
                   false))))))
;



Georg P. Loczewski 2004-03-05


Impressum und Datenschutz