bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#27659: 26.0.50; Add string-matched-text: string-match + match-string


From: Philipp Stephani
Subject: bug#27659: 26.0.50; Add string-matched-text: string-match + match-string
Date: Sun, 23 Jul 2017 20:45:34 +0000



Michael Heerdegen <address@hidden> schrieb am Sa., 22. Juli 2017 um 03:46 Uhr:
Hi Philipp,

nice idea!  I have some questions:


+(pcase-defmacro rx (&rest regexps)
+  "Build a `pcase' pattern matching `rx' regexps.
+The REGEXPS are interpreted as by `rx'.

Should we tell what the semantics of multiple REGEXPS is?  I guess they
are implicitly wrapped inside rx-`and' (but FWIW, the doc of `rx' also
fails to tell that).


yes, probably something should be added to the docstring of `rx'.
 


+Within the case code, the match data is bound as usual, but you

This makes it sound like match data is bound pcase-branch-locally.
This isn't the case, right?

Yes, I've reworded it to sound less like a variable binding.
 


+In addition to the usual `rx' constructs, REGEXPS can contain the
+following constructs:
+
+  (let VAR FORM...)  creates a new explicitly numbered submatch
+                     that matches FORM and binds the match to
+                     VAR.

This made me wonder what FORM should be.  I think it means any rx
symbolic _expression_, so the name FORM seems misleading.

I think the words `form' and `sexp' are used mostly interchangeably nowadays, and the docstring of `rx' speaks of "forms" several times.
 


+(ert-deftest pcase-tests-rx ()
+  (should (equal (pcase "a 1 2 3 1 b"
+                   ((rx (let u (+ digit)) space
+                        (let v (+ digit)) space
+                        (let v (+ digit)) space
+                        (backref-var u))
+                    (list u v)))
+                 '("1" "3"))))
+

I don't understand the example (or test).  Is v first bound to 2, and
after that rebound to 3?  This seems at least surprising, since let
behaves differently in pcase, e.g.

(pcase 'foo
  ((and (let x 1) (let x 2)) x))
==> nil

Hmm, in general I see the risk of confusing this `let' with `pcase' let.
It seems to be something very different.  Maybe you could just pick a
different name, `bind' maybe?



I'd rather stick with the short and common `let'. That there's a name clash is unfortunate, but there are lots of similar cases (e.g. pcase `let' vs. Lisp `let', rx `and' and `or').

reply via email to

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