next up previous contents
Next: Testing class `account' Up: Object Oriented Programming in Previous: First example of object   Contents

Source code for constructor `make-account'


(define make-account 
  (lambda(balance)
    (define get-balance
      (lambda()
        balance))
;
    (define deposit 
      (lambda(amount)
        (define balance (add balance amount))
        balance))
;
    (define withdraw 
      (lambda(amount)
        (if (gep balance amount)
            ((lambda()
               (define balance (sub balance amount))
               balance))
            false)))
;
    (define print-account
      (lambda()
        (ndisp! balance)))
;
    (define self 
      (lambda(msg)
        (if (equaln msg one) 
            get-balance
            (if (equaln msg two) 
                 deposit
                 (if (equaln msg three) 
                     withdraw
                     (if (equaln msg four) 
                         print-account
                         false)))))) 
    self))
;



Georg P. Loczewski 2004-03-05


Impressum und Datenschutz