Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why don't reader macro extensions propagate to runtime (read)?

Why does the following not work?

;;;; foo.lisp
(in-package :cl-user)

(eval-when (:compile-toplevel :load-toplevel :execute)
  (require :cl-interpol))

(cl-interpol:enable-interpol-syntax)

(defun read-and-eval (s)
  (eval (read-from-string s)))

(cl-interpol:disable-interpol-syntax)

then:

LISP> (load (compile-file "foo.lisp"))
=> T

LISP> (read-and-eval
        "(let ((a \"foo\")) (princ #?\"${a}\"))")
=> no dispatch function defined for #\?
like image 852
nbtrap Avatar asked Sep 02 '13 13:09

nbtrap


1 Answers

Because there's only a single reader, with global state. You're effectively turning your macros on and off. In this case the reader macros are enabled only for the duration that your read-and-eval function is read at compile time.

In this case you would need to set the macros up within the read-and-eval function to ensure the reader is in the proper state when you need it.

like image 50
Will Hartung Avatar answered Oct 07 '22 23:10

Will Hartung