all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Richard Stallman <rms@gnu.org>
Cc: emacs-devel@gnu.org
Subject: Re: Code for cond*
Date: Sat, 03 Feb 2024 01:09:26 -0500	[thread overview]
Message-ID: <jwvcyte3zje.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <E1rW6l7-00021X-Qi@fencepost.gnu.org> (Richard Stallman's message of "Fri, 02 Feb 2024 22:32:01 -0500")

>   > As I said: in Pcase I moved some of the "built-in" patterns, such as the
>   > backquote, out of the core (using `pcase-defmacro` to define them
>   > instead), as a way to make sure that `pcase-defmacro` is indeed
>   > flexible enough.
>
> You're suggesting that I do this by exploring, but that's the hard
> way.  Harder than actually necessary -- since the real intention of a
> macro facility is for defining other kinds of pattern _given the ones
> that will be provided_.  It's comparable to looking for axioms for
> mathematics (or even just plane geometry) -- interesting, but there
> was no need for the rest of mathematics to wait for this to work.

What have it tried to implement using the macro facility you designed
for your patterns?  Have you tried to implement, say the `map` pattern
we have in `map.el` or the `cl-struct` pattern?

> I wouldn't want to use it without making it include the improvements
> I've designed into cond*, and I expect that `pcase-defmacro' is not
> capable of implementing constrained variables or `cdr-ignore'.

Your expectation is incorrect.

> That would require changing the pcase pattern code.

I don't think so.  The primitive patterns were carefully chosen so it
shouldn't be needed.  E.g.:

    (pcase-defmacro constrain (symbol exp) `(and ,symbol (guard ,exp)))

Admittedly, for `cdr-ignore` it would take more than a one-liner,
because it affects the interpretation of all the patterns within it
(which makes its meaning somewhat unclear: should `(constrain x (null
(cdr x)))` be ignored if it appears within a `cdr-ignore`?).
It might be the case that a clean implementation would require some
adjustments to the implementation of other patterns.  The details
would matter.

> If you tell me the name of the function in pcase which is the entry
> point for processing a pattern, with that starting point I might be
> able to understand some of that code.  I doubt it will change the
> situation, but I will take a look.

As I said, you don't need to know the internals, as shown in the
PoC below.  Which adds a `pcase*` construct to your `cond*`. It's used
like your `match*` but with Pcase patterns.
[ The patch also fixes some misuses of ";;; " which are reserved for
  sectioning and mess up `outline-minor-mode`.  ]

