On Jan 30, 1:09 pm, Jan Rychter <j...@rychter.com> wrote: > From what I read, the reasoning is that Clojure provides extremely > general multimethods where you have to define a dispatch function. On > the object side, there is metadata and you can do with it whatever you > want. But this seems to leave a gaping hole saying "fill me with an > object system". Is the goal for everyone to roll their own?
I think the goal is to provide object-like capabilities without needing actual objects. The emerging pattern is to use maps, with a :tag key identifying the type. Types are usually namespace- qualified keywords. You can create any kind of inheritance hierarchy with "derive". (defn make-window [id] {:tag ::window, :id id}) (defn make-color-window [id color] (assoc (make-window id) :tag ::color-window :color color)) (derive ::color-window ::window) (defmulti describe-window :tag) (defmethod describe-window ::window [w] (println "Window with ID" (:id w))) (defmethod describe-window ::color-window [w] (println (:color w) "Window with ID" (:id w))) (let [w (make-color-window 24 "blue")] (describe-window w)) ;; => prints "blue window with ID 24" -Stuart Sierra --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---