[Top][All Lists]

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

Re: [PATCH] pcase.el: Add type pattern

From: Adam Porter
Subject: Re: [PATCH] pcase.el: Add type pattern
Date: Mon, 09 Mar 2020 16:54:18 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux)

Stefan Monnier <address@hidden> writes:

>>> `cl-typep` does it but I think it's a mistake.
>>> We should not rely on such heuristics when we can "do it right",
>>> e.g. with a property along the lines of `cl-deftype-satisfies`.
>> Understood, but I'm not sure exactly what you mean, as far as what I
>> should do in that regard.  I'm not very familiar with cl-lib's
>> internals.  :)
> The property `cl-deftype-satisfies` is very simple:
>    (get <TYPE> 'cl-deftype-satisfies)
> gives you the predicate you need to call.

Thanks, I didn't know about that property.

> So we could use this property or choose a new property name
> (without the `cl-` prefix) which works the same way.  Then we need to
> add the corresponding list of
>     (put '<TYPE> '<PROP> '<PRED>)
> somewhere (probably in `subr.el`, tho if we keep the
> `cl-deftype-satisfies` name, then it would also fit in
> `cl-preload.el`).

Thanks, now I understand.

> But at the same time, I can't think of a good reason why we should use
> a different notion of type than CL's, so I guess it does make sense to
> use `cl-typep` (makes the overall system simpler).  To avoid the
> circularity, we can simply move the (pcase-defmacro type ...) outside of
> `pcase.el` so it can easily depend on both `pcase` and `cl-lib`.
> Another option is to do something like
>     (pcase-defmacro type (ty)
>       (require 'cl-lib)
>       `(pred (pcase--flip cl-typep ',ty)))
> so `cl-lib` is only required lazily (when we actually expand a `(type
> TYPE)` pattern), so the bootstrapping problem shouldn't bite us as long
> as neither pcase.el nor cl*.el themselves use such a pattern.

Sounds good to me.  I found that cl-macs.el defines the pcase pattern
for cl-struct, so it seemed like a natural place to put a pattern that
uses cl-typep.  Please see the new patch attached.  I added a
co-authored-by pseudo-header; I hope that's appropriate.

>> Seems like a good idea to me, although the scope of those changes seem
>> much larger than this patch,
> Indeed.  But it's not enormous either (it's only an addition to what we
> have, so there's no tricky business with backward compatibility and stuff).
>> and I'm not sure I'm the right person for that job.
> Based on the fact that it hasn't been done yet, I think we can assume
> that noone is "the right person for that job", but you might still be
> the closest there is.  I'd be happy to help.

If you'd still like me to work on that or the other ideas, please let me
know, and I might be able to find time for that.


Attachment: 0001-lisp-emacs-lisp-cl-macs.el-Add-type-pattern.patch
Description: Add pcase type pattern to cl-macs.el, etc.

reply via email to

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