Utilizing environments to make classes and objects.
Utilizing environments to make classes and objects.
Date Created:Tuesday October 14th, 2008 10:07 AM
Date Modified:Tuesday October 14th, 2008 10:40 AM
(define (make-account init-amount)
(let (
(balance init-amount)
(init init-amount)
(transactions '())
)
(define (withdraw amount)
(begin
(set! balance (- balance amount))
(set! transactions (cons (cons (- amount) balance) transactions))
balance))
(define (deposit amount)
(begin
(set! balance (+ balance amount))
(set! transactions (cons (cons amount balance) transactions))
balance))
(define (dispatch msg)
(cond
((eq? msg 'balance) balance)
((eq? msg 'init-amount) init)
((eq? msg 'transactions) transactions)
((eq? msg 'withdraw) withdraw)
((eq? msg 'deposit) deposit)))
dispatch))
Downloads:
Download: env.scm 754 B
Please login or Click Here to register for downloads
Environments by Dan Lynch
is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License
Based on a work at www.3daet.com
Permissions beyond the scope of this license may be available at http://www.3daet.com
