Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Learn C and build your own Lisp (buildyourownlisp.com)
320 points by juliangamble on Oct 29, 2015 | hide | past | favorite | 49 comments


On the topic of writing lisps, an obligatory link to my favorite project: Make a Lisp

https://github.com/kanaka/mal


not yet in brainfuck though, I see



Yes, like that.


Now might be a little late to comment, but if you want to write your own Scheme and learn Haskell, try this: https://en.wikibooks.org/wiki/Write_Yourself_a_Scheme_in_48_...

This tutorial/book, written by Jonathan Tang is actually cited as an inspiration in the credits page and is a very nice way to get into functional programming.


There is a previous discussion about this.

https://news.ycombinator.com/item?id=7530427


if you really want to learn to build lisp, please lookup "lisp in small pieces" http://www.amazon.com/Lisp-Small-Pieces-Christian-Queinnec/d...


For a much smaller piece, this technical report contains a two-page compiler for a small Lisp to x86 assembly, from parsing to codegen, written as a series of Parsing Expression Grammar substitutions:

http://www.vpri.org/pdf/tr2010003_PEG.pdf

I admit that it's probably not the best thing to learn from at first, but it's truly a thing of beauty.


For french speakers, there is a newer edition of that book which has never been translated to english. It is titled "Principes d'implantation de Scheme et Lisp" and is available here:

http://paracamplus.com/spip/?page=livre&isbn=978-2-916466-03...


I still remember when Amazon CA accidentally had this on sale for a pittance, then axed all the orders when people tried to buy it. Really should get a copy at some point.


Ha, they did cancel the orders ?

The fun of seeing a lisp book on amazon's best sellers all of a sudden.

ps: Highly valuable book, it's dense, theoretical but not too much, opens on a lot of other papers, and covers a large space about languages.


Yeah they cancelled my order. The price (of a few cents) had been assigned by a software error. Amazon was most apologetic for their inability to ship the item, and compensated me with a $10.00 voucher.

On a related note, I found a copy of Adele Goldberg's 'Smalltalk 80: The Language' in a junk shop for 50 cents. When I checked Amazon, the listed price was over five thousand dollars (due to automated bidding bots from rival booksellers).


I think a few orders actually shipped, but the impression I got was the vast majority got cancelled, and yeah I've only heard wonderful things about the book, I just need to decide to drop the cash on it.


Not just for learning lisp. This is must-read text for anyone developing interpreters or compilers development or implementing dynamic languages.


ahem... "Any sufficiently complicated C or Fortran program contains an ad hoc, informally-specified, bug-ridden, slow implementation of half of Common Lisp."


That... actually makes sense.

