unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Ihor Radchenko <yantar92@posteo.net>
To: rms@gnu.org
Cc: thievol@posteo.net, emacs-devel@gnu.org
Subject: Re: pcase bindings in patterns with complicated logic
Date: Sun, 21 Jan 2024 14:06:42 +0000	[thread overview]
Message-ID: <87edeag4r1.fsf@localhost> (raw)
In-Reply-To: <E1rROAY-00024E-Di@fencepost.gnu.org>

Richard Stallman <rms@gnu.org> writes:

> I am not confident I understand app pattern, but if it does what I now
> think, the equivalent of (app (mapcar #'cdr) `(,_ ,_ ,c))) would be
> this:
>
>   (match* `(,_ ,_ ,c) (mapcar 'car  '((foo . 1) (bar . 2) (baz . 3))))

Yes.

> What cond* cannot do is apply `and' to two different match* clauses
> which test different objects.  I could add that capability.

You understand correctly - `and' for different match* clauses is what I
pointed to.

> ... I could also add `app', if that is worth adding. Its absence is
> not a fundamental design issue, just that it dud not seem necessary.

`app' is actually a more limited version of what you can do when
combining multiple match* clauses - match* clauses can test completely
unrelated objects, while pcase's `app' can only test a transformed first
pcase argument.

So, I do not think that `app' is required if combining match* clauses is
allowed.

> That example wan't a solution to a real problem, so I am not convinced
> this is a real gap in cond*.  If I see this sort of situation in a
> real problem, that will convince me I should do something about this.

I looked up the use of pcase's `app' pattern across the packages I use
and inside Emacs source code. There are only several trivial uses,
actually:

(defun engrave-faces-preset-style (faces)
  "Return the preset style for FACES, should it exist.
Unconditionally returns nil when FACES is default."
  (pcase faces
    ('default nil)
    ((pred symbolp)
     (assoc faces engrave-faces-preset-styles))
    ((and (pred listp) (app length 1)) ; <--- here
     (assoc (car faces) engrave-faces-preset-styles))))

(defun octave--indent-new-comment-line (orig &rest args)
  (pcase (syntax-ppss)
    ((app ppss-string-terminator ?\')
     (user-error "Cannot split a single-quoted string"))
    ((app ppss-string-terminator ?\")
     (insert octave-string-continuation-marker))
    ((pred (not ppss-comment-depth))
     (delete-horizontal-space)
     (unless (octave-smie--in-parens-p)
       (insert " " octave-continuation-string))))
  (apply orig args)
  (indent-according-to-mode))

and a couple of internal pcase uses that are there to extend pcase -
`rx--pcase-expand', `seq--make-pcase-bindings',
`map--make-pcase-bindings', and (pcase-defmacro eieio...)

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>



  reply	other threads:[~2024-01-21 14:06 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-13  3:54 pcase bindings in patterns with complicated logic Richard Stallman
2024-01-13 19:58 ` Ihor Radchenko
2024-01-14  6:58   ` Thierry Volpiatto
2024-01-14  7:27     ` Thierry Volpiatto
2024-01-14 15:42     ` Ihor Radchenko
2024-01-14 15:58       ` Thierry Volpiatto
2024-01-14 16:21         ` Ihor Radchenko
2024-01-14 17:54           ` Thierry Volpiatto
2024-01-16  3:32             ` Richard Stallman
2024-01-16 13:18               ` Ihor Radchenko
2024-01-18  3:37                 ` Richard Stallman
2024-01-18 13:13                   ` Ihor Radchenko
2024-01-20  3:39                     ` Richard Stallman
2024-01-20 12:48                       ` Ihor Radchenko
2024-01-21  3:06                         ` Richard Stallman
2024-01-21 14:06                           ` Ihor Radchenko [this message]
2024-01-23 13:40                             ` Richard Stallman
2024-01-23 15:08                             ` Stefan Monnier via Emacs development discussions.
2024-01-23 19:59                               ` Stefan Monnier via Emacs development discussions.
2024-01-15  3:13   ` Richard Stallman
2024-01-14  7:03 ` Thierry Volpiatto

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

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87edeag4r1.fsf@localhost \
    --to=yantar92@posteo.net \
    --cc=emacs-devel@gnu.org \
    --cc=rms@gnu.org \
    --cc=thievol@posteo.net \
    /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 public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).