--- /dev/null
+#lang racket
+
+(define (make-monitored f)
+ (let ((num-calls 0))
+ (lambda (x)
+ (cond
+ ((eq? x 'how-many-calls?) num-calls)
+ (else
+ (begin
+ (set! num-calls (+ num-calls 1))
+ (f x)))))))
+
+#|
+> (define (square x) (* x x))
+> (square 4)
+16
+> (define mf (make-monitored square))
+> (mf 'how-many-calls?)
+0
+> (mf 10)
+100
+> (mf 'how-many-calls?)
+1
+> (mf 100)
+10000
+> (mf 'how-many-calls?)
+2
+>
+|#
\ No newline at end of file
--- /dev/null
+#lang racket
+
+(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 given-password m)
+ (if (eq? given-password password)
+ (cond ((eq? m 'withdraw) (lambda (amt) (withdraw amt)))
+ ((eq? m 'deposit) (lambda (amt) (deposit amt)))
+ (else (error "Unknown request -- MAKE-ACCOUNT"
+ m)))
+ (lambda (temp) "Incorrect password")))
+ dispatch)
\ No newline at end of file
--- /dev/null
+#lang racket
+
+(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)
+ (let ((bad-password-count 0))
+ (define (dispatch given-password m)
+ (if (eq? given-password password)
+ (cond ((eq? m 'withdraw) (lambda (amt) (withdraw amt)))
+ ((eq? m 'deposit) (lambda (amt) (deposit amt)))
+ (else (error "Unknown request -- MAKE-ACCOUNT"
+ m)))
+ (lambda (temp)
+ (begin
+ (set! bad-password-count (+ bad-password-count 1))
+ (if (>= bad-password-count 7)
+ "Something is wrong. Calling 911..."
+ "Incorrect password")))))
+ dispatch))
+
+#|
+
+> (define acc (make-account 100 'secret-password))
+> ((acc 'secret-password 'withdraw) 40)
+60
+> ((acc 'some-other-password 'deposit) 50)
+"Incorrect password"
+> ((acc 'some-other-password 'deposit) 50)
+"Incorrect password"
+> ((acc 'some-other-password 'deposit) 50)
+"Incorrect password"
+> ((acc 'some-other-password 'deposit) 50)
+"Incorrect password"
+> ((acc 'some-other-password 'deposit) 50)
+"Incorrect password"
+> ((acc 'some-other-password 'deposit) 50)
+"Incorrect password"
+> ((acc 'some-other-password 'deposit) 50)
+"Something is wrong. Calling 911..."
+>
+
+|#
\ No newline at end of file