[Top][All Lists]

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

Re: How the backquote and the comma really work?

From: Michael Heerdegen
Subject: Re: How the backquote and the comma really work?
Date: Wed, 12 Aug 2015 17:29:18 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux)

Marcin Borkowski <address@hidden> writes:

> Interestingly, there's a lot of buzz about Lisp /interpreter/ written
> in Lisp, but not so much about Lisp /reader/ written in Lisp.  In
> fact, I didn't find one on the Internet.

Good question.  Maybe it's because doing such things is mainly for
educational reasons, and when you want to learn how a language works,
studying the interpreter is more beneficial.

> What I found was Peter Norvig's tiny Lisp written in Python
> (  His reader is quite simple, but there
> is an important difference: he reads all the tokens into a (Python)
> list, and then he can "peek" at the next token without "consuming" it.
> In my approach, this is not possible (well, it is of course possible,
> but moving the point back so that the same token will be read again is
> ugly).

What disadvantages do you fear could your version have?

On the page you cited, the flat list is only used as an intermediate
step to produce the syntax tree.  There is not much more you could do
with it.

And if you want to re-read any form in some buffer, putting point back
to its beginning is a fast operation.

> Now I'm wondering: is my approach (read one token at a time, but never
> go back, so that I can't really "peek" at the next one) reasonable?
> Maybe I should just read all tokens in a list?  I do not like this
> approach very much.  I could also set up a buffer, which would contain
> zero or one tokens to read, and put the already read token in that
> buffer in some cases (pretty much what TeX's \futurelet does.  Now
> I appreciate why it's there...).

I really don't get the point in which way the Python example would have
advantages over yours.  The only difference is that your version
combines the two steps that are separate in the Python example.  Your
version is more efficient, since it avoids building a very long list
that is not really needed and will cause a lot of garbage collection to
be done afterwards.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]