-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3.7.rkt
More file actions
36 lines (32 loc) · 1013 Bytes
/
3.7.rkt
File metadata and controls
36 lines (32 loc) · 1013 Bytes
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
30
31
32
33
34
35
#lang scheme
; pre-defined
(define (make-account balance password)
(define (withdraw amount)
(if (>= balance amount)
(begin (set! balance (- balance amount))
balance)
"Insufficient funds"))
(define (deposit amount)
(set! balance (+ balance amount))
balance)
(define (dispatch pw m)
(cond ((not (eq? pw password)) (error "Incorrect password"))
((eq? m 'withdraw) withdraw)
((eq? m 'deposit) deposit)
(else (error "Unknown request: MAKE-ACCOUNT"
m))))
dispatch)
; required
(define (make-joint account password new-password)
(define (dispatch pw m)
(if (eq? pw new-password)
(account password m)
(error "Incorrect password")))
((account password 'deposit) 0)
dispatch)
; test
(define peter-acc (make-account 100 '123456))
((peter-acc '123456 'withdraw) 40)
(define paul-acc (make-joint peter-acc '123456 'paul))
((paul-acc 'paul 'withdraw) 20)
((peter-acc '123456 'deposit) 0)