[Top][All Lists]

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

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

From: Eric Abrahamsen
Subject: Re: Generic functions: Specializers like `or' or `memq'?
Date: Thu, 04 Nov 2021 10:31:45 -0700
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)

Stefan Monnier via Users list for the GNU Emacs text editor
<> writes:

>>>> I haven't tried it myself, but it seems like you would have to use
>>>> cl-generic-generalizers (see cl-generic.el) to do so.
>>> Yes, it should be doable.  I find it a bit suspicious that this is not
>>> already available.
>> My understanding is that these more computationally-intensive
>> generalizers have the potential to seriously slow down method funcalls,
>> and so we're sort of gently discouraged from doing that.
> Not really, actually, no.
> The main problem is one of ordering between different methods when
> several methods are applicable.
> [ `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.  ]

Thank you for correcting my FUD!

>> Is anyone else's brain incapable of maintaining the distinction between
>> "specializer" and "generalizer"?
> A specializer is what you write in the `cl-defmethod`, it says this
> method is specialized for arguments of a particular type.
> It can be thought of as a type or a set of values.
> A generalizer is a sort of function that takes a value and returns the
> specializer to which it belongs (it "generalizes" from a value to a set
> that includes this value).  Every kind of specializer comes with
> a matching generalizer as part of its implementation.

Okay, this is helpful, but my brain is still resisting. I also read the
docstring for `cl-generic-generalizers' from time to time, and I think
if I can really understand what it's saying, I'll have a handle on it.

My earliest confusion began when I decided that if I could find the part
of the code that runs the `eql' specializer (or do we call it the `eql'
generalizer?) and then worked back from there, I would be able to make
sense of everything. But I couldn't even find the bit of code that looks
like (eql <val> <tag>)! And still can't.


> BTW, I took the term "generalizer" from the following article (from
> which I drew a fair bit of inspiration when designing `cl-generic.el`):
>     Generalizers: New metaobjects for generalized dispatch

Thanks! I'm reading this now.


reply via email to

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