hw8 - (define (deposit amount pass-try) (if (eq? password...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
;; Exercise 3.3 (define (make-account balance password) (define (withdraw amount pass-try) (if (eq? password pass-try) (if (>= balance amount) (begin (set! balance (- balance amount)) balance) "Insufficient funds") "Incorrect password")) (define (deposit pass-try amount) (if (eq? password pass-try) ((set! balance (+ balance amount)) balance) "Incorrect password")) (define (dispatch m) (cond ((eq? m 'withdraw) withdraw) ((eq? m 'deposit) deposit) (else (error "Unknown request -- MAKE-ACCOUNT" m)))) dispatch) ;; Exercise 3.4 (define (make-account balance password) (let ((incor-pass 0)) (define (withdraw amount pass-try) (if (eq? password pass-try) (if (>= balance amount) (begin (set! balance (- balance amount)) (set! incor-pass 0) balance) (begin (set! incor-pass 0) "Insufficient funds")) (begin (set! incor-pass (+ incor-pass 1)) "Incorrect password")))
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: (define (deposit amount pass-try) (if (eq? password pass-try) (begin (set! balance (+ balance amount)) (set! incor-pass 0) balance) (begin (set! incor-pass (+ incor-pass 1)) "Incorrect password"))) (define (dispatch m) (cond ((eq? m 'withdraw) withdraw) ((eq? m 'deposit) deposit) (else (error "Unknown request -- MAKE-ACCOUNT" m)))) dispatch)) ;; Exercise 3.7 (define (make-joint acc pass-try new-pass) (lambda (try method) (if (eq? try new-pass) (acc pass-try method) (error "Incorrect password!")))) ;; Exercise 3.8 (define f (let ((j 1)) (lambda (x) (set! j (* j x)) j))) ( ;; Exercise 3.10 ; I drew it out for the practice. .. but I ; don't know how i'm supposed to turn it in now. ; ;; Exercise 3.11 ; I drew it out for the practice. .. but I ; don't know how i'm supposed to turn it in now. ;...
View Full Document

Page1 / 2

hw8 - (define (deposit amount pass-try) (if (eq? password...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online