Also, BTW, I don't understand this behavior of your code:

    (macroexpand '(cond* ((match* `(c ,@d ,e) DAT) BRANCH1)))
==>
    (let ((d2624 DAT))
     (if (and (consp d2624) (eq 'c (car d2624)) (append (cdr d2624) (list e)))
         (let* ((d (cdr d2624))) BRANCH1)
       nil))


        Stefan


diff --git a/lisp/cond*.el b/lisp/cond*.el
index e40543ce393..d25bd858324 100644
--- a/lisp/cond*.el
+++ b/lisp/cond*.el
@@ -218,8 +218,8 @@ cond*-convert-condition
                    ;; Then always go on to run the UNCONDIT-CLAUSES.
                    (if true-exps
                        `(let ((,init-gensym ,first-value))
-;;; ??? Should we make the bindings a second time for the UNCONDIT-CLAUSES.
-;;; as the doc string says, for uniformity with match*?
+;;;  ??? Should we make the bindings a second time for the UNCONDIT-CLAUSES.
+;;;  as the doc string says, for uniformity with match*?
                           (let* ,mod-bindings
                             (when ,init-gensym
                               . ,true-exps)
@@ -235,6 +235,18 @@ cond*-convert-condition
                     (let* ,mod-bindings
                       (when ,init-gensym
                         . ,true-exps)))))))
+          ((eq pat-type 'pcase*)
+           (if true-exps
+               (progn
+                 (cl-assert (null uncondit-clauses))
+                 (cl-assert (or (null iffalse) rest))
+                 `(pcase ,(nth 2 condition)
+                    (,(nth 1 condition) ,@true-exps)
+                    (_ ,iffalse)))
+             (cl-assert (null iffalse))
+             (cl-assert (null rest))
+             `(pcase-let ((,(nth 1 condition) ,(nth 2 condition)))
+                (cond* . ,uncondit-clauses))))
           ((eq pat-type 'match*)
            (cond*-match condition true-exps uncondit-clauses iffalse))
           (t
@@ -340,8 +352,8 @@ cond*-bind-pattern-syms
 
 (defvar cond*-debug-pattern nil)
 
-;;; ??? Structure type patterns not implemented yet.
-;;; ??? Probably should optimize the `nth' calls in handling `list'.
+;;;  ??? Structure type patterns not implemented yet.
+;;;  ??? Probably should optimize the `nth' calls in handling `list'.
 
 (defun cond*-subpat (subpat cdr-ignore bindings inside-or backtrack-aliases data)
   "Generate code to match ibe subpattern within `match*'.




  reply	other threads:[~2024-02-03  6:09 UTC|newest]

Thread overview: 134+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-18  3:37 Code for cond* Richard Stallman
2024-01-18  4:59 ` Emanuel Berg
2024-01-20  3:39   ` Richard Stallman
2024-01-24 12:37     ` Po Lu
2024-01-24 19:12     ` Alan Mackenzie
2024-01-27  3:35       ` Richard Stallman
2024-01-18 15:44 ` Andrea Corallo
2024-01-19 10:42   ` João Távora
2024-01-21  3:04     ` Richard Stallman
2024-01-21 20:05       ` Adam Porter
2024-01-22  5:32         ` tomas
2024-01-23 13:39         ` Richard Stallman
2024-01-24  6:02           ` Po Lu
2024-01-24  9:48       ` Stefan Kangas
2024-01-24 10:09         ` Emanuel Berg
2024-01-24 11:30         ` João Távora
2024-01-24 12:08           ` João Távora
2024-01-24 12:09         ` Po Lu
2024-01-24 12:22           ` Ihor Radchenko
2024-01-24 12:33             ` Po Lu
2024-01-24 13:34               ` Ihor Radchenko
2024-01-24 13:52                 ` João Távora
2024-01-24 14:31                   ` Po Lu
2024-01-27  3:35                   ` Richard Stallman
2024-01-27  3:35                   ` Richard Stallman
2024-01-24 14:07                 ` Po Lu
2024-01-24 14:20                   ` Ihor Radchenko
2024-01-24 14:34                     ` Po Lu
2024-01-24 14:44                       ` Ihor Radchenko
2024-01-24 14:47                         ` João Távora
2024-01-24 15:28                         ` Emanuel Berg
2024-01-24 16:30                           ` Ihor Radchenko
2024-01-24 16:34                             ` Emanuel Berg
2024-01-25  9:06                           ` Po Lu
2024-01-25  9:55                             ` Alfred M. Szmidt
2024-01-25 10:38                               ` Eli Zaretskii
2024-01-25 11:29                               ` Po Lu
2024-01-25 12:04                                 ` Emanuel Berg
2024-01-25 13:32                                   ` Po Lu
2024-01-25 14:08                                     ` Emanuel Berg
2024-01-25 13:19                                 ` Alfred M. Szmidt
2024-01-25 13:43                                   ` Emanuel Berg
2024-01-25 14:31                                     ` Eli Zaretskii
2024-01-25 15:02                                       ` Emanuel Berg
2024-01-25 15:29                                         ` Eli Zaretskii
2024-01-25 15:33                                           ` Alfred M. Szmidt
2024-01-25 15:50                                             ` Eli Zaretskii
2024-01-25 16:01                                               ` Alfred M. Szmidt
2024-01-25 16:13                                                 ` Eli Zaretskii
2024-01-25 15:40                                           ` Emanuel Berg
2024-01-25 10:30                             ` Eli Zaretskii
2024-01-25 11:27                               ` Emanuel Berg
2024-01-24 12:15         ` Alan Mackenzie
2024-01-24 12:28           ` Emanuel Berg
2024-01-25  9:10           ` Po Lu
2024-01-25 11:56             ` Emanuel Berg
2024-01-25 13:21               ` Po Lu
2024-01-25 13:56                 ` Emanuel Berg
2024-01-25 23:32           ` Stefan Kangas
2024-01-20  3:39   ` Richard Stallman
2024-01-23 18:10 ` Stefan Monnier via Emacs development discussions.
2024-01-24  4:49   ` JD Smith
2024-01-24  9:45     ` Stefan Kangas
2024-01-24 15:29       ` JD Smith
2024-01-24 15:55         ` Stefan Monnier
2024-01-24 16:02           ` Stefan Monnier
2024-01-24 16:20           ` JD Smith
2024-01-24 17:08             ` Stefan Monnier
2024-01-24 16:35           ` [External] : " Drew Adams
2024-01-24 16:30     ` Drew Adams
2024-02-01  8:56       ` Madhu
2024-02-01 22:46         ` Emanuel Berg
2024-01-25  3:16     ` Madhu
2024-01-25 13:57       ` Stefan Monnier
2024-01-25 15:17         ` JD Smith
2024-01-25 15:37           ` JD Smith
2024-01-25 15:44             ` Alfred M. Szmidt
2024-01-25 16:00               ` JD Smith
2024-01-25 16:05               ` Stefan Monnier
2024-01-25 16:12                 ` Alfred M. Szmidt
2024-01-25 16:20                   ` Stefan Monnier
2024-01-25 16:33                   ` JD Smith
2024-01-29  3:19             ` Richard Stallman
2024-01-26  4:30   ` Richard Stallman
2024-01-28  3:06     ` Stefan Monnier via Emacs development discussions.
2024-01-30  3:59       ` Richard Stallman
2024-01-30 13:02         ` Stefan Monnier
2024-02-23  3:04           ` Richard Stallman
2024-01-26  4:30   ` Richard Stallman
2024-01-28  4:16     ` Stefan Monnier via Emacs development discussions.
2024-01-31  3:32       ` Richard Stallman
2024-01-31 13:20         ` Stefan Monnier
2024-02-03  3:32           ` Richard Stallman
2024-02-03  6:09             ` Stefan Monnier [this message]
2024-02-03  6:48               ` Emanuel Berg
2024-02-04  4:46               ` Richard Stallman
2024-02-04 14:04                 ` Stefan Monnier
2024-02-04  4:46               ` Richard Stallman
2024-02-04 13:58                 ` Stefan Monnier
2024-02-13  0:48                 ` Stefan Monnier
2024-02-13  2:27                   ` Stefan Monnier
2024-02-14 11:16                   ` Richard Stallman
2024-02-14 12:45                     ` Stefan Monnier
2024-02-22  3:05                       ` Richard Stallman
2024-02-22  4:08                         ` Stefan Monnier
2024-02-25  3:14                           ` Richard Stallman
2024-02-25 15:03                             ` Stefan Monnier
2024-02-29  3:50                               ` Richard Stallman
2024-02-29 18:07                                 ` Stefan Monnier
2024-02-29  3:50                               ` Richard Stallman
2024-02-13  0:41         ` Stefan Monnier
2024-02-23  3:04           ` Richard Stallman
2024-02-23 13:39             ` Stefan Monnier
2024-02-25  3:16               ` Richard Stallman
2024-02-25 14:57                 ` Alfred M. Szmidt
2024-02-25 15:38                   ` Stefan Monnier
2024-02-25 16:42                     ` Alfred M. Szmidt
2024-02-25 17:13                       ` Stefan Monnier
2024-02-25 17:22                     ` Alan Mackenzie
2024-02-25 17:46                       ` Alfred M. Szmidt
2024-02-25 18:13                         ` Stefan Monnier
2024-02-25 17:10                 ` Stefan Monnier
2024-02-27  3:11                   ` Richard Stallman
2024-01-24 12:39 ` Alan Mackenzie
2024-01-24 14:43   ` Emanuel Berg
2024-01-24 16:25   ` Manuel Giraud via Emacs development discussions.
2024-01-25 14:01   ` Code for cond* - cond*-match, cond*-subpat and backtrack-aliases Alan Mackenzie
2024-01-29  3:19     ` Richard Stallman
2024-01-29  8:54       ` Andreas Schwab
2024-01-29  3:19     ` Richard Stallman
2024-01-29 12:16       ` JD Smith
2024-02-01  3:51         ` Richard Stallman
2024-02-01 14:54           ` JD Smith
2024-02-04  4:42             ` Richard Stallman

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

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

  git send-email \
    --in-reply-to=jwvcyte3zje.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=emacs-devel@gnu.org \
    --cc=rms@gnu.org \
    /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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.