all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: emacs-devel@gnu.org
Subject: Re: EXPVAL in pcase-defmacro docstrings
Date: Mon, 04 Jun 2018 10:43:29 -0400	[thread overview]
Message-ID: <jwvin6ymxpx.fsf-monnier+gmane.emacs.devel@gnu.org> (raw)
In-Reply-To: 87y3fzx49l.fsf@gnuvola.org

> Yes.  That is awkward, when reading the source code.  Thanks for
> pointing it out; i was focusing on the aggregated docstring for
> that change.  For docstrings where it makes sense to use EXPVAL
> (maybe not this one), how about we add a small comment pointing
> to the EXPVAL convention?  That way, we retain consistency in
> the presentation (for ‘C-h f pcase RET’), and give a clue to
> people who read source code.

As mentioned, I think "target" is the standard terminology, so we could
use that.  Of course, there might be cases where EXPVAL would work
better, but I don't think we need to encourage people to use EXPVAL nor
to decide how best to use it when it makes sense because it will likely
depend on the specifics.

>     ;; FIXME: We'd like to use a negative pattern (not consp),
>     ;; but pcase doesn't support it.  Using `atom' works but
>     ;; generates sub-optimal code.
>     `(or `(t . ,,vpat) (and (pred atom) ,vpat))))
>
> Does that mean we'd want a hypothetical ‘(pred (not consp))’ if
> such a construct were supported by ‘pcase’?

The idea was to use

     `(or `(t . ,,vpat) (and (not (pred consp)) ,vpat))))

Strictly speaking I'm very happy with the appearance of the current
code, the comment is only about the resulting macroexpansion because
pcase doesn't understand that (atom X) and (consp X) are
mutually exclusive.  But you're right that maybe a halfway solution
would be

     `(or `(t . ,,vpat) (and (pred (not consp)) ,vpat))))

which might be much easier to implement (in the sense that it might be
reasonably easy to add code to the handling of `pred` so it treats
negation efficiently).

> Another question i have concerns ‘(t . ...)’.  My understanding

This is used for leaves whose *value* is itself a `cons`.
E.g. compare

    (radix-tree-insert nil "ab" '42)
and
    (radix-tree-insert nil "ab" '(42))

So indeed the `t` is used because it's not a string so it shouldn't
match any normal code's `car`.


        Stefan




      reply	other threads:[~2018-06-04 14:43 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-30 12:28 EXPVAL in pcase-defmacro docstrings Stefan Monnier
2018-05-31 14:56 ` Thien-Thi Nguyen
2018-06-04 14:43   ` Stefan Monnier [this message]

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=jwvin6ymxpx.fsf-monnier+gmane.emacs.devel@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --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.