[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Scheme-reports] Common Lisp-like read macros in Scheme

musicdenotation@x scripsit:

> In Common Lisp you have "read(er) macros" which are macros which
> convert a string to Lisp code and run it. In Scheme the feature is
> not specified in the R7RS-small. I propose that this be included in
> the core language in R7RS-large.

The trouble with read macros is that they suffer from the same phasing
problem as Common Lisp syntax macros (i.e. defmacro macros).  Whatever
code is used to change the readtable happens at run time, which means
there is no guarantee that it can reach backwards to affect the read-time
operations of the compiler, not even those which appear in the source
after the code that alters the readtable.

Racket avoids this problem using the lexical directive "#lang foo", which
loads a library named "foo" from a suitable place from inside `read`.
It is the responsibility of this library to translate whatever follows
the directive into ordinary Scheme.  It need not even be S-expressions:
Racket supports Algol 60 via "#lang algol60".

It would be possible to standardize this, or something like it, for
R7RS-large; in order to make it convenient to use, however, it would be
necessary to provide some way to expose the standard lexical syntax of
R7RS-small so that it could be altered selectively rather than replaced
in full.  I don't have any ideas on how to do that.

A half measure that would still be very useful is SRFI 108, which
translates a limited amount of lexical syntax extension into calls on
macros or procedures with specified names.  That allows arbitrary objects
to be represented in source code, but not in data to be read with `read`,
unless a syntax expander is available at run time.  (Which itself is an
interesting idea.)

After fixing the Y2K bug in an application:     John Cowan
        WELCOME TO <censored>                   cowan@x
        DATE: MONDAK, JANUARK 1, 1900           http://www.ccil.org/~cowan

Scheme-reports mailing list