On Mar 31, 12:45 pm, Konrad Hinsen <konrad.hin...@laposte.net> wrote:
> On Mar 31, 2009, at 16:32, Rich Hickey wrote:
>
> > Here are some problems/limitations of existing OO/GF systems that I
> > don't intend to repeat:
>
> ...
>
> I agree that these are not desirable features. I have had to work
> around some of them many times in the past. Traditional OO combines
> aspects that should better be handled separately.
>
> > Here are the areas I'm looking to improve:
>
> > - There's no easy way to talk about "the method you would get if you
> > were dispatch value X". Note that this is not the same as call-next-
> > method, which reintroduces global ordering requirements, but allows
> > for easy explicit reuse of already-defined methods.
>
> That would be VERY nice to have. More than once I ended up writing a
> private function that I then called from several methods in the same
> multimethod, to avoid code duplication.
>
I've added get-method (SVN 1338).
(derive ::Circle ::Shape)
(derive ::Rect ::Shape)
(defmulti area :Shape)
;note - you can name methods
(defmethod area ::Shape area-shape [x] nil)
(get-method area ::Rect)
#<user$area_shape__43 user$area_shape_...@674a93a6>
(defmethod area ::Rect area-rect [r]
(* (:wd r) (:ht r)))
(defmethod area ::Circle area-circ [c]
(* (. Math PI) (* (:radius c) (:radius c))))
(get-method area ::Rect)
#<user$area_rect__18 user$area_rect_...@4e42751f>
(get-method area ::Circ) ;not there
nil
(get-method area ::Circle)
#<user$area_circ__20 user$area_circ_...@74da0c91>
;if you don't think squares are rectangles, you can still reuse
implementation (silly example)
(defmethod area ::Square area-square [sqr]
((get-method area ::Rect) {:wd (:dim sqr) :ht (:dim sqr)}))
(area {:Shape ::Square :dim 20})
400
Note how you can name methods for diagnostic purposes. This doesn't
introduce names into the namespace, just puts a name on the fn object.
Rich
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---