woonie

make-secure-account1

Oct 2nd, 2011
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scheme 0.71 KB | None | 0 0
  1. (define (make-secure-account password balance)
  2.   (define tries 7)
  3.   (define bal 0)
  4.   (define password1 0)
  5.   (set! password1 password)
  6.   (set! bal balance)
  7.   (define (object pw withdraw)
  8.     (cond ((not (equal? password1 pw)) (begin (set! tries (- tries 1))
  9.                                               (if (<= tries -1)
  10.                                                   (call-the-cops)
  11.                                                   "Wrong password!")))
  12.           ((>= bal withdraw) (begin (set! bal (- bal withdraw))
  13.                                     (set! tries 7)
  14.                                     bal))
  15.           (else (begin (set! tries 7)
  16.                        "Insufficient funds!"))))
  17.   object)
  18.  
Advertisement
Add Comment
Please, Sign In to add comment