libera/#commonlisp - IRC Chatlog
Search
0:39:24
nytpu
is it possible to define a method dispatching on an object that is a child of multiple classes; for example with made-up syntax: `(defmethod method ((obj (and parent1 parent2))) ...)`
0:40:39
nytpu
to avoid x-y, i'm abusing classes and multiple inheritance to define traits: https://en.wikipedia.org/wiki/Trait_(computer_programming) and i want to define a method that'd dispatch on any class that inherits from two of the traits
0:51:24
_death
there's no built-in way.. you can introduce an intermediate class and inherit from that, or perform the dispatch yourself, even introduce a new kind of specializer (see project called "specializable")
0:56:23
nytpu
i don't want to define an intermediatry class and dispatch off of that, because then a subclass would have to use that intermediary specifically instead of being able to inherit those two traits separately, maybe at different points in the hierarchy
0:56:33
nytpu
i'm thinking for the level of complexity it's currently at it'd be best to just use duck typing instead of proper method dispatch; maybe i'd look into a MOP solution if it got a lot more complex
1:08:41
_death
there are also some ambiguities.. for example what if there are two methods, (and p1 p2) and (and p1 p3) and the class is a subclass of (p1 p2 p3)
1:11:51
_death
you would have to decide how to resolve them in a way that easy to understand.. CLOS has a precedence rule, but it probably needs to be extended to handle these cases
7:33:51
mfiano
The code is pretty simple if this doesn't work for your needs. Just a couple MOP methods to define really.