emacs-devel
[Top][All Lists]
Advanced

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

Re: EXPVAL in pcase-defmacro docstrings


From: Stefan Monnier
Subject: Re: EXPVAL in pcase-defmacro docstrings
Date: Mon, 04 Jun 2018 10:43:29 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

> 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 via email to

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