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.

  • 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 at 12:15
  • @JohnKitchin I have found the cause: the lexical-binding: t directive in the Emacs Lisp Buffer. Anyway, your alternative works, thanks. – Elena Oct 13 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 at 0:12
  • 1
    Similar to emacs.stackexchange.com/questions/30173/… (not an exact dup, since the use of rx-to-string adds some wrinkles) – npostavs Oct 14 at 3:08
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)))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.