i once did an exercise like this myself (just the code not the book) for fun and found it extremely gratifying even though the code does not survive and never made it into any of my other projects as i had hoped at the outset.
mine got to be around 5 kloc with all the error handling but i wasn’t optimizing for keeping it short. i’m impressed by the many super brief ones that others with deeper understanding have built.
the point of view that this is really about learning C might have been buttressed further by starting with an existing super brief personal lisp and reading through that in a structured way; something that i personally would still like to do and that i semi-resorted to when debugging my way through the eval of the y-combinator which was one of the moments that exposed my poor design choices and the flaws i wasn’t cognizant of when doing simple expression evaluation. building a proper test harness was also a big deal as i went which seems like a highly relevant bit to highlight in a journey like this.
some references to existing high-quality short personal lisps and schemes might also be a welcome addition.
Not as complete as this version of the language, but apparently ~300 lines of even REXX was enough although I never tried REXX.
This is an amazing resource for getting started with learning C by making your own "programming language", independent of any Lisp conventions.
For me, the most 'lispy' aspect of 'making your own lisp' is prebaked by the author with their using their own prebuilt parser library 'mpc'. (I was unable to find a link to the source in the book, so https://github.com/orangeduck/mpc )
I was unable to find any instance of 'car' or 'cdr' or 'caddar' and their like, which I feel is the real 'build your own lisp' epiphany.
https://en.wikipedia.org/wiki/CAR_and_CDR
The parser is so widely, and wildly, useful that it is independent of notation style, for instance, lisp's nearly ubiquitous 'polish notation'. (or its variants, for instance, 'cambridge polish notation')
Perfect example:
Under 'Chapter 9: Reading Expressions':
> Don't Lisps use Cons cells?
> Other Lisps have a slightly different definition of what an S-Expression is. In most other Lisps S-Expressions are defined inductively as either an atom such as a symbol of number, or two other S-Expressions joined, or cons, together.
> This naturally leads to an implementation using linked lists, a different data structure to the one we are using. I choose to represent S-Expressions as a variable sized array in this book for the purposes of simplicity, but it is important to be aware that the official definition, and typical implementation are both subtly different.
https://www.buildyourownlisp.com/chapter9_s_expressions#Read...
This is an awesome educational resource.
I think I would promote it more broadly than "Build Your Own Lisp".
Would you explain further?
That's not true. Both CL and Scheme have other data structures besides cons cells, and that's been true for the Lisp family of languages for nearly 70 years now.
This bizarre belief that everything is a cons cell in Lisp and Scheme needs to go away.
Thanks for the sarcasm! Very productive and good-natured of you.
For your reference:
LISP 1.5 manual: https://www.softwarepreservation.org/projects/LISP/book/LISP...
Arrays were present in 1960. Admittedly, not much else but clear evidence that even then it wasn't just cons cells.
https://www.lispworks.com/documentation/HyperSpec/Front/Cont... - Common Lisp Hyper Spec which describes data structures other than lists and cons cells.
C-f that PDF for "array". For the other manual, I linked the TOC. It's right there on the page (arrays and hash tables, and you can follow up with structures and objects) and there's no reason to read the entire manual. I figured most people knew how to use a table of contents, I apologize if I expected too much from you.
...do not require abandoning CAR and CDR, I think. See all other lisps having vectors, hashmaps, etc. Perhaps you're talking for code representation ? But I don't think that true for all 'traditional' lisps either. Also, there's been some innovation regarding lists: https://docs.racket-lang.org/reference/treelist.html
Linked lists are comically inefficient on modern hardware and naming two of your fundamental operations based on CPU instructions from a chip from the 60s is not what I would call good API design.
Then again, creating a toy-language is a worthwhile goal in itself, so kudos to everyone who follows this through to the end
Just so people are aware of it. It is not a good source if you want to learn how to make a lisp that could scale beyond a toy.
You can still learn a bit of C and get a taster of how to make a language, just be aware that some stuff you learn will hold you back in the long term.
Discussed here, a few times:
Mal – Make a Lisp - https://news.ycombinator.com/item?id=26924344 - April 2021 (40 comments)
Mal – Make a Lisp, implemented in 79 languages - https://news.ycombinator.com/item?id=21670442 - Nov 2019 (11 comments)
Mal – Make a Lisp, in 68 languages - https://news.ycombinator.com/item?id=15226110 - Sept 2017 (69 comments)
Make your own Lisp - https://news.ycombinator.com/item?id=13967401 - March 2017 (32 comments)
Mal – Make a Lisp - https://news.ycombinator.com/item?id=12720777 - Oct 2016 (1 comment)
Make a Lisp in Nim - https://news.ycombinator.com/item?id=9145360 - March 2015 (44 comments)
Make a Lisp - https://news.ycombinator.com/item?id=9121448 - Feb 2015 (41 comments)
Lisp implemented in under 1K of JavaScript - https://news.ycombinator.com/item?id=9109225 - Feb 2015 (16 comments)
Writing a Lisp in Ocaml: https://bernsteinbear.com/blog/lisp/00_fundamentals/
Not Lisp-specific but Crafting Interpreters is also great: https://craftinginterpreters.com/
[edit - though it looks like handlebars (that I use for generating HTML from templates) has about 30k lines in files that end in .js, so maybe twitter is 30m lines of code?]
[second edit - hmm... maybe i'll change the name to "mini-blog" to signal it's a blog that's 25% the performance of a "mainframe-blog" but 10% the cost. though "mini-blog" might be more appropriate: halfway between a "normal" blog entry and a "micro-blog."]
It takes a very thoughtful approach to introducing an increasingly complex Scheme implementation. I doesn't shy away from the complexity that many LISP implementation tutorials try to push under the rug.
Be aware that it's some 500 pages and makes several interpreters then a couple of compilers as I recall. If you read it though, you'll come out the other end with a pretty good understanding of how lisp implementations actually work.
I remember chatting with them years ago and they were pretty friendly. But yeah Lisp does have a specific culture and it can put people off thought I personally never encountered any bad apples.
"And a parser generator is very overkill for a Lisp parser - just use recursive decent!" -- it's interesting that, as simple as Lisp is to parse, this is the same advice you'd get from experienced C/C++ compiler writers, from modern Clang to Stroustrup in 1993.
My lisp has a conservative mark-and-sweep garbage collector. The mark phase spills all registers and then walks the entire stack looking for pointers to lisp objects. I managed to implement the stack walking through some convoluted pointer nonsense but even C could not express the notion of spilling registers, I had to write assembly code for each architecture.
I have no idea how such a garbage collector would be implemented in Rust or Zig.
"Build Your Own Lisp" is an opinionated, idiosyncratic take on one style of programming in C and one way to implement a Lisp-like language.
If you go into it treating it like an intro textbook to the "standard" way of implementing an interpreter, it may lead you astray. Worse, it may lead you astray without realizing it if it's your first book on the topic.
On the other hand, if you approach it as following an author as they deliberately wander off the well-trod path of implementing Lisps with recursive descent and all the other classic techniques, then you can have a good time and maybe get some interesting ideas out of it.
For what it's worth, I quite enjoyed the book. But I had enough programming language experience already to know when the author was teaching you the basics versus teaching you their own thing.
The more the world world becomes aggregated, summarized, averaged, and watered down, the more I crave stuff like this that is quirky and unique.
https://gist.github.com/intellectronica/593885fcb02b0d10c4b9...
Maybe I should read and compare it. Mine was a really slow Poc to inspired by SICP, is that book still used in courses somewhere?
Dabbling into llms I think that lisps could be very interesting format to expose tools to llms, ie prompting a llm to craft programs in a Lisp and then processing (by that I mean parsing, correcting, analyzing and evaluating the programs) those programs within the system to achieve the user's goal.
Do you mean Lisp-1 and Lisp-2 as in the number of namespaces?
https://dreamsongs.com/Separation.html - Goes into depth on the topic including pros and cons of each in the context of Common Lisp standardization at the time (ultimately arguing in favor of Lisp-2 for Common Lisp on grounds of practicality, but not arguing strictly for either in the future).
Common Lisp was a, more or less, unification of the various Lisps, not Scheme, that had developed along some path starting from Lisp 1.5 (some more direct than others). They were all Lisp-2s because they all kept the same Lisp 1.5 separation between functions and values. Scheme is a Lisp-1, meaning it unifies the namespaces. The two main differences you'll find are that in CL (and related Lisps) you'll need to use `funcall` where in Scheme you can directly use a function in the head position of an s-expr:
(let ((f ...)) ;; something evaluating to a function
(f ...)) ;; Scheme
(funcall f ...)) ;; Lisp
Build Your Own Lisp - https://news.ycombinator.com/item?id=36103946 - May 2023 (12 comments)
Learn C and build your own Lisp (2014) - https://news.ycombinator.com/item?id=35726033 - April 2023 (45 comments)
Learn C and build your own Lisp (2014) - https://news.ycombinator.com/item?id=27598424 - June 2021 (86 comments)
Learn C and Build Your Own Lisp (2014) - https://news.ycombinator.com/item?id=17478489 - July 2018 (86 comments)
Learn C and build your own Lisp - https://news.ycombinator.com/item?id=10474717 - Oct 2015 (49 comments)
Learn C and build your own Lisp - https://news.ycombinator.com/item?id=7530427 - April 2014 (145 comments)
The typeface:
https://github.com/be5invis/Iosevka
The language:
https://github.com/be5invis/PatEL
Their tool which they used to build the language:
https://github.com/be5invis/patrisika
These kinds of projects are deeply inspirational. Striving to achieve one percent of this output would be enough for me. Knowing there are people like Belleve / Renzhi Li and their team in the world -- that I might be able to do something like what they do if I, too, try hard -- is what makes me get out of bed in the morning. It is incredible that there are people like them, doing what they do, and sharing it freely. Thank you so much.
PS: Re: inspo: Hope 16 is next week :D https://www.hope.net/pdf/hope_16_schedule.pdf
If you're interested in the latter, Peter Norvig has a little project that builds a stripped down Scheme interpreter in python. Takes some shortcuts, provides only a few functions (about 30) to its environment and only recognizes 5 special forms (`quote`, `if`, `define`, `set!`, and `lambda`) but the whole thing is less than 150 lines and very informative if you're new to that kind of thing.
https://www.iso-9899.info/wiki/Books#Stuff_that_should_be_av...
Edit: nvm, found it on the bigger list
I am also really bad at C, though, so "Can confirm", I guess?
ale•14h ago
vincent-manis•8h ago
vincent-manis•8h ago