unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Alan Mackenzie <acm@muc.de>
To: Richard Stallman <rms@gnu.org>
Cc: emacs-devel@gnu.org
Subject: Re: Code for cond* - cond*-match, cond*-subpat and backtrack-aliases
Date: Thu, 25 Jan 2024 14:01:47 +0000	[thread overview]
Message-ID: <ZbJpy33YiqYPahyW@ACM> (raw)
In-Reply-To: <ZbEFGl4lj81inF-f@ACM>

Hello again, Richard.

On Wed, Jan 24, 2024 at 12:39:54 +0000, Alan Mackenzie wrote:
> On Wed, Jan 17, 2024 at 22:37:47 -0500, Richard Stallman wrote:
> > [[[ To any NSA and FBI agents reading my email: please consider    ]]]
> > [[[ whether defending the US Constitution against all enemies,     ]]]
> > [[[ foreign or domestic, requires you to follow Snowden's example. ]]]

> > Here is the first draft of cond*.  I have tested some cases
> > but I ask others to help in testing it more thoroughly.

> > I invite constructive comments, bug reports, patches,
> > and suggestions.

I've found some more things I'm not happy about in the code.

1/- There are typos in the doc string of cond*-subpat.
2/- There are three places where backtrack-aliases is used where I think
  it should be (cdr backtrack-aliases).
3/- In cond*-subpat, there are bindings for (gensym "ba") which seem
  unable to be referenced by anything.  I think I'm missing something
  here.  As I said yesterday, I'd be happier if gensyms could be
  avoided.  I don't know if this is possible or practicable.
4/- There are several place where "\\>" is appended to a regexp.  Would
  "\\_>" ("end of symbol"), which we've had in Emacs for 10 or 15 years
  now, perhaps be better?

I've included a patch for the first two of these things below.

There are other typos in the code, too, and I think it highly unlikely
that it is bug free, yet.  For cond* to be successful, it will need an
extensive test file.  Possibly we could copy the pcase test file (at
test/lisp/emacs-lisp/pcase-tests.el) and adapt it to cond*.

[ .... ]


--- stallman.20240119.el	2024-01-25 13:31:15.049200457 +0000
+++ stallman.20240125.el	2024-01-25 13:36:44.454224261 +0000
@@ -200,7 +200,7 @@
     ;; Run TRUE-EXPS if match succeeded.  Bind our bindings around it.
     (setq expression
           `(if ,expression
-               ,(if (not (and backtrack-aliases (null uncondit-clauses)))
+               ,(if (not (and (cdr backtrack-aliases) (null uncondit-clauses)))
                     ;; Bind these here if there are no UNCONDIT-CLAUSES.
                     `(let ,(mapcar 'cdr (cdr backtrack-aliases))
                        (let* ,(car raw-result)
@@ -219,7 +219,7 @@
                       (let* ,(car raw-result)
                         ,(cond*-convert uncondit-clauses)))))
     ;; If there are backtrack aliases, bind them around the UNCONDIT-CLAUSES.
-    (if (and backtrack-aliases uncondit-clauses)
+    (if (and (cdr backtrack-aliases) uncondit-clauses)
       (setq expression `(let ,(mapcar 'cdr (cdr backtrack-aliases))
                           ,expression)))
     ;; If we used a gensym, add code to bind it.
@@ -254,16 +254,16 @@
 ;;; ??? Probably should optimize the `nth' calls in handling `list'.
 
 (defun cond*-subpat (subpat cdr-safe bindings backtrack-aliases data)
-  "Generate code to match ibe subpattern within `match*'.
+  "Generate code to match the subpattern within `match*'.
 SUBPAT is the subpattern to handle.
 CDR-SAFE if true means don't verify there are no extra elts in a list.
 BINDINGS is the list of bindings made by
 the containing and previous subpatterns of this pattern.
 Each element of BINDINGS must have the frm (VAR VALUE).
-BACKTRACK-ALIASES is used to pass adta uward.  Initial call should
+BACKTRACK-ALIASES is used to pass data upward.  Initial call should
 pass (list).  The cdr of this collects backtracking aliases made for
 variables boung within (or...) patterns so that the caller
-dna bind them etc.
+can bind them etc.
 DATA is the expression for the data that this subpattern is
 supposed to match against.
 
@@ -290,7 +290,7 @@
              ;; for backtracking, just use that.
              (let ((this-alias (assq subpat (cdr backtrack-aliases))))
                (if this-alias (cdr this-alias)
-                 (if backtrack-aliases
+                 (if (cdr backtrack-aliases)
                      ;; Inside or subpattern but this symbol has no alias,
                      ;; make one for it.
                      (progn (setcdr backtrack-aliases (cons (cons subpat (gensym "ba"))

> > -- 
> > Dr Richard Stallman (https://stallman.org)
> > Chief GNUisance of the GNU Project (https://gnu.org)
> > Founder, Free Software Foundation (https://fsf.org)
> > Internet Hall-of-Famer (https://internethalloffame.org)

-- 
Alan Mackenzie (Nuremberg, Germany).



  parent reply	other threads:[~2024-01-25 14:01 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
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   ` Alan Mackenzie [this message]
2024-01-29  3:19     ` Code for cond* - cond*-match, cond*-subpat and backtrack-aliases 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

  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=ZbJpy33YiqYPahyW@ACM \
    --to=acm@muc.de \
    --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 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).