Live data from Hacker News

Compiling a Lisp: Reader

bernsteinbear.com

21–30 of 30 posts

Re: Compiling a Lisp: Reader

#21

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

Is there a reason you treat the arithmetic operators specially in your reader? Non-lisps do so as they are infix operators, but most lisps treat them the same as any other identifier.

Re: Compiling a Lisp: Reader

#22
post #21

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

Is there a reason you treat the arithmetic operators specially in your reader? Non-lisps do so as they are infix operators, but most lisps treat them the same as any other identifier.

I don't think I treat them any differently in my reader. They are part of the set of "symbol characters". I do special case + and - prefixed integers, though.

Re: Compiling a Lisp: Reader

#23
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?

Lots of things you might want to name have natural names starting with numbers. If you're writing, say, a TSP solver, some of your procedures may be called 2-opt or 3-opt, for example.

Re: Compiling a Lisp: Reader

#24
post #6
post #3

Earlier quoted context omitted.

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?

Nothing wrong, was just wondering in case I missed something, in most languages by convention variables and functions cannot start with a number. I'm learning lisp and ran into this at some point just had the chance to ask someone experienced why.

Re: Compiling a Lisp: Reader

#25
post #23
post #3

Earlier quoted context omitted.

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

Lots of things you might want to name have natural names starting with numbers. If you're writing, say, a TSP solver, some of your procedures may be called 2-opt or 3-opt, for example.

I like that about lisp and surprisingly I came to like the kebab case, i find it quite easy to read at a glance. Before toying with scheme that and the parentheses seemed a bit dated but I came to like them quite a bit

Re: Compiling a Lisp: Reader

#26
post #21

Earlier quoted context omitted.

Is there a reason you treat the arithmetic operators specially in your reader? Non-lisps do so as they are infix operators, but most lisps treat them the same as any other identifier.

I don't think I treat them any differently in my reader. They are part of the set of "symbol characters". I do special case + and - prefixed integers, though.

Right, just read some logic backwards flipping through that code.

Re: Compiling a Lisp: Reader

#27
post #6

Earlier quoted context omitted.

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

Nothing wrong, was just wondering in case I missed something, in most languages by convention variables and functions cannot start with a number. I'm learning lisp and ran into this at some point just had the chance to ask someone experienced why.

[deleted]

Re: Compiling a Lisp: Reader

#28
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…

Racket is fun. You can indeed use it to write about any language you want, not limited to Lisp-alikes.

https://blind.guru/MarioLANG.html

Re: Compiling a Lisp: Reader

#29
post #6

Earlier quoted context omitted.

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

Nothing wrong, was just wondering in case I missed something, in most languages by convention variables and functions cannot start with a number. I'm learning lisp and ran into this at some point just had the chance to ask someone experienced why.

I had floating point implemented like that in Nokolisp. If the item contains anything except number characters, it is a symbol. Stupid, but very transparent eventually, because modified arithmetic operators test if a symbol can be interpreted as a floating point number.

Re: Compiling a Lisp: Reader

#30

Earlier quoted context omitted.

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!

I agree that I really enjoy reading in-depth blog post series, but after releasing a 3-part series myself, I'm not sure if I would do it again. Each subsequent post got about 1/3 the views of the previous one, and wow does it take sooo much more effort to write than a one-off post! This one is great though. I just every few days for the next post!

Indeed, these things take a lot of effort and views / feedback isn’t great.

Unfortunately the internet has moved towards short form, rehashing simple concepts and clickbait titles - there’s so much junk online, and the signal to noise ratio is high.

But people are gaming for most interaction, views, etc and attention spans are shorter. So this is the world we live in

Post reply on HN