[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Code for cond* - cond*-match, cond*-subpat and backtrack-aliases
|
From: |
Alan Mackenzie |
|
Subject: |
Re: Code for cond* - cond*-match, cond*-subpat and backtrack-aliases |
|
Date: |
Thu, 25 Jan 2024 14:01:47 +0000 |
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).
- Re: Code for cond*, (continued)
Re: Code for cond*, Richard Stallman, 2024/01/25
Re: Code for cond*, Alan Mackenzie, 2024/01/24
- Re: Code for cond*, Emanuel Berg, 2024/01/24
- Re: Code for cond*, Manuel Giraud, 2024/01/24
- Re: Code for cond* - cond*-match, cond*-subpat and backtrack-aliases,
Alan Mackenzie <=
- Re: Code for cond* - cond*-match, cond*-subpat and backtrack-aliases, Richard Stallman, 2024/01/28
- Re: Code for cond* - cond*-match, cond*-subpat and backtrack-aliases, JD Smith, 2024/01/29
- Re: Code for cond* - cond*-match, cond*-subpat and backtrack-aliases, Richard Stallman, 2024/01/31