8 ms·
Build Your Own Lisp
- ale 1y agoGiven how this is about building and compiling programming languages a portrait of Admiral Grace Hopper would have been more appropriate than Ada Lovelace.
- vincent-manis 1y agoOr Jean Sammet (author of a very comprehensive book on programming languages in the 1960s), or Lois Haibt (involved in development of original Fortran compiler) or Frances Allen (did key work at IBM on optimization in Fortran compilers), or Sister Mary Keller (involved in developing Dartmouth Basic), or Adele Goldberg (key developer of Smalltalk), or Barbara Liskov (CLU, and many other things)...those off the top of my head, though a web search would find many more, I'm sure.
- vincent-manis 1y agoOh, I forgot Lynn Conway (computer architecture)
- coderatlarge 1y agoi’m grateful to the author for making their work available online for free. 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.
- nyrikki 1y agoI may be old. But use to use the pure Lisp Chatlin included in C with his papers to learn languages a few times. Not as complete as this version of the language, but apparently ~300 lines of even REXX was enough although I never tried REXX.
- lskfiep 1y agoThis is MUCH more than a 'Build Your Own Lisp'. To the point of almost being anything but. 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 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 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#Reading_expressions 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".
- netbioserror 1y agoUnfortunately, part of the pragmatic usefulness of newer Lisps (Clojure and Janet) is the abandonment of CAR and CDR in favor of efficient distinct data structure types backed by efficient bases (tries, arrays, arraylists, hashmaps) and a focus on homoiconicity as the winning feature, separated forcefully from the idea of linked lists and CAR/CDR.
- kentrado 1y agoI don't well understand this. How is clojure more efficient than common lisp? Would you explain further?
- dark-star 1y agoLike most of these tutorials, this stops right where things get interesting. Taill-Call Optimization, Continuations, CPS, Call/CC... those are the things that are tricky to implement and without those the language is only a toy language. Then again, creating a toy-language is a worthwhile goal in itself, so kudos to everyone who follows this through to the end
- cardanome 1y agoDon’t Build Your Own Lisp: https://gist.github.com/no-defun-allowed/7e3e238c959e27d4919bb4272487d7ad https://gist.github.com/no-defun-allowed/7e3e238c959e27d4919... 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.
- Arch-TK 1y agoYou shouldn't use it to learn C either. It's full of bad C.
- freilanzer 1y agoThat sounds horrible. What are better resources?
- stevekemp 1y agoMAL, the original "make a lisp", is a bit terse on details but gives you freedom to use different languages, and yet still provide a rough blueprint: https://github.com/kanaka/mal https://github.com/kanaka/mal Discussed here, a few times: https://news.ycombinator.com/from?site=github.com/kanaka https://news.ycombinator.com/from?site=github.com/kanaka
- dang 1y agoThanks! Macroexpanded: Mal – Make a Lisp - https://news.ycombinator.com/item?id=26924344 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 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 https://news.ycombinator.com/item?id=15226110 - Sept 2017 (69 comments) Make your own Lisp - https://news.ycombinator.com/item?id=13967401 https://news.ycombinator.com/item?id=13967401 - March 2017 (32 comments) Mal – Make a Lisp - https://news.ycombinator.com/item?id=12720777 https://news.ycombinator.com/item?id=12720777 - Oct 2016 (1 comment) Make a Lisp in Nim - https://news.ycombinator.com/item?id=9145360 https://news.ycombinator.com/item?id=9145360 - March 2015 (44 comments) Make a Lisp - https://news.ycombinator.com/item?id=9121448 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 https://news.ycombinator.com/item?id=9109225 - Feb 2015 (16 comments)
- intellectronica 1y agoor just ask AI to do it for you :D https://gist.github.com/intellectronica/593885fcb02b0d10c4b90c77f7d26fc0 https://gist.github.com/intellectronica/593885fcb02b0d10c4b9...
- golly_ned 1y agoAre there any such build-a-lisp books/guides using modern c++?
- tnlogy 1y agoSomeone seems to have saved my old self-compiling scheme-to-c compiler in about 1k lines of scheme code. https://github.com/veqqq/llvm_scheme/blob/main/compile.ccode.ss https://github.com/veqqq/llvm_scheme/blob/main/compile.ccode... (also an llvm version) 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?
- adz5a 1y agoIs there a resource which compares Lisps (expressiveness, limitations, available special forms, ...)? I often read about lisp 1 and 2.0, clojure being a lisp 1.5 (because of the callable keywords if iirc). 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.
- Jtsummers 1y ago> lisp 1 and 2.0 Do you mean Lisp-1 and Lisp-2 as in the number of namespaces? https://dreamsongs.com/Separation.html 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
- dang 1y agoRelated: Build Your Own Lisp - https://news.ycombinator.com/item?id=36103946 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 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 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 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 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 https://news.ycombinator.com/item?id=7530427 - April 2014 (145 comments)
- codr7 1y agoI've been working this problem from different angles for a while now: https://github.com/codr7/shi-c https://github.com/codr7/shi-c https://github.com/codr7/hacktical-c https://github.com/codr7/hacktical-c
- gorgoiler 1y agoI learned recently that the creator of the Iosevka typeface did so using their own Lisp implementation. The typeface: https://github.com/be5invis/Iosevka https://github.com/be5invis/Iosevka The language: https://github.com/be5invis/PatEL https://github.com/be5invis/PatEL Their tool which they used to build the language: https://github.com/be5invis/patrisika 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 https://www.hope.net/pdf/hope_16_schedule.pdf
- metalliqaz 1y agoI poked around on those links and I have yet failed to find any use of this Lisp in that font project. Looks like he just built everything with Javascript
- dannyobrien 1y agoThe glyphs themselves are written in PatEl: see https://github.com/be5invis/Iosevka/blob/main/packages/font-glyphs/src/letter/latin/lower-a.ptl https://github.com/be5invis/Iosevka/blob/main/packages/font-... for instance. If you look through the commit history, you can see Be5invis gradually elaborating the font itself by editing these files. Javascript is used as the build language, but not to define the characters.
- staplung 1y agoAs others have pointed out, this is as much about learning C as it is about making a Lisp. 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://norvig.com/lispy.html https://norvig.com/lispy.html
- atan2 1y agoThe iso-9899.info C language website also includes this book in their "Stuff That Should Be Avoided" section. https://www.iso-9899.info/wiki/Books#Stuff_that_should_be_avoided https://www.iso-9899.info/wiki/Books#Stuff_that_should_be_av...
- carraes 1y agoHuh? It doesn't Edit: nvm, found it on the bigger list
- endmin 1y ago[dead]
- fmbb 1y agoThat page also seems to recommend using lex and yacc, so … what are we to do with this information?
- shawn_w 1y agoNothing wrong with lex and yacc.
- burnt-resistor 1y agoOr GNU flex and bison. ;o)
- J_McQuade 1y agoI feel called out - I have read and learned from 4 of the things on that list. I am also really bad at C, though, so "Can confirm", I guess?
- burnt-resistor 1y agoI concur with Stuff That Should Be Avoided.
- potato-peeler 1y agoIt seems to use c99, I would like to know from folks who have read this book, for learning newer features in C, what do you recommend? Also, does this book also teach some of the pitfalls of stdlib like gets or scanf? Basically I always read in HN/lobsters/other forums that modern C is just as safe as newer languages but I don’t see much book or tutorials teaching modern concepts or even industry standards like Misra?
- atiedebee 1y ago> Basically I always read in HN/lobsters/other forums that modern C is just as safe as newer languages This is absolutely false. Modern C++ might get close (although I am not too familiar with it) but C has not gotten much safer over the years (one might argue it got even less safe due to threads being added in C11). As for learning about modern versions of C: you can read cppreference[0] which has fairly accurate information on the standard. Not much has been added over the years and C17 is merely a minor correction, so there has really only been 2 new versions since C99. [0]: https://en.cppreference.com/w/c.html https://en.cppreference.com/w/c.html
- potato-peeler 1y agoI specifically mentioned Misra standards for writing safe C. And ensuring thread safety is not just a C Lang pitfall. I was not looking for language reference rather how current software written in C ensure memory safety. How do their development paradigm look like? Teaching both the software pitfalls in C and how to mitigate them, maybe by giving examples from modern software or standards like Misra, will really help someone to understand how to write better C. Just linking a language reference does not help.
- atiedebee 1y agoI misunderstood the question then, since I thought it was about learning about the newer language features. C coding standards differ quite a lot, and unfortunately I can't point out any software that has standards developed for safety. As to still try and be helpful: I've enjoyed reading nullprograms blog[0] where he looks into interesting ways to make C more useable (although he tends to replace the entire standard library for reasons highlighted here[1]) There is some must avoid functions (mostly string functions) and a good list of them has been compiled in the git project repository[2]. I've tried looking up the misra C guidelines but they were hard to find or (if I remember correctly) had to be paid for or something like that [0] https://nullprogram.com https://nullprogram.com [1] https://nullprogram.com/blog/2023/02/11/ https://nullprogram.com/blog/2023/02/11/ [2] https://github.com/git/git/blob/master/banned.h https://github.com/git/git/blob/master/banned.h
- frimmy 1y agolfg
- deterministic 1y agoI highly recommend writing your own Lisp interpreter in any language followed by writing a Lisp compiler using your own interpreted Lisp (compiling to C for example). It is great fun!