I was wondering if there was a way to create my own readtable and
subsequently set it for a temporary call to READ? Basically, I'd like
this temporary readtable to contain lists, strings and numbers but
nothing else.
While I've created read macros in the past, I haven't done too much
with read macros or dispatch characters that are already there. Can I
use COPY-READTABLE and delete functionality from it, set it, and return
the old one?
Thanks in advance!
Jeff
Hello!
Jeff <···@insightbb.com> wrote:
>I was wondering if there was a way to create my own readtable and
>subsequently set it for a temporary call to READ? Basically, I'd like
>this temporary readtable to contain lists, strings and numbers but
>nothing else.
>While I've created read macros in the past, I haven't done too much
>with read macros or dispatch characters that are already there. Can I
>use COPY-READTABLE and delete functionality from it, set it, and return
>the old one?
>Thanks in advance!
>Jeff
(let ((*readtable* (copy-readtable)))
; modify it
(read))
Or cache your modified readtable like this:
(defvar *own-readtable*)
(setf *own-readtable* (copy-readtable))
; modify it
(let ((*readtable* *own-readtable*))
(read))
Just love the magic of special variables sometimes.
Kind regards,
Hannah.
······@schlund.de (Hannah Schroeter) writes:
> Hello!
>
> Jeff <···@insightbb.com> wrote:
>>I was wondering if there was a way to create my own readtable and
>>subsequently set it for a temporary call to READ? Basically, I'd like
>>this temporary readtable to contain lists, strings and numbers but
>>nothing else.
>
>>While I've created read macros in the past, I haven't done too much
>>with read macros or dispatch characters that are already there. Can I
>>use COPY-READTABLE and delete functionality from it, set it, and return
>>the old one?
>
>>Thanks in advance!
>
>>Jeff
>
> (let ((*readtable* (copy-readtable)))
> ; modify it
> (read))
>
> Or cache your modified readtable like this:
>
> (defvar *own-readtable*)
> (setf *own-readtable* (copy-readtable))
> ; modify it
>
> (let ((*readtable* *own-readtable*))
> (read))
>
> Just love the magic of special variables sometimes.
Also note that both LOAD and COMPILE-FILE bind *readtable* (and
*package*). I.e. it's as if they were implemented sort of like:
(defun load (file)
(let ((*readtable* *readtable*))
(internal-load file)))
and
(defun compile-file (file)
(let ((*readtable* *readtable*))
(internal-compile-file file)))
Since the new binding is the same value you don't want to modify the
readtable itself. But you can, in a file that is intended to be LOADed
or COMPILE-FILE'd say:
(eval-when (:compile-toplevel :load-toplevel)
(setq *readtable* *my-own-readtable*))
and not worry about setting *readtable* back to its original value.
-Peter
--
Peter Seibel ·····@javamonkey.com
Lisp is the red pill. -- John Fraser, comp.lang.lisp