emacs-devel
[Top][All Lists]
Advanced

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

Re: Replace trivial pcase occurrences in the Emacs sources


From: Michael Heerdegen
Subject: Re: Replace trivial pcase occurrences in the Emacs sources
Date: Wed, 31 Oct 2018 20:50:58 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

Eli Zaretskii <address@hidden> writes:

> > I wouldn't call a `let' or `app' pattern that introduces a new binding
> > destructuring per se.  OTOH, I would call a pattern using ` that tests
> > e.g. the car of the matched object with e.g. `pred' destructuring even
> > if that car is not bound to a variable.
>
> Can you give an example?  I don't think I follow.

(pcase '(1 2 3)
  ((let a 3) a))
==> 3

Is the used pattern destructuring?  It binds a variable.

Or

(pcase '(1 2 3)
  ((app (lambda (thing) 27) x) x))
==> 27

As in the above example, the pattern ignores the given object.  OTOH,
when you use `app' with a function like `car' (the ` pcase macro is
defined like this), it can be used for destructuring.  The feature to
bind variables is totally orthogonal to destructuring.  The two are
often used together, however, but that shouldn't let us confuse these
two different things.

> > With other words: I would say a pattern where subpatterns are matched
> > against parts of a compound object is desctructuring.
>
> But note that your generalization is inconsistent with your example:
> there's no "pattern matching" in the example, there's only a "matched
> object", which is a matching of an entirely different kind.

I think it is.  I mean a pattern like `(,a ,b) is destructuring,
independently from the object being matched, because when used for
matching it (tries to) extract parts of a compound object and tests
these with subpatterns (a, b in this case).  The pattern fails to match
objects that are not compound or have the wrong structure.  But trying
to use the pattern for matching tries to extract and analyse the parts
of any object.  That's why I would call the pattern destructuring.

To give an exact accurate definition is nearly impossible, however.  For
example, is

  (or 'foo `(,a ,b))

desctructuring?

Is

 (pred some-fun)

destructuring if SOME-FUN may look at the parts of its argument?  How
would you define that?

I don't think "destructuring" is such a good term to use in the docs,
apart from giving a hint what ` is about.


Michael.



reply via email to

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