help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Generic functions: Specializers like `or' or `memq'?


From: Stefan Monnier
Subject: Re: Generic functions: Specializers like `or' or `memq'?
Date: Sat, 06 Nov 2021 19:36:14 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

>> [ `cl-generic.el` solves this problem by forcing the generalizer to
>>   come with a priority (a number), which makes the ordering "trivial"
>>   for `cl-generic.el` but it can be hard to choose the right priority
>>   to use when defining a new specializer/generalizer.  ]
>
> I don't see this.  How would an `or' or `memql' specializer be different
> from implementing the method several times for each alternative using
> the same body?

You need to specify the priority of things like

    (or (eql 4) integer)
and
    (or (eql 4) (eql 5))
and
    (or (eql 4) (eql "hello"))

The first wants to have lower priority than `integer`, the second should
have higher priority than `integer`, as for the third ... well ...

It's easier to move the code to a separate function and use individual
`cl-defmethod`s for each case, all of them implemented by calling that
separate function.


        Stefan




reply via email to

[Prev in Thread] Current Thread [Next in Thread]