0

I am trying to code an rx-to-string form that contains an intermediate regexp.

This code works in Lisp Interaction Mode:

(let* ((a-plus '(one-or-more "a")))
  (rx-to-string '(sequence (eval a-plus))))

but fails in Emacs Lisp Mode with a (void-variable a-plus) error. Why? How do I fix that?

EDIT: I have found the cause: the lexical-binding: t directive in the Emacs Lisp buffer.

Eleno
  • 1,428
  • 11
  • 17
  • 1
    This seems to work fine for me in both modes. If you replace '(sequence (eval a-plus)) with `(sequence ,a-plus) does it work for you? – John Kitchin Oct 13 '19 at 12:15
  • @JohnKitchin I have found the cause: the `lexical-binding: t` directive in the Emacs Lisp Buffer. Anyway, your alternative works, thanks. – Eleno Oct 13 '19 at 13:58
  • If you have found the solution, please post it as an answer and then accept that answer as soon as the system allows you. Self-answers are totally fine (encouraged, in fact). – Dan Oct 14 '19 at 00:12
  • 1
    Similar to https://emacs.stackexchange.com/questions/30173/why-does-this-straightforward-use-of-a-closure-fail (not an exact dup, since the use of `rx-to-string` adds some wrinkles) – npostavs Oct 14 '19 at 03:08

1 Answers1

0

The problem is that rx-to-string does not work with lexical-binding: t, because of eval (see also: https://emacs.stackexchange.com/a/30174/2763).

However, the workaround proposed by @JohnKitchin works:

(let* ((a-plus '(one-or-more "a")))
  (rx-to-string `(sequence ,a-plus)))
Eleno
  • 1,428
  • 11
  • 17