19 ms·
Learn C and Build Your Own Lisp (2014)
- oumua_don17 8y agoPrevious discussions https://news.ycombinator.com/item?id=7530427 https://news.ycombinator.com/item?id=7530427 and https://news.ycombinator.com/item?id=10474717 https://news.ycombinator.com/item?id=10474717
- spraak 8y agoIs there a guide like this that uses Golang instead of C?
- phoe-krk 8y agoYou could try MAL (Make A Lisp) - it has a go version. https://github.com/kanaka/mal/tree/master/go https://github.com/kanaka/mal/tree/master/go
- phamilton 8y agoI highly recommend MAL. It does a great job introducing these concepts.
- schoen 8y agoAnother way to describe the MAL concept is that it aspires to be implementation-language agnostic, so that it gives you a series of steps that you're meant to follow regardless of what language you're writing your interpreter in. So the fact that someone else has (or hasn't) already succeeded in doing it in language X needn't affect your ability to do it yourself with language X. I worked through most of MAL with Python and am currently doing it in Haskell. It's a great experience! (I think a few of the concepts could be explained in more detail, though. Maybe I should send in a patch.)
- eigenspace 8y agoMAL is great!
- AlexeyBrin 8y agoWriting an interpreter in Go https://www.amazon.com/Writing-Interpreter-Go-Thorsten-Ball/dp/300055808X https://www.amazon.com/Writing-Interpreter-Go-Thorsten-Ball/... is pretty good. The book assumes that you know Go and the resulting interpreter is not a Lisp.
- UncleEntity 8y agoI've been thumbing through that every so often (as is, presumably, the person who stole the package off my doorstep the first time they shipped it) and it's easy enough to follow without having ever written a single line in go. Though I would suggest reading other sources on how pratt parsers work if you want to fully understand the pure simple genius behind them.
- stevekemp 8y agoI had fun extending the sample language to add new features https://github.com/skx/monkey/ https://github.com/skx/monkey/ though so far I've still not read the book.
- cabaalis 8y agoI have been following this for the past few weeks in my off-time and would recommend it to everyone. It is also geared towards teaching C. I wrote in C many years ago but with the past 8 or so years writing exclusively C# it feels like a homecoming. It does make use of the author's grammar parser, which is my only minor complaint. Does anyone know a good resource in which the author handcrafts a parser? I'm aware of the various parser generators that exist. I also read the dragon book in my college's compiler design course ~12 years ago. But we also used a parser generator in that class.
- AlexeyBrin 8y ago> Does anyone know a good resource in which the author handcrafts a parser? http://craftinginterpreters.com/contents.html http://craftinginterpreters.com/contents.html the book implements the Lox language in Java and C.
- nur0n 8y agoI read through parts of this book a few months back. I also did not like using that parser because I wanted to keep external dependencies to a minimum. Writing a parser for s-expressions turned out to be relatively simple. You can check out my implementation here: https://github.com/00vareladavid/scheme/blob/master/src/parse.c https://github.com/00vareladavid/scheme/blob/master/src/pars... . I believe the technique is called "recursive descent parsing".
- drblast 8y agohttp://www.lispworks.com/documentation/HyperSpec/Body/02_b.htm http://www.lispworks.com/documentation/HyperSpec/Body/02_b.h... That's the algorithm for the common lisp reader. Writing a recursive descent parser based on that spec is fairly straightforward. And once you hand write your own recursive descent parser you'll probably not want to give up the control that gives you to a parser generator. Yuck.
- deleted 8y ago[deleted]
- _d8fd 8y ago
- nojvek 8y agoPretty comprehensive site I should say. Even if not for LISP, it contains good patterns for C, lexers, parsers, interpreters, etc. As someone interested in Language. I’ll definitely be giving more thought to it.
- mysterydip 8y agoSemi-related, racket http://racket-lang.org/ http://racket-lang.org/ is a lisp dialect and touts itself as "the world’s first ecosystem for developing and deploying new languages. Make your dream language"
- deleted 8y ago[deleted]
- deleted 8y ago[deleted]
- sus_007 8y agoYou can also support the author by purchasing the book from Amazon. (: http://www.amazon.com/Build-Your-Lisp-Daniel-Holden/dp/1501006622 http://www.amazon.com/Build-Your-Lisp-Daniel-Holden/dp/15010...
- p0nce 8y agoA great way to learn about the value of syntax.
- iafisher 8y agoI read this book about a year ago and later wrote another Lisp [1] from scratch but based on the design in the book. It's still one of my favorite computer science books. He covers quite a range of topics (C programming, traditional Lisp stuff, some other functional programming topics like currying) and the quality is superb. One thing the Lisp interpreter described in the book lacks (if I recall correctly) is a proper garbage collector, which can be an interesting extension to the project if you're up for a challenge. [1] https://github.com/iafisher/scam https://github.com/iafisher/scam
- aecorredor 8y agoDoes this cover memory management?
- rain1 8y agodoesn't seem to do GC or TCO! I've got those in my scheme https://github.com/rain-1/scheme_interpreter https://github.com/rain-1/scheme_interpreter but it isn't perfect
- shakna 8y agoKinda? Every value has both a constructor that assigns memory, and a destructor that frees it. Every expression also reallocates it's memory as it processes. So memory is managed and doesn't leak, but it doesn't quite fit with what we know as a GC, and could trash performance in some cases. And Tail-Call-Optimisation isn't really touched on.
- nils-m-holm 8y agoIf you excuse the plug: Scheme 9 from Empty Space (https://www.t3x.org/s9book/index.html https://www.t3x.org/s9book/index.html) explains GC, tail call elimination, continuations, macros, bignums, flonums, etc.
- kuwze 8y agoThere is also "Write Yourself a Scheme in 48 Hours"[0]. I am looking towards following this tutorial. [0]: https://en.wikibooks.org/wiki/Write_Yourself_a_Scheme_in_48_Hours https://en.wikibooks.org/wiki/Write_Yourself_a_Scheme_in_48_...
- masayune 8y agoIs this a good resource to beat the fear of recursion out of me? I get recursion, but it’s still really uncomfortable to think about.
- PeCaN 8y agolearn Haskell or OCaml or something alternatively just write more code because tbh that sounds like you just started programming
- renox 8y agoI find this dismissive comment funny: I started programming a long time ago in BASIC then assembly then Pascal then C and I still don't like recursion. I remember having to fix a bug in a recursive code that I didn't write: my feeling is that it is more difficult to debug recursive code than normal code.
- panzerklein 8y agoJust read The Little Schemer - the best book on recursion.
- chuchana 8y agoI liked Common Lisp: A Gentle Introduction to Symbolic Computation. You can find its first edition online (free of charge): https://www.cs.cmu.edu/~dst/LispBook/ https://www.cs.cmu.edu/~dst/LispBook/ Apart from explanations, it also contains exercises and their solutions.
- pjmlp 8y agoAs usual, the classical book for anyone interested digging into Lisp development environments, is "Lisp in Small Pieces".
- convolvatron 8y agothis book is really beautiful. it is in fact filled with exposition about how to build a lisp, but also how to bootstrap a language (or more generally any non-trivial environment). queinnec went to some pains to make this book accessible, in particular by heavily reducing his usual reliance on denotational semantics. but its not really a good causal introduction to the topic, it requires a certain amount of work to get through. but can't recommend this book strongly enough, maybe as the ideal followon to SICP
- User23 8y agoThis is a solid exercise. I particularly enjoy reimplementing the C primitives in Lisp once the system is bootstrapped. I used a quine as one of my unit tests for EVAL too.
- guywithahat 8y agoHonest question: why do people like lisp so much? Everything I've been able to learn about the language is that it was designed for a non-register based hardware that never caught on, so now it's just a less effective language that doesn't run as fast as anything else and has a steep learning curve since you need to learn a new programming paradigm. The only good thing I've heard about it is it's simple to implement since it doesn't have a ton of functions, but that doesn't seem like a very good reason to do something just because it's easy to write the code.
- KingMob 8y agoI doubt anyone in the modern era thinks about 60's hardware when evaluating Lisps. If this is what you think of them, you're reading some odd stuff. Check out Paul Graham's On Lisp, or Seibel's Practical Common Lisp. Most people using lisps aren't implementing them. People are drawn to them for various reasons, among them: strong metaprogramming facilities, real homoiconicity, DSLs, multiple paradigms, REPL development, hot-loading, and sheer elegance.
- MatthewPhillips 8y agoI don't know where you get that it can't be fast, that's certainly not true. Gambit Scheme is just one example of a fast lisp. People like lisps because they are written as ASTs. So you can manipulate programs (ASTs) to create DSLs very easily.
- jmcomets 8y agoMetaprogramming. At least that's what I enjoy. In Lisp you can "quote" s-expressions (think "function body"), manipulate the AST and evaluate them how you see fit. It's like Ruby's blocks or Python's metaclasses, but with any construct in the language.
- ychen306 8y agoPerformance wise it's not slower than languages like Python. For some people (not me) macros simplify their development by a lot. The learning curve is honestly pretty shallow; in my experience Lisp is hard for people who haven't really nailed down recursions, and in this respect it's also a great learning tool. Being simple to implement is a big plus as it allows you to focus on the crucial parts -- IMO people learn better when they get to learn one thing at a time and having a small core to your language is important.
- agumonkey 8y agoFind the style and code lovely.
- mastrsushi 8y agoIf you want a job as an entry level programmer, do not bother learning C, go with something like C#, JavaScript, Java, or Python. The author doesn't really list any viable reasons to use C over any more modern, convenient language. Just the whole "shows you how memory management really works". A lot of C programmers remind me of the die hard Gentoo/Arch Linux people who think it'll help them "show you how Linux really works".
- tannhaeuser 8y agoThe value of learning asm and C doesn't necessarily come from using these languages, but lies in understanding how a CPU works and how memory is laid out and managed. So that you can put abstractions and automatic memory management to good work. There's a reason Knuth uses his MIX assembler language for discussing algorithms and algorithmitic complexity analysis. If you don't know these things, you basically don't know what you're doing when you're programming a computer.
- DonaldFisk 8y agoMaybe, but the author writes: "This book is for anyone wanting to learn C, or who has once wondered how to build their own programming language ... But C is not about software development and careers." So the author has something else in mind: building a high level language from the hardware up. C#, JavaScript, Java, and Python already contain much of the basic functionality of Lisp, most importantly a garbage collector, memory safety, and high-level data types.
- JasonFruit 8y agoI've spent an hour on this now, and I've learned more about actual C programming than in several previous attempts put together. What a teacher!
- gsaga 8y agoThe comments here mention a lot of advanced stuff like recursive decent and compiler design. Should a second year student get into this book?
- gsaga 8y agoI'm currently looking into the clojure source code with the tim daly's book.
- rwnspace 8y agoThat's a question that doesn't have any really good answer, right? Unless you're looking for someone to say 'yes, unconditionally' or 'actually [x] requires masters-level+ mathematics'. I'm self-studying and have been working through 'the Dragon book', regarding compilers. I like Lisp due to beginning my learning with HtDP and SICP, and the functional paradigm appeals to me. I'm just beginning K&R C, and Kernighan's Unix Programming Environment. Naturally I'm really excited to find this here so I'll definitely be working through it. Were I more concerned about ticking boxes on my CV for the person in HR then I probably wouldn't bother.
- pjmlp 8y agoI got into compilers when I was still in high school, I was 16 years old at the time. It is only a matter of reading the required material and get going at it.
- htor 8y agothe question is which one learns you c the better? learn c and build your own lisp? or learn lisp and build your own c? both poses challenges with regards to the inner workings of c.
- Const-me 8y agoI recently wrote slightly similar example, much simpler, where I essentially implemented 10% of Basic in modern C++: https://github.com/Const-me/MicroScript https://github.com/Const-me/MicroScript
- pankajdoharey 8y agoNot a very good tutorial if you want to learn how to make a lisp interpreter. It uses a parser combinator library, when in reality a lisp parser is so simple to implement that all you need is basic C skills. Infact it feels like a self promotion of his combinator library than an actual tutorial. Better study MAL.