When I implemented propaganda I was
in need of generic operators with predicate dispatch. It wasn’t
available in Clojure, and I had to spend a bit of time implementing it
and to come up with a set of acceptable tradeoffs.
I have extracted the generic operator implementation from the propaganda
library and it available separatly as the library
kaleidoscope. The library offers
two functions: generic-operator for creating a new generic operator,
and assign-operation for assigning an operation to an existing
operator. assign-operation is a destructive operation.
In this example we are creating our own version of the +-operator,
which works on both numbers and strings.
A more advanced example is the mixing of datatypes in basic operations.
The examples do not fully demonstrate the possibilities in the library
as we could have achieved something similar with multimethods. Unlike
multimethods, generic operators are not bound to a namespace, and they
support arbitrary predicate dispatch, not just type dispatch (meta
types or otherwise).
I would recomment studying the literature for more advanced usages of
predicate dispatch.