help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: How the backquote and the comma really work?


From: Marcin Borkowski
Subject: Re: How the backquote and the comma really work?
Date: Tue, 11 Aug 2015 13:41:20 +0200

On 2015-07-24, at 15:01, Michael Heerdegen <address@hidden> wrote:

> Michael Heerdegen <address@hidden> writes:
>
>> > Stupid me – again;-).  No wonder ‘mci/read-list-contents’ appears
>> > twice, once, once in ‘mci/read’ and once in ‘mci/read-list-contents’
>> > – it seems there’s no other way (though I can’t prove it formally).
>>
>> I don't think every implementation needs to have it in two different
>> defuns.
>
> For the record: Better make your `mci/read' read lists recursively.  If
> `mci/read' finds something that isn't a list, read that.  If it finds a
> list, `mci/read' all its members recursively and put the read objects
> into a list.  No need for a `mci/read-list-contents'.

As you can see, I came back to this project, and I have further
questions...

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.

What I found was Peter Norvig's tiny Lisp written in Python
(http://norvig.com/lispy.html).  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).

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...).

Yet another approach would be not to signal an `error' in (mci/read)
when the closing paren is encountered, but use `throw' and `catch'.  Not
the most elegant way, probably.

So, does anyone know of a Lisp reader written in Lisp, so that I could
learn how smarter people solved this problem?

Anyway, it seems that the main purpose of my project turned out really
well: I'm learning a lot.  I'd love to grab some real book on language
design/implementation, but I'd have to schedule considerable time for
that...

> Regards,
>
> Michael.

Best,

-- 
Marcin Borkowski
http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski
Faculty of Mathematics and Computer Science
Adam Mickiewicz University



reply via email to

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