[Top][All Lists]

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

Re: Replace trivial pcase occurrences in the Emacs sources

From: Eli Zaretskii
Subject: Re: Replace trivial pcase occurrences in the Emacs sources
Date: Sat, 03 Nov 2018 18:25:37 +0200

> From: Michael Heerdegen <address@hidden>
> Cc: address@hidden,  address@hidden
> Date: Sat, 03 Nov 2018 16:45:08 +0100
> control.texi line 521 "is equals": typo.

Thanks, fixed.

> | The pcase patterns that are useful for destructuring bindings are
> | generally those described in @ref{Backquote Patterns}, since they
> | express a specification of the structure of objects that will match.
> I don't like that sentence for two reasons:
> (1) ` is the pcase pattern for destructuring.  The "Backquote Patterns"
> or "Backquote style Patterns" are not really "pcase patterns" since they
> are part of the implicit semantics ``' defines.  They are _not_ pcase
> patterns.  Your sentence confuses the both.

Sorry, you lost me here.  How can these not be pcase patterns, when
they are used with 'pcase', and "pcase patterns" are _defined_ as
those used with 'pcase'?

> (2) We already have a lot other patterns for destructuring (eieio, seq,
> map, cl-struct), and we probably will get even more in the future.

OK, but why is that a reason not to use what I wrote?  Note that it
talks about "destructuring binding", not just about destructuring.
Also please note that I made some changes in the description of
seq-let to say that is an alternative facility for destructuring

The text you quoted doesn't say that those pcase patterns are the
_only_ method of destructuring.  If that is the root cause of your
disliking, we could make this even more clear.

> | @defmac pcase-let bindings address@hidden
> | Perform desctructuring binding of variables according to
> | @var{bindings}, and then evaluate @var{body}.
> and lots of similar:
> `pcase-let', `pcase-dolist' and the like are very often used only for
> destructuring, but they are not limited to destructuring.  Like in
> (defun test (arg)
>   (pcase-let (((or (and (pred stringp) s)
>                    (and (pred numberp) (app number-to-string s)))
>                arg))
>     s))
> (test "Hallo") => "Hallo"
> (test 1)       => "1"

OK, but why would I need pcase-let in this example?  Isn't the above
the same as

  (defun test (arg)
    (let ((s (cond ((stringp arg) arg)
                   ((numberp arg) (number-to-string arg)))))

(which is both simpler and shorter)?

> Also the docstrings give the impression that these are limited to
> destructuring, which is not true.

Can you tell where did you get that impression?  The doc strings talk
about destructuring bindings, when BINDINGS have the form specified,
and I believe that is true.

reply via email to

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