[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
- Re: Generic functions: Specializers like `or' or `memq'?, (continued)
- Re: Generic functions: Specializers like `or' or `memq'?, Philip Kaludercic, 2021/11/03
- Re: Generic functions: Specializers like `or' or `memq'?, Michael Heerdegen, 2021/11/03
- Re: Generic functions: Specializers like `or' or `memq'?, Eric Abrahamsen, 2021/11/03
- Re: Generic functions: Specializers like `or' or `memq'?, Michael Heerdegen, 2021/11/03
- Re: Generic functions: Specializers like `or' or `memq'?, Emanuel Berg, 2021/11/03
- Re: Generic functions: Specializers like `or' or `memq'?, Michael Heerdegen, 2021/11/03
- Re: Generic functions: Specializers like `or' or `memq'?, Stefan Monnier, 2021/11/03
- Re: Generic functions: Specializers like `or' or `memq'?, Stefan Monnier, 2021/11/03
- Re: Generic functions: Specializers like `or' or `memq'?, Emanuel Berg, 2021/11/04
- Re: Generic functions: Specializers like `or' or `memq'?, Michael Heerdegen, 2021/11/06
- Re: Generic functions: Specializers like `or' or `memq'?,
Stefan Monnier <=
- Re: Generic functions: Specializers like `or' or `memq'?, Michael Heerdegen, 2021/11/06
- Re: Generic functions: Specializers like `or' or `memq'?, Stefan Monnier, 2021/11/21
- Re: Generic functions: Specializers like `or' or `memq'?, Michael Heerdegen, 2021/11/23
- Re: Generic functions: Specializers like `or' or `memq'?, Eric Abrahamsen, 2021/11/04