Sadly :(


I learned Go and built my own Logo: https://github.com/adkennan/logo :]


Are there any guides like this one for building a logo interpreter? I'd wager it's been around 15 years since I last played with that - but it left me with a lasting impression


To be honest, I just grabbed a PDF of the Apple Logo II manual and blazed away at it, hence the scariness of some of the eval and rendering code... I got distracted by other things before completing the IO and editing parts but it was a lot of fun.


how did you handle the ambiguous syntax, i'm writing a logo interpreter right now? having a lot of problems with the inline command syntax.


It's been a while but, from memory, the parts that caused me the most grief were infix operators, unary minus and statements like IF with a variable number of parameters.

I parsed the text into nested lists of Nodes where each node could be a literal or "word" value, a [ ] list or a ( ) grouping. The interpreter treats the nodes as a stream to be consumed one at a time.

When the interpreter is expecting a call to a procedure the next node in the stream should be a word. It can then look up the procedure in a dictionary of built in and user defined procedures. The list of parameters to the procedure indicates how many additional nodes to evaluate when building the values to pass to it.

In the case of variable parameters like a call to SUM you can express it as "SUM 10 20" for the minimum parameters or "(SUM 10 20 30)" for a variable number. The grouping indicates the first element, SUM, is the proc and all the other values are parameters. You could also express it as "10 + 20 + 30" which is evaluated as either "(SUM 10 (SUM 20 30))" or "(SUM (SUM 10 20) 30)" - I can't remember off the top of my head!


And so I did in 2008-2009 https://github.com/szastupov/lgears :)


In a similar vein, I've been playing with a simple Lisp interpreter:

http://www.sonoma.edu/users/l/luvisi/sl3.c

The "toy" interpreters that I've found -- Lisp and otherwise -- leak memory. So I'm doing a little bit of research into garbage collection. All in the name of fun and learning.


The book refers to a link to getting started in creating a garbage collector.

http://journal.stuffwithstuff.com/2013/12/08/babys-first-gar...


Thanks for that link! It looks like something that I could comprehend. My C programming skills are pretty limited -- I learned C to move myself one step away from assembly language on microcontrollers.


Similar: Exploring Programming Languages In Perl by Bill Hails, where he builds an implementation of Scheme

http://billhails.net/Book/


Ah, nice topic. Just released TXR 121. TXR Lisp gets delimited continuations in this release.

http://www.kylheku.com/cgit/txr

Doc: http://www.nongnu.org/txr/txr-manpage.html#N-01C4E6B4


Check out UC Berkeley's introductory CS class's take on it: http://cs61a.org/lab/lab09/


Cool. I really like the inline quizzes on that page, where you can hit the button to toggle solutions.


Here's another option for building a lisp-descendant from Scheme.

http://t3x.org/s9book/index.html

"Scheme9 from Empty Space"

I've not tried any of these. I'd be interested in someone who's done the lot (Lisp in Small Pieces, the Haskell one, and these two C-created lisps) giving a take on each. Making a lisp or forth seems like a great way to learn [x] thing.


Is this really for someone with no C knowledge, i'd definitely love to learn manual memory management and the such - this might be too much to chew at once.


Judging by the start (especially http://www.buildyourownlisp.com/chapter2_installation) I would say it's very much aimed at beginners. Not beginners to programming but definitely beginners and up for C.


Shameless plug, but here we go: http://t3x.org/s9book


Nice to see you chiming in. I picked up the 2nd Ed years ago and filled in a few of those "Oh, that's what they meant" gaps that looking at a complete/optimized/bummed implementation didn't explain for me. :)


Good to hear! Thanks!


Building a C compiler in Lisp can be a fun thing, too, and learn a lot about C.


This looks great. C was my first language but I never did anything too advanced with it.


My first love too. I still like to go back and play around with it.


I just started this. :)


Great book, but this is the third time this has been posted in the last year.

https://news.ycombinator.com/from?site=buildyourownlisp.com


True, but we don't count posts as dupes unless the story has had significant attention in the last year or so (see https://news.ycombinator.com/newsfaq.html), and arguably there hasn't been significant attention since https://news.ycombinator.com/item?id=7530427.


That shows just how great the concept is.


what other built-in ways are there to query stories posted to HN?


There aren't any, that one is new. You can play with the Firebase or Algolia systems though.


I'm a bit looking too forward. Found video of Stephen Wolfram himself demonstrating the power of his language. https://www.livecoding.tv/video/live-with-stephen-wolfram/


Please stop using HN comments just to promote links to your site. Users here consider that spam.

HN threads are supposed to be conversations. It's fine to bring up what you're working on if it's naturally related and makes the conversation more interesting. But it's not fine only to do that, or to contrive opportunities for it; that's not conversation, it's commercials.


> If you're looking to learn C, or you've ever wondered how to build your own programming language, this is the book for you. In just a few lines of code, I'll teach you how to use C, and together, we'll start building your very own language.

Agreed on "a few lines", but why should I buy a whole book on this? I'd really appreciate if the OP tried not to hijack hacker feeds for promotion. At least in my book, (s)he is blacklisted for eternity.


You can read the book online. Beyond that, if by hacker feeds you're referring to hacker news, you may notice that the author of the book and the submitter are two different people. Finally, do you really think it's unusual for someone to use hacker news for promotion?

Save the "blacklisted for eternity" melodrama for a worthy cause.


I disagree. The author (she?) has spent what looks like a lot of effort in building a introduction to at least two areas of basic software literacy and, assuming the book is even half way reliable (quick look shows no obvious horrors) then this is a worthwhile addition to the "how to code" which beats most Java-in-10-days books simply for its subject matter.

Add in what seems to be a recurring theme of "don't worry, this is hard, ignore the (male?) arse-hats and just do it, and we have an introduction by and for women - a sorely needed part of the landscape.

So, as I judge this book by its cover, it seems a good and worthwhile addition to the community. Please use Hacker News to promote worthwhile additions (especially as there seems to be a free online copy)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: