Presentation is loading. Please wait.

Presentation is loading. Please wait.

Bank Account Environment Model Examples Prof. Tony White April 2010.

Similar presentations


Presentation on theme: "Bank Account Environment Model Examples Prof. Tony White April 2010."— Presentation transcript:

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


Download ppt "Bank Account Environment Model Examples Prof. Tony White April 2010."

Similar presentations


Ads by Google