all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Adam Porter <adam@alphapapa.net>
Cc: emacs-devel@gnu.org
Subject: Re: [PATCH] pcase.el: Add cl-type and type patterns
Date: Fri, 16 Jul 2021 18:41:47 -0400	[thread overview]
Message-ID: <jwvmtqlew2h.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <87a6mt38fa.fsf@alphapapa.net> (Adam Porter's message of "Sat, 10 Jul 2021 21:12:41 -0500")

> +@item (cl-type @var{type})
> +Matches if @var{expval} is of type @var{type}, which is a symbol or
> +list as accepted by @ref{cl-typep,,,cl,Common Lisp Extensions}.

Rather than mention "symbol or list", I'd only refer to `cl-typep`,
maybe something like:

    Matches if @var{expval} is of type @var{type}, which is type descriptor
    as accepted by @ref{cl-typep,,,cl,Common Lisp Extensions}.

The rest of the first patch looks good to me.

> +(pcase-defmacro type (type)
> +  "Pcase pattern that matches objects of TYPE.
> +This checks using a predicate named `TYPEp' or `TYPE-p', as
> +appropriate.  For matching structs defined with `cl-defstruct',
> +the `cl-type' pattern matcher should be used instead."
> +  (let* ((type (symbol-name type))
> +         (pred (or (intern-soft (concat type "p"))
> +                   (intern-soft (concat type "-p"))
> +                   (error "Unknown type: %s" type))))
> +    `(pred ,pred)))

I'm not convinced this second patch is worth the trouble:

    (type FOO)

is not significantly shorter or simpler than

    (pred FOO-p)

but it is inherently brittle because `intern-soft` may
return non-nil even though there's no predicate by that name, and it may
also let you use a "type" which really isn't one such as
`cl--struct-name` or `looking-at`.

`cl-type` provides that functionality in a cleaner and more
reliable way (it still also relies to some extent on similar heuristic
as your code, admittedly, but I've been working to get rid of it).


        Stefan




  parent reply	other threads:[~2021-07-16 22:41 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-09 18:19 [PATCH] pcase.el: Add type pattern Adam Porter
2020-03-09 18:38 ` Eli Zaretskii
2020-03-09 19:20   ` Adam Porter
2020-03-09 19:35     ` Adam Porter
2020-03-09 18:38 ` Adam Porter
2020-03-09 18:45 ` Eric Abrahamsen
2020-03-10 15:48   ` Adam Porter
2020-03-10 17:40     ` Eric Abrahamsen
2020-03-09 18:53 ` Stefan Monnier
2020-03-09 19:31   ` Adam Porter
2020-03-09 21:00     ` Stefan Monnier
2020-03-09 21:54       ` Adam Porter
2020-03-09 22:22         ` Michael Heerdegen
2020-03-09 22:46           ` Adam Porter
2020-03-10 14:54             ` Michael Heerdegen
2020-03-10 15:01             ` Michael Heerdegen
2020-03-10 15:46               ` Adam Porter
2020-03-10 16:24                 ` Michael Heerdegen
2020-03-10 17:03                   ` Adam Porter
2020-03-10 17:43                     ` Michael Heerdegen
2020-03-10 18:04                       ` Adam Porter
2020-03-10 18:17                         ` Adam Porter
2020-03-10 19:07                           ` Michael Heerdegen
2020-03-10 19:19                             ` Adam Porter
2020-03-10 19:10                           ` Eric Abrahamsen
2020-03-10 19:21                             ` Adam Porter
2020-03-11  2:08                         ` Michael Heerdegen
2020-03-16 12:59                 ` Stefan Monnier
2021-07-11  1:33                   ` [PATCH] pcase.el: Add cl-type and type patterns Adam Porter
2021-07-11  2:12                     ` Adam Porter
2021-07-11  6:11                       ` Eli Zaretskii
2021-07-16  9:32                         ` Adam Porter
2021-07-17 11:58                           ` Eli Zaretskii
2021-07-16 22:41                       ` Stefan Monnier [this message]
2021-07-17 16:07                         ` Adam Porter
2021-07-30 21:24                           ` Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwvmtqlew2h.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=adam@alphapapa.net \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.