Live data from Hacker News

Compiling a Lisp: Reader

bernsteinbear.com

1–10 of 30 posts

Re: Compiling a Lisp: Reader

#2
For a very simple, very readable Lisp reader, see Lumen's reader.l file: https://github.com/sctb/lumen/blob/master/reader.l

It compiles to Javacript and Lua, so if you prefer reading those, you can:

https://github.com/sctb/lumen/blob/master/bin/reader.js

https://github.com/sctb/lumen/blob/master/bin/reader.lua

It turns out that you can greatly simplify the code by e.g. "does an atom start with 0x, 0-9, or dash? if so, try converting it to a number."

That turns out to handle cases like 1e9 too. Whereas "1e" becomes a valid lisp symbol. So you can set it to your own value.

The emacs source code is also worth reading. It's not simple, but it's simple enough to be understandable: https://github.com/emacs-mirror/emacs/blob/7b3e94b6648ed00c6...

I like emacs source code because it handles "every possible real-world case that you can think of."

Re: Compiling a Lisp: Reader

#3

For a very simple, very readable Lisp reader, see Lumen's reader.l file: https://github.com/sctb/lumen/blob/master/reader.l It compiles to Javacript and Lua, so if you prefer reading those, you can: https://github.com/sctb/lumen/blob/master/bin/reader.js https://github.com/sctb/lumen/blob/master/bin/reader.lua It turns out that you can greatly simplify the code by e.g. "does an atom start with 0x, 0-9, or dash? if so…

Why are atoms that start with numbers accepted as symbols? Is there any usecase for that?

Re: Compiling a Lisp: Reader

#5

For a very simple, very readable Lisp reader, see Lumen's reader.l file: https://github.com/sctb/lumen/blob/master/reader.l It compiles to Javacript and Lua, so if you prefer reading those, you can: https://github.com/sctb/lumen/blob/master/bin/reader.js https://github.com/sctb/lumen/blob/master/bin/reader.lua It turns out that you can greatly simplify the code by e.g. "does an atom start with 0x, 0-9, or dash? if so…

I attribute a big chunk of my real-world education (back in the 90s) about how to ship a complicated software product on multiple architectures to reading the Mosaic and XEmacs source code. It helped me immensely when trying to ship my own software.

Re: Compiling a Lisp: Reader

#6
post #3

For a very simple, very readable Lisp reader, see Lumen's reader.l file: https://github.com/sctb/lumen/blob/master/reader.l It compiles to Javacript and Lua, so if you prefer reading those, you can: https://github.com/sctb/lumen/blob/master/bin/reader.js https://github.com/sctb/lumen/blob/master/bin/reader.lua It turns out that you can greatly simplify the code by e.g. "does an atom start with 0x, 0-9, or dash? if so…

Why are atoms that start with numbers accepted as symbols? Is there any usecase for that?

The use case is someone wanted to name a symbol that way. What’s wrong with that?

Re: Compiling a Lisp: Reader

#7

Oh cool, someone else besides me posted my blog :D I'm the author and here to answer questions and take constructive criticism. If you want to comment but don't have an HN account, please check out the mailing list: https://lists.sr.ht/~max/compiling-lisp

I love seeing long form blog posts like this! Whilst its not something I’d personally do for a long time, its great to have resources on the web that go into detail in advanced topics like building a lisp interpreter.

From another lisper, congrats and well done!

Re: Compiling a Lisp: Reader

#8
I've been working my way through Beautiful Racket [1] over the last week or so. It's been awesome. If this kind of thing is of interest to you, I highly recommend it. It's a book focused on a way of thinking that involves building small domain-specific languages to solve your problems. It's so easy.

Racket (if you're not aware of what it is) is just a lisp, but the standard library includes an incredible amount of support for creating readers and expanders for programming languages with very little effort.

You aren't even limited to Racket as the target language for your compilation. It's incredibly easy to formulate whatever output you want (like assembly in this article).

Of course there's still an incredible amount of value and fun in doing everything from scratch like this article's series describes. One of the most intellectually rewarding things I've ever done is working through nand2tetris.

You have a great blog /u/tekknolagi.

[1]: https://beautifulracket.com/

Re: Compiling a Lisp: Reader

#9
post #8

I've been working my way through Beautiful Racket [1] over the last week or so. It's been awesome. If this kind of thing is of interest to you, I highly recommend it. It's a book focused on a way of thinking that involves building small domain-specific languages to solve your problems. It's so easy. Racket (if you're not aware of what it is) is just a lisp, but the standard library includes an incredible amount of su…

I've been meaning to do beautiful racket but totally forgot about it. Thanks for mentioning it.

Re: Compiling a Lisp: Reader

#10

Oh cool, someone else besides me posted my blog :D I'm the author and here to answer questions and take constructive criticism. If you want to comment but don't have an HN account, please check out the mailing list: https://lists.sr.ht/~max/compiling-lisp

I love seeing long form blog posts like this! Whilst its not something I’d personally do for a long time, its great to have resources on the web that go into detail in advanced topics like building a lisp interpreter. From another lisper, congrats and well done!

[deleted]
Post reply on HN