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 21:41:01 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

Eli Zaretskii <address@hidden> writes:

> > (pcase '(1 2 3)
> >   ((let a 3) a))
> > ==> 3
>
> Thanks, but I meant an example of what's described after the "OTOH".

Oh, sorry.  How about this:

(defun second-elt-is-positive-p (l)
    (pcase l
      (`(,_ ,(pred (< 0)) . ,_) t)))

(second-elt-is-positive-p (list 1 2 3))
==> t

(second-elt-is-positive-p (list 1 -2 3))
==> nil

Is the pattern `(,_ ,(pred (< 0)) . ,_) destructuring or does it
additionally have to bind at least one variable to be called like that?

Such patterns are used in real life - some bind variables, but others
are only used as tests to see if the structure fulfils certain
requirements.  I guess there is no sharp dividing line.


Michael.



reply via email to

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