Neil Toronto:
> I've been studying up on reader macros and macros so I can understand 
> them better. I have some questions about the former.

I'm guessing you mean Common Lisp, yes?  There are lots of Lisp-based 
languages.  But presuming you mean Common Lisp...

> So a reader macro gets registered to the readtable using a single 
> character, or two for dispatch read macros.

Er, sortof.  You can set more than one macro character to invoke the same 
function.

> 1. How many characters can you unread?

Only one, and it has to be the character you just read.  See "unread-char", 
page 573,
"Common Lisp: The Language" 2nd ed, Guy L. Steele Jr.  Copyright 1990.  C's 
ungetc() has the same (portable) limitation.

Scheme doesn't even have a standard unget character, as far as I know.  I don't 
know about emacs Lisp or other Lisps.

> 2. Even if you can unread as many as you want, does the setup 
> effectively limit reading to certain subsets of context-free languages?

See above.

> 3. Would it be useful for reader macros to somehow keep "state" or 
> "context"? (E.g. access to the call stack of reader macros.)

Sure, though it depends.

I plan to implement sweet-expressions-noindent as a completely new function 
that replaces "read" in its entirety.  Scheme doesn't have a readtable anyway, 
but even so, the readtable works well with certain kinds of syntax... and not 
so well with others.  In the longer term, a Common Lispish unique reader that 
also employed the readtable (etc.) might be best, but that should be enough for 
enabling use.

> 4. Would it be useful to have readers that operate on tokens rather than 
> characters - that is, they run on the output of a lexer, or on the 
> output of the regular reader macros?

Sure, it depends.

Again, many just call "read", so if you override "read", you're going to use a 
completely different reader.

--- David A. Wheeler

Reply via email to