Is it possible to obtain an (rx ...)
form, that is expanded at compile time for performance, but partially variable?
rx-to-string
may be slow
For instance I want an expression that behaves equivalent to
(rx-to-string `(: "PREFIX"
(or "hello" "world" ,@user-defined-words)
"SUFFIX))
Written this way, it works, but does an unnecessary amount of work at runtime (especially in more complex real-world examples). In some places, this can become a potential performance issue.
What I want to produce at compile time is essentially a partial compile-time expansion, such as
(concat "PREFIX\\(?:hello\\|world\\|"
(mapconcat #'regexp-quote user-defined-words "\\|")
"\\)SUFFIX")
eval
form does not work
I already know that the (rx ... (eval ...) ...)
form does not work:
;; INCORRECT RESULT; VARIABLE EXPANDED AT COMPILE TIME:
(rx "PREFIX"
(eval `(or "hello" "world" ,@user-defined-words)
"SUFFIX))
;; When loading from source and user-defined-words is initialized to nil:
=> "PREFIX\\(?:hello\\|world\\)SUFFIX"
;; When compiling:
=> Error: Symbol's value as variable is void: user-defined-words