learning-sicp

My embarrassing half assed SICP run.
git clone https://kaka.farm/~git/learning-sicp
Log | Files | Refs

exercise-3.scm (800B)


      1 (define-library (sicp solutions chapter-3 exercise-3)
      2   (import (scheme base))
      3   (export make-account)
      4 
      5   (begin
      6     (define (make-account balance super-secret-symbol)
      7       (define (withdraw amount)
      8         (if (>= balance amount)
      9             (begin
     10               (set! balance
     11                     (- balance
     12                        amount))
     13               balance)
     14             "Insufficient funds"))
     15 
     16       (define (deposit amount)
     17         (set! balance (+ balance
     18                          amount))
     19         balance)
     20 
     21       (lambda (whisper m)
     22         (if (eq? whisper super-secret-symbol)
     23             (cond
     24              ((eq? m 'withdraw) withdraw)
     25              ((eq? m 'deposit) deposit)
     26              (else (error "Uknown request: MAKE-ACCOUNT" m)))
     27             (lambda x "Incorrect password"))))))