-
Notifications
You must be signed in to change notification settings - Fork 1
/
3_04.rkt
32 lines (27 loc) · 869 Bytes
/
3_04.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#lang racket
#| Solution for exercise 3_04. |#
(provide make-account)
(define (make-account balance password cops-proc)
(let ((wrong-attempt 0))
(define (withdrow amount)
(if (< balance amount)
"Not enough money"
(begin (set! balance (- balance amount))
balance)))
(define (deposit amount)
(set! balance (+ balance amount))
balance)
(define (dispath pass op)
(if (eq? pass password)
(begin
(set! wrong-attempt 0)
(cond ((eq? op 'withdrow) withdrow)
((eq? op 'deposit) deposit)
(else "Wrong operation")))
(begin
(if (< wrong-attempt 3)
(begin
(set! wrong-attempt (+ wrong-attempt 1))
(lambda (arg) "Wrong password"))
(lambda (arg) (cops-proc))))))
dispath))