[plt-scheme] reader macros

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Thu Jun 2 21:54:02 EDT 2005

At Wed, 1 Jun 2005 23:17:07 -0500, Corey Sweeney wrote:
> I'm looking through the docs on the new reader macros, and am a little
> fuzzy how to get them started. [...]
>
> except read only can take 1 parameter, so maybe more like:
> (make-readtable #f #\~  {somesymbol}
>     (lambda (char port)
>          (list (quote super-quasi-quote) (read port))))
> 
> but once i get this, how do i register the table so that the next
> "(read)" will use the new transformation?

You could do this:

 (current-readtable (make-readtable ....))

which installs the readtable for future reads.


In most cases, of course, it's better to use `parameterize' with
`current-readtable' around a particular call to `read' or
`read-syntax'.


If you want to change the reading of code --- epsecially code in a
module --- then it's better to prefix the code with

 #reader "special-quote.ss"

where "special-quote.ss" is a module that provides a `read-syntax' like
this:

 (define (read-syntax source input-port)
   (parameterize ([current-readtable
                   (make-readtable ...)])
      (read-syntax source input-port)))


Matthew



Posted on the users mailing list.