what do y'all think about this for quick and dirty predicate dispatch? https://stackoverflow.com/questions/53329709/dispatching-function-calls-on-different-formats-of-maps/53354967#53354967
I'm not as conversant in macros, so it's probably pretty buggy
@john it seems because you're using a {}
to store the impls, when a value satisfies multiple predicates, which one gets dispatched is random, isn't it? How about (def poly-atom (atom (array-map)))
? That way we can implement prefer-method
?
This is first time I've seen predicate dispatch so I have no idea what I'm talking about.
@jaihindh.reddy I updated the example a bit, to read a bit clearer. Particular poly
s, like myinc
s or take-turn
s are stored as keys in the map. Their predicate implementations are conj
ed to a vector of vectors which contain pairs of predicates and functions, which apply to the params when the predicate returns true with the params.
prefer-method
enhancement would need to replace the filtering functionality that runs over those pairs
Oops. The comment cleared it up. Got it.