Hello,guys!
   I'm reading  《Programming Clojure》.  I've seen closure. But I
haven't seen how simulate  Class.
   Lisp can simulate Class by closure and nest Function.
Example:
    (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 50))
((acc 'deposit) 40)
90
((acc 'withdraw) 60)
30

    But how  Clojure  do it?
 
by    Edward  Shen    from  Shanhai,China

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Clojure" 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/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to