(define (serialized-exchange account1 account2)
(let ((serializer (account1 'serializer))
(serializer (account2 'serializer))
(id1 (account1 'id))
(id2 (account2 'id)))
(if (< id1 id2)
((serializer2 (serializer1 exchange))
account1
account2)
((serializer1 (serializer2 exchange))
account1
account2))))
(define (make-account-and-serializer balance id)
(define (withdraw amount)
(if (>= balance amount)
(begin (set! balance (- balance amount))
balance)
"Insufficient funds"))
(define (deposit amount)
(set! balance (+ balance amount))
balance)
(let ((balance-serializer (make-serializer)))
(define (dispatch m)
(cond ((eq? m 'withdraw) widthdraw)
((eq? m 'deposit) deposit)
((eq? m 'balance) balance-serializer)
((eq? m 'serializer) balance-serializer)
((eq? m 'id) id)
(else (error "Unknow request -- MAKE_ACCOUNT"
m))))
dispatch))