100 likes | 239 Views
Bank Account Environment Model Examples. Prof. Tony White April 2010. Example Bank Account: Code. (define new-withdraw (let (( balance 100)) (lambda (amount) (if (>= balance amount)
E N D
Bank AccountEnvironment Model Examples Prof. Tony White April 2010
Example Bank Account: Code (define new-withdraw (let (( balance 100)) (lambda (amount) (if (>= balance amount) (begin (set! balance (- balance amount)) balance) "Insufficient funds") ) )) (define a1 (new-withdraw 30)) (define a2 (new-withdraw 40))
Example: new-withdraw let’ Π=9
Example: new-withdraw let’ new-withdraw’ Π=4 Π=9
Example: new-withdraw let’ Π=10
Example Bank Account: Code (define(new-withdraw) (let (( balance 100)) (lambda (amount) (if (>= balance amount) (begin (set! balance (- balance amount)) balance) "Insufficient funds") ) )) (define a1 ((new-withdraw)30)) (define a2 ((new-withdraw)40)) Now define new-withdraw as a procedure; note the brackets!
Example: new-withdraw new-withdraw’ let’ Π=9
Example: new-withdraw new-withdraw’ let’ lambda’ Π=4 Π=9