Download presentation
Presentation is loading. Please wait.
Published byChristine Chambers Modified over 8 years ago
1
Bank Account Environment Model Examples Prof. Tony White April 2010
2
Example Bank Account: Code 1.(define new-withdraw 2. (let (( balance 100)) 3. (lambda (amount) 4. (if (>= balance amount) 5. (begin 6. (set! balance (- balance amount)) 7. balance) 8. "Insufficient funds") ) )) 9.(define a1 (new-withdraw 30)) 10.(define a2 (new-withdraw 40))
3
Example: new-withdraw new-withdrawλ(3) let’ balance100 Π=9
4
Example: new-withdraw new-withdrawλ(3) let’ balance100 Π=9 amount30 Π=4 new-withdraw’
5
Example: new-withdraw new-withdrawλ(3) a170 let’ balance70 Π=10
6
Example Bank Account: Code 1.(define (new-withdraw) 2. (let (( balance 100)) 3. (lambda (amount) 4. (if (>= balance amount) 5. (begin 6. (set! balance (- balance amount)) 7. balance) 8. "Insufficient funds") ) )) 9.(define a1 ((new-withdraw) 30)) 10.(define a2 ((new-withdraw) 40)) Now define new-withdraw as a procedure; note the brackets!
7
Example: new-withdraw new-withdrawλ( 1) Π=9
8
Example: new-withdraw new-withdrawλ( 1) let’ balance100 Π=9 new-withdraw’
9
Example: new-withdraw new-withdrawλ( 1) let’ balance100 Π=9 new-withdraw’ amount30 lambda’ Π=4
10
Example: new-withdraw new-withdrawλ( 1) a170 Π=10
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.