Advertisement
Guest User

Untitled

a guest
Jun 6th, 2018
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Racket 0.58 KB | None | 0 0
  1. #lang racket
  2.  
  3. ;; cw. 1
  4.  
  5. (define (make-account balance password)
  6.   (define (withdraw amount)
  7.     (if (>= balance amount)
  8.         (begin (set! balance (- balance amount))
  9.                balance)
  10.         "Insufficient funds"))
  11.   (define (deposit amount)
  12.     (set! balance (+ balance amount))
  13.     balance)
  14.   (define (dispatch p m)
  15.     (if (eq? password p)
  16.         (cond ((eq? m 'withdraw) withdraw)
  17.               ((eq? m 'deposit) deposit)
  18.               (else (error "Unknown request -- MAKE-ACCOUNT"
  19.                            m)))
  20.         (error "Wrong password" p)))
  21.   dispatch)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement