On 21 Jan 2011, at 17:28, Peter Morris wrote:
> 1) Polymorphism appears to be handled by the ability to supply different
> implementations of a keyword dependent on parameters.
> This means your oo methods are broken up out of your class definitions and
> sprinkled around your keyword definitions.
I've flicked ahead a bit to chapter 3 of SICP and they describe message passing
in Scheme as implemented like this:
(define (make-account balance)
(define (withdraw amount)
(if (>= balance amount)
(begin
(set! balance (- balance amount))
balance)
"Insufficient funds!"))
(define (deposit amount)
(set! balance (+ balance amount))
balance)
(define (dispatch m)
(cond ((eq? m 'withdraw) withdraw)
((eq? m 'deposit) deposit)
(else
(error "Unknown request -- MAKE-ACCOUNT")
m)))
dispatch)
(define acc (make-account 100))
((acc 'withdraw) 40) ;=> 60
";" is the Scheme comment character BTW :)
To the best of my understanding, an "object' is a function with mutable state.
I think it's a bit like a static variable in a C function, except bound to the
instance of the function.
I'd like to know if Clojure uses a similar convention for OO or if it does
something different.
I'm looking forward to chapter 3 of SICP as comparing the Scheme and Ruby
approaches to OO should be interesting.
Ash
--
http://www.patchspace.co.uk/
http://www.linkedin.com/in/ashleymoran
--
You received this message because you are subscribed to the Google Groups
"NWRUG" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/nwrug-members?hl=en.