brandonbloom / dispatch-map

Persistent map with Clojure's multimethod dispatch semantics
29 stars 3 forks source link

Polymorphic isa? #1

Closed brandonbloom closed 11 years ago

brandonbloom commented 11 years ago

From IRC:

<tsdh>   Is there a way to use multimethods dispatching on type if the type of an objects isn't manifested in its class?  Basically, I need something like (defmulti foo class), but with my own class and isa? functions.
[00:56:21] <tsdh>    I mean, I could use `make-hierarchy' and `derive' to convert the custom type hierarchy of the objects to a hierarchy suitable for isa?, but it doesn't feel right to duplicate that information...
brandonbloom commented 11 years ago

Done. See https://github.com/brandonbloom/dispatch-map/blob/93631c125a4cce5f2a46e36fd77638bece7eff8b/test/dispatch_map/core_test.clj#L76-86

As discussed in IRC, your isa implementation for IHierarchy must be memoizable. You should story your hierarchy in a reference, like an Atom or Var.

2 to follow shortly.