2009/3/19 Edward Shen <shend...@hotmail.com> > > 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 > > In Clojure, they are considered a bad idea. You can read the rationale in this essay:
http://clojure.org/state --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---