From: Jeff
Subject: Creating my own read table
Date: 
Message-ID: <cf8fc4$srr@odah37.prod.google.com>
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

From: Hannah Schroeter
Subject: Re: Creating my own read table
Date: 
Message-ID: <cf8kh3$a1t$1@c3po.use.schlund.de>
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.
From: Peter Seibel
Subject: Re: Creating my own read table
Date: 
Message-ID: <m3llgot378.fsf@javamonkey.com>
······@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