Subject: bug#50136: 28.0.50; A problem with rx-let expansion

From: Mattias Engdegård <[email-masked]>
Date: Fri, 20 Aug 2021 17:23:58 +0200

20 aug. 2021 kl. 15.59 skrev Michael Heerdegen <[email-masked]>:

> (rx-let ((scatter (string)
>                  (regex (mapconcat #'string (string-to-list string) ".*"))))
>  (rx (scatter "abc"))) => useless error message

Yes, that's an unfortunate consequence of the current substitution mechanism (validating Stefan's premonitions to some extent).
However the syndrome is entirely avoidable and does not make the facility less powerful.

> Personally I would be more happy with a thing called `rx-macrolet' than
> with an extended `rx-let' to support this additional macro-like kind of
> syntax.

Noted (in the honest sense)!

> AFAIU, the current approach doesn't allow to extend this with an
> optional CHARS argument to specify with chars are allowed "in between"
> (instead of "any").  The "&optional" keyword makes it barf.

That's right. What would be the preferred semantics? For example, what value would you expect an absent optional parameter to take? `nil` isn't very useful inside rx forms, so it would only make sense inside embedded Lisp expressions.

> And I can't actually "look" at the arguments to provide a conditional
> replacement.  All I can do is to use `regex' to eval a constant
> expression I specify (at run-time).  This seems a quite limiting
> approach.  Something more macro-like would be appropriate IMO.

Actually it's the rx `eval` form that you are looking for if you want arbitrary compile-time computation. `regexp` and `literal` are explicitly made for run-time expressions.