14 ms·
Learn C and build your own Lisp
- aaronsnoswell 13y agoGot halfway through this today - most fun I've had programming in ages. Thanks for the link and thanks to the author!
- leondutoit 13y agoAwesome. Hope I can make time to go through it - looks like good fun. Thanks for putting it out there.
- quakkels 13y agoThanks for writing this. I find your writing style to be very easy to follow. I've wanted to play with a toy language for some time, so I'm very excited to dive into your book with both feet. I'm working on Windows and am up to chapter 6. Very enjoyable. The only suggestions I would offer is perhaps to mention that AST stands for Abstract Syntax Tree. It seems this book is targeted to less experienced programmers, so it may be helpful to mention what AST means in this context. Thank you for your hard work and willingness to share your knowledge.
- quakkels 13y agoWell, just made it to the next chapter where you talk about AST. :-)
- CGudapati 13y agoHow good is this book for a complete beginner? I am starting to learn C in my free time and I have no objective way to judge this book.
- deleted 13y ago[deleted]
- Xophmeister 13y agoI've only just had a quick scan through, but it looks thorough and well-paced; there are examples, exercises and useful looking pull-outs. Anecdotally, It definitely looks worthwhile for a self-teaching beginner and going in the "implementing your own LISP" direction is an interesting approach.
- simias 13y agoSkimming through the first chapters of the book I can say it doesn't seem to assume any prior knowledge of C or even a background in programming, it explains all the basic concepts (conditionals, types etc...) That being said I'm not entirely convinced that implementing a programming language is the best toy project for learning C since one of the first things you have to write is a parser and we all know string handling in C is a pity. That being said it looks very interesting, I know C quite well but I might read it for the "implementing lisp" parts.
- orangeduck 13y agoAuthor here. Actually a parser combinator library is used for the parsing. As you mention, I think there should be some interesting things inside for people with any experience in C.
- csl 13y agoI also did a scan of the book; it seems pretty good! However, if you're serious about learning C then I strongly recommend getting the K&R book [0]. It's short and quickly gets down to business --- the first chapter alone gives you a condensed but working overview of the language as a whole. Even experienced C programmers seem to keep the book around as it's good as a reference as well. I strongly recommend people to learn C. It's a small, beautiful and very powerful language and the lingua franca for language ABIs. In fact, many popular dynamic languages are implemented in C (Python, Ruby, Lua and countless others). Your time will be well spent! [0]: http://en.wikipedia.org/wiki/The_C_Programming_Language http://en.wikipedia.org/wiki/The_C_Programming_Language
- HillRat 13y agoOr King's C Programming: A Modern Approach, which lacks the conciseness (and affordability) of K&R but is probably the best single text out there, and unlike K&R is updated through C99.
- kjs3 13y agoKim King wrote my Modula-2 textbook. If this is as good as that, it's probably something worth picking up.
- krick 13y agoIn fact, this one (implementing Lispy thing, I mean) seems the best to me so far. Why? Paradoxically, because it's so obviously incomplete, so it makes you search something by yourself while you read it and helps to actually understand a little bit more. Both K&R and "Modern Approach" lack that word "Modern" very much, yet are written with undertone "it's everything you have to know about C", when it isn't. Person who doesn't know C very likely doesn't know how OS works, what architecture layers are behind the software he uses every day. He just knows somehow he wants to learn C, but doesn't really understand what C is, yet he knows that virtually everything is written in C, and "everything" usually doesn't run in terminal, but processes and produces sound, images, video, can have GUI, use some external devices, run in parallel, run on GPU. Also, it's pretty obvious (especially if you've used some language like Python already) that nobody writes everything from scratch these days, but there're many libraries that proved to be useful. And stuff like branching and cycles seems to be pretty obvious even for somebody without coding experience, as far as I can judge from what I've seen so far. Yet we have plenty books that spends 20 pages to explain "if" keyword and mentions every function in standard library (why?! it's 2014, people, we have cplusplus.com now!)and covers nothing in sense of what useful libraries are out there, what are these domains where you still should use C today (because feet to meter converter shouldn't be written in C today and you probably should choose Python if there's no specific reason to use C), what tools to use for testing and debugging and such. And while it can be justified for K&R (jeez, how old is that book!) it's just ridiculous that book that has "Modern" (well, it was 2008, but still…) in it's title covers almost nothing of what person who wants to program in C should know today. Worse, you'll see that only after reading these 800+ pages. "C the Hard Way" is a little bit better, but still not as good as this one. This one also isn't perfect, but is the best of what I've seen so far.
- DSMan195276 13y agoAdmittedly, while I'm interested to look at this book, it really looks to me like you should come in with at least a basic knowledge of C. The book appears to hold your hand through most of what goes on to create a basic Lisp-like language, but it really jumps fairly quickly over the basic C stuff at the beginning so you can get to the coding. That may actually be fine for you if you already have a basic C knowledge though.
- krick 13y ago> it really jumps fairly quickly over the basic C stuff at the beginning In fact, for me it seems to be the best thing about this book. It mentions everything you need to hear once to be able to use search engine and clarify anything you don't understand. So help yourself! You don't know syntax of "switch" statement? Google it (or duckduckgo, or whatever)! You don't know how to use printf? You've been shown the way to cplusplus.com already, take your time and find out everything you want to know about that function. Then come back for a new piece of information to think about. The only two things I guess are missing is "make" (I'd mention it from the start to help everybody save some time, with gdb and valgrind) and a little bit more information about pointers from the very beginning, because searching for help about "free" function will be no good if you don't know about stack/heap allocations.
- fsloth 13y agoLike others, I would suggest K&R. Perhaps after that, Lourdon's "Mastering algorithms with C". I've found that structuring any program around well understood datastructures and keeping it KISS after that takes you a very long way. Also applies to C. Like others have commented, stylistically the code in the linked book is perhaps not the best place to learn the best conventions for C. But! Writing an interpreter gives a huge kick and reading other peoples code is always nice. For real world projects, it's not a bad idea to implement your own memory manager (even if it's only a wrapper for malloc and free). For real world interpreters Lua (www.lua.org) is written in C, is quite widely used and is not too large - if interpreters are your interest. If you are into lisps Structure and Interpretation of Computer Programs http://mitpress.mit.edu/sicp/full-text/book/book.html http://mitpress.mit.edu/sicp/full-text/book/book.html contains a the instructions for writing a lisp interpreter in any language.
- sanxiyn 13y agoI disagree with recommendation of Lua. Lua is a production-grade interpreter, and a production-grade interpreter is usually not a good educational material for those "interested in interpreters". In particular, Lua uses no intermediate representation (there is no Lua AST!), which makes its compiler portion a quite confusing read. Its interpreter portion is no less confusing, being a register VM with a register window scheme and a non-recursive eval using goto and a separate call stack. Do not be fooled by "not too large" aspect. Lua is worth studying, but it is definitely not a beginner material.
- yk 13y agoI was one of the beta readers. The book makes quite a different trade off from most other beginner C books. Most other books follow the K&R model of short examples and a lot of detail on the topic in question, while Build your own Lisp is just one project. So you actually see how the parts fit together. I would think that either way you can learn C. Which way is better for you depends if you are more motivated by going through one long project, or if you prefer to have many small ones.
- visarga 13y agoI think it's better at teaching Lisp.
- quantabytes 13y agoYour Bitcoin and Dogecoin addresses are mixed up. EDIT: Fixed now.
- tomp 13y agoIn the last chapter, Bonus Projects, the author mentions Static Typing & type systems. If anyone's interested in learning more: I've implemented a few simple implementations of basic (and not so basic) type systems[1]. Currently, only 3 type systems are finished (Hindley Milner's Algorithm W, and Daan Leijen's extensible rows and first-class polymorphism), while gradual typing is almost done (based on [2], in branch 'dev'). [1] https://github.com/tomprimozic/type-systems https://github.com/tomprimozic/type-systems [2] Jeremy G. Siek, Manish Vachharajani - Gradual Typing with Unication-based Inference - http://ecee.colorado.edu/~siek/dls08igtlc.pdf http://ecee.colorado.edu/~siek/dls08igtlc.pdf
- jnbiche 13y agoOh wow! This is extremely useful, thank you. I've been wanting to develop my own statically-typed language, but almost all tutorials on the web are for dynamic languages with little mention given to type systems. I've already started a toy dynamically-typed language, but the step up from that to a static language seems significant, particularly given the dearth of information I can find on the web (aside from dense academic papers). I know the dragon book probably covers this, but I can't justify spending 130 USD on a book at the moment. And I'm working in OCaml, so this is perfect. Please consider putting out a donation link so people can support your work (Bitcoin would be most convenient for me, but I'll definitely try to donate regardless). Also, some kind of open source license would be great (MIT or BSD, maybe?).
- m_mueller 13y agoSomething that might be useful for you: I've heard a talk where the speaker described how F# allows defining one's own type system as an input to the compiler. The language is apparently very extendible this way. It's also open source but I can't find information about its license just now. If I were to build a custom type system that's probably where I'd start to look at, even though I'm not a .NET developer.
- jnbiche 13y agoHmm, maybe he was talking about type providers? These let you "customize" F# (kind of like macros) but not really implement a new language. But I'd definitely be interested in that talk if you can remember the name of the speaker or the venue/conference so I can try to Google it.
- unwind 13y agoI always find it so hard to help out proof-reading code for causes like this. Often, the code is more complicated than I find reasonable, while omitting things that make a lot of sense in "real" code, and it's very hard to know as an outside reader what the exact motivation for each decision was, by the author. A few such things that caused me to WTF: The initial few examples use a pointlessly static and global line buffer, instead of declaring the line buffer where it's being used. There is hardly any const in the code, even for cases where it obviously should (to me) be used, i.e. for variables that are never written once given their initial value. A magic number (the buffer size 2048) is repeated in the code, and even encoded into a comment, instead of just using "sizeof buffer". I do think I found an actual bug (on http://www.buildyourownlisp.com/chapter4_interactive_prompt); http://www.buildyourownlisp.com/chapter4_interactive_prompt)... the readline() implementation ignores its prompt argument and uses a hardcoded string, instead. The same function also does strcpy() followed by using strlen() to truncate the string it just copied; that really doesn't sit well with me.
- DSMan195276 13y agoI would agree, like all code this author definitely has a few quirks about how they write their C code, and I think all of your criticisms are valid. Their readline implementation is definitely sloppy, but they also just throw it in there without really talking about it. Adding to the readline issue, they definitely should have const'd the strings for readline and add_history. It's not just good practice, in this case it'd be required to conform to how readline's declaration is. I'm surprised they don't get warnings about passing a const char * into a char . Also, talking about the strcpy() and strlen(), the catch there is that it's actually removing the '\n' from fgets, it's not actually trying to terminate the string. That said, they should have just saved the strlen(buffer) result in a size_t and then used it later. The real function should look something like this: /* Fake readline function */ char* readline(const char* prompt) { fputs(prompt, stdout); fgets(buffer, sizeof buffer, stdin); size_t bufsiz = strlen(buffer); char* cpy = malloc(bufsiz + 1); strcpy(cpy, buffer); cpy[bufsiz - 1] = '\0'; return cpy; }
- unwind 13y ago
- arcatek 13y agoPL101[1], from Nathan's University, is also a pretty good way to learn the basics of programming language compilers. [1] http://nathansuniversity.com/ http://nathansuniversity.com/
- swah 13y agoWould tcc be good enough a compiler for this? Its very easy to install on Windows compared to Mingw/cygwin etc.
- sanxiyn 13y agoYes.
- pjmlp 13y agoPlease don't. Rather pick something like "Compiler Construction" from Niklaus Wirth and learn how to write compilers using memory safe system programming languages. http://www.ethoberon.ethz.ch/WirthPubl/CBEAll.pdf http://www.ethoberon.ethz.ch/WirthPubl/CBEAll.pdf
- orangeduck 13y agoI wrote this book over several months. It took a few days to get the courage to share it online. It probably took you about 20 seconds to not read my book, dismiss it, and post a comment telling other to do the same. If you think an alternative is better that's fine, but how about you take an extra 20 seconds to think about the situation next time you are going post a comment.
- zenlikethat 13y agoOP, I hear you on this one and commend you for sticking it to the trolls. For what it's worth, I LOVE the book and think you rock for making it.
- karuth 13y agoI had the time to read a good portion of this book. Really well written. I hope some of the negative comments don't discourage you from sharing your work next time around. I learnt something useful this time.
- pjmlp 13y agoSorry but I think the world is better server by younger generations learning that C is not the only way to do systems programming and there are better, safer, alternatives.
- Iftheshoefits 13y agoThe person you're responding to has a history of hating on C around here. I wouldn't take what he wrote personally (easier said than done, I know). That said, I offer the following: Almost any language can be (ab)used in an "unsafe" manner. Conversely, it is entirely possible to create elegant, efficient, and safe code using C, and there is no particular reason to not use C for this project. In fact, C is marvelous in its simplicity and is an excellent candidate for it. On a scale of 1 to 10 I'd put my skill with C++ around a 6 or 7. For C I'd go lower, around 3 or 4. I appreciate the work you put into this, and I intend to read your book to help me improve my skills with C. So thanks for your effort.
- workingbrains 13y agonice one i like it
- jameshk 13y agoThis is awesome, I will certainly be using this to learn more Lisp.
- SneakerXZ 13y agoDoes it use a generator to generate lexer and parser or author is suggesting to write them manually?
- mcmillhj 13y agoI imagine if the goal is to design from the ground up, you wouldn't be using a generator.
- orangeduck 13y agoAuthor here. A parser combinator library is used to do the parsing.
- SneakerXZ 13y agoToo bad, always everyone who teaches how to write a programming language uses generators but actual production programming languages never use them. Except of a few langugages. I wonder why...
- kevinnk 13y agoIt's hard to generate high quality error messages with current generators unfortunately. More common nowadays is building first with a generator and switching to recursive decent when it becomes too unwieldy.
- hamburglar 13y agoMy one criticism is that it's a fairly big leap from learning C from ground zero to being a client of a complex, high-level library like mpc. I feel like the moment you hit the call to mpca_lang, anyone who really was learning C at the beginning shifted from "learning C" mode to "copy and paste C code I don't understand" mode.
- JasonFruit 13y agoIf I decided to work through this, and thought it was really good, I'd be unable to make a donation because I don't dabble in cryptocurrencies. Why not make donating "real" money possible, as well?
- orangeduck 13y agoThanks for the suggestion. I'll open this option up if possible.
- jafaku 13y agoIt's called "fiat", not "real".
- JasonFruit 13y agoNot all non-cryptocurrencies are fiat currency.
- jafaku 13y agoI doubt he was talking about precious metals...
- pseut 13y agoFWIW, cryptocurrencies are far more fiat than dollars. You can pay taxes in dollars, for example, so they're not even a pure fiat currency.
- gmfawcett 13y agoIf you're interested in this, you might also enjoy "Write yourself a Scheme in 48 hours." It uses Haskell rather than C as the implementation language. https://en.wikibooks.org/wiki/Write_Yourself_a_Scheme_in_48_Hours https://en.wikibooks.org/wiki/Write_Yourself_a_Scheme_in_48_...
- rasur 13y agoI am working through this slowly - it is excellent (although I find myself referring to the Haskell report tutorial too, when I find something that needs further clarification). A word of warning - the pdf version is not as accurate as the html version. Prepare for some head scratching if you use the pdf.
- agumonkey 13y agoWYASI48 is mentioned as an inspiration somewhere IIRC
- sanxiyn 13y agoThis is a good stuff. 4 years ago, I wrote a Lisp in 500 lines of C in one day after finishing SICP. Typing it out did made what I learned more concrete. https://gist.github.com/sanxiyn/523967 https://gist.github.com/sanxiyn/523967
- ilbe 13y agoWow, very timely, yesterday I needed to brush up on C and was wondering how I would go about it. Thanks. Very minor note: the link to "Learn C the Hard Way" on the faq page links back to the faq page.
- orangeduck 13y agoThanks. I've fixed the link.
- osho 13y agoCan i get an pdf/epub version of this book?
- zafka 13y agoVery Cool, I don't want to spend much time here now as I am at work......, but I love the concept. I have been using C for almost twenty years, and I think this would be a fun check.
- crnixon 13y agoIs the source of the text on GitHub or elsewhere? I'd love to send pull requests for some of the things mentioned in these comments, like magic numbers not being in constants.
- orangeduck 13y agoHi crnxion. The source can be found here: https://github.com/orangeduck/BuildYourOwnLisp https://github.com/orangeduck/BuildYourOwnLisp I welcome corrections/edits.
- lispm 13y agoFine to implement something. But I would wish that the language implemented actually looks like Lisp or Scheme. Currently this claims to be Lisp, but it is some strange version of it. Using a Scheme or Lisp has a lot of advantages: * one can compare it with other actually working implementations * there is already a wealth of material to learn from or where code could be reused * many books exist * the language actually has already got some thought A good example is the book on Scheme 9: http://www.t3x.org/s9book/index.html http://www.t3x.org/s9book/index.html
- kyllo 13y agoThanks for sharing, this is really helping me to understand in a little more detail how compilers work. And the doge example gave me a good chuckle.
- donniezazen 13y agoI am new to programming. What is it so special about Lisp that I keep hearing about it in Hacker's News (often in Machine Learning and from old programmers)?
- agentultra 13y agoYou will get different answers from different people. There doesn't appear to be any commonly accepted universal truths in Lisp (otherwise we'd all be programming in some variant of it by now). However there are plenty of good ideas which many more popular languages have adopted. What made it special for me was discovering the link between symbolic computing and the lambda calculus. The kernel at the center of every Lisp is a substrate upon which languages are built. eval knows nothing about your program but can read some Lisp forms and turn itself into a machine that can execute it. This is immensely powerful. From a shockingly small number or primitives you could build, theoretically, any language you need. The more superficial qualities, for me, are a distinct lack of frivolous, obfuscating syntax; its uniformity; and its direct representation. I don't have to maintain an exhaustive mental mapping of syntactic digraphs and operators, I don't have to remember precedence rules, I don't have to remember the grammatical distinctions between expressions and statements, and I certainly don't have to maintain a running interpreter/compiler in my head. Armed with a simplified mental model of the lambda calculus such as the substitution method is enough to work out what any program is doing (and indeed due to the nature of Lisps is also easy to interactively verify). Every other language I've worked with requires memorizing a laundry list of special cases and weird rules (ie: how array and pointer parameters are changed by the compiler in C, precedence rules as mentioned, etc) imposed for efficiency's sake and often maligned with good engineering practices. Some strange monkey-brained part of me fools myself into believing I am becoming a better programmer when I pollute my mind with these things... but I've learned over the years that it's just a trick. The ideas are important and the implementation is just the painful cost we pay to make them reality. Lisp just happens to have the least cognitive load in my case.
- platz 13y agoI agree with everything, though the idea of least cognitive load I think only runs skin deep (syntax). This helpful for small scripts which need to be scanned quickly, but anything non-trivial will already have a significant layer of abstraction which takes time to parse. Lisp people love their macros. Clojure has fancy data structures and control flow. It will take time to understand these things whether its in lisp or sandskrit.
- sgy 13y agoOf course C is not the only option, and perhaps not an option at all for newbies. JavaCC can be a good medium to build your own language too. They recently added the ability to generate C/C++ code (https://java.net/projects/javacc https://java.net/projects/javacc) Is there any tree building capabilities using C?
- notastartup 13y agoUsing this guide, is it possible to create a programming language in a non-English language?
- Jemaclus 13y agoThe basic principles apply whether you're using English or not. You should theoretically be able to write a programming language in any real-world language you want.
- matt_heimer 13y agoThere is also a pretty good Compilers MOOC going on right now https://class.coursera.org/compilers/lecture/preview https://class.coursera.org/compilers/lecture/preview
- blt 13y agoI dislike the use of a parser generator libary. If it were any other language, sure. But Lisp is so easy to parse. Writing parsers is fun, and it would be a good exercise. I applaud you for wanting to teach beginners how to install libraries, but this seems like the wrong choice. Props for mentioning conditional compilation early. It's underrepresented in books but essential for real life.
- deleted 13y ago[deleted]
- yk 13y agoYou should perhaps submit it to r/C_Programming/ since you looked there for beta readers.
- JoelMcCracken 13y agoCan anyone briefly explain what makes the lisp that the author develops unique?
- akkartik 13y agoIn similar vein to tomp's comment: if someone's interested in the bonus project of implementing macros, I've implemented a simple lisp with first class macros (fexprs): http://github.com/akkartik/wart http://github.com/akkartik/wart. Moreover, you can write anonymous macros out of more primitive constructs. Over time it's accumulated other features: http://akkartik.name/post/wart http://akkartik.name/post/wart. But hopefully it's still easy to understand, because it has thorough unit tests. If you have a question about some line of code you can try changing it. Seeing what tests break is a great way to get feedback as you learn, in my experience.
- z3phyr 13y agoThere is one excellent book I would recommend to everybody -> http://en.wikibooks.org/wiki/Write_Yourself_a_Scheme_in_48_Hours http://en.wikibooks.org/wiki/Write_Yourself_a_Scheme_in_48_H...
- skittles 13y agoAnyone know why clang on mac os x doesn't know about edit/history.h? The line editing portion of the book requires it.
- exef 13y agoYou can try to install with MacPorts Readline with terminal command: sudo portu install readline And after that you include with #include <readline/read line.h> #include <readline/history.h>
- jdp 13y agoThat would be for libedit: http://thrysoee.dk/editline/ http://thrysoee.dk/editline/
- jdstraughan 13y agoI've installed this, but I still get this error: fatal error: 'editline/history.h' file not found Any advice would be greatly appreciated.
- melonman 13y agoAre you using Mavericks? You need to import the library using #include <histedit.h>. Other problem is that the code won't work with this library. You need to rework it using the following example: http://www.cs.utah.edu/~bigler/code/libedit.html http://www.cs.utah.edu/~bigler/code/libedit.html There's a lot more to set up and tear down when using the Mavericks' editline; it's not so user-friendly for a beginner as the code in the example.
- elwell 13y agoThis looks really cool. I wish I had the time to read it.
- aidenn0 13y agoOut of curiosity, what are you doing with your time that is currently more important than reading it?
- elwell 13y agoWorking on my startup, a social photo/video aggregator that organizes by event, and has B2C and B2B aspects: http://wesawit.com http://wesawit.com Any feedback is appreciated.
- visarga 13y agoIt' slow. DOM loaded in 59 seconds. Content loaded in 180 seconds and weighs 12MB It's also downloading mp4 files in the background. .... 4 minutes passed and it is still working on the banner-video.mp4 Also, it has problems with scrolling (freezing). I use a MacBook Air 11'' from 2012.
- zenlikethat 13y agoI get DOMContentLoaded in ~1.41 seconds on from here, but the background video downloading is worrisome. Grandparent, currently your website has slurped 31.3 MB (and counting!) over the wire for a simple landing page. What gives man? Seems that everything which should be setup on your page already, is.
- wedesoft 13y agoI was trying to implement an interpreter for a minimal (lazy) language in C [1]. It uses Church encoding and other encodings. E.g. here are the definitions of false, true, identity, and pair: f_ = proc_self(lambda(v0)); t_ = proc(lambda(v1), f()); id_ = proc(v0, f()); pair_ = lambda3(op_if(v0, v1, v2)); For the moment I gave up on it though but maybe it might serve as inspiration ;) [1] https://github.com/wedesoft/blc/blob/master/src/x.c#651 https://github.com/wedesoft/blc/blob/master/src/x.c#651
- EdwardDiego 13y agoIf the author is reading this, thank you very much - I've always wanted to experiment with C, but never had a project to use it on. Writing a Lisp interpreter (compiler?) is not one that occurred to me, but it definitely interests me. Cheers for your hard work. :)
- anateus 13y agoSounds like this may subvert Greenspun's Tenth Rule: "Any sufficiently complicated C or Fortran program contains an ad hoc, informally-specified, bug-ridden, slow implementation of half of Common Lisp." http://en.wikipedia.org/wiki/Greenspun's_tenth_rule http://en.wikipedia.org/wiki/Greenspun's_tenth_rule
- acqq 13y agoActually the project depends on the library which claims to implement the named rule: https://github.com/orangeduck/mpc https://github.com/orangeduck/mpc
- mcescalante 13y agoI've already programmed quite a bit of C and C++, and this seems like a great read + resource. I'd be curious to know how a non-developer or somebody coming from something like Ruby or Python that had never developed C felt about this.
- adamcanady 13y agoAt my undergrad institution, we have a class that does a project very similar to this. I recently completed the class and project and have a bit of advice for anyone looking to take up this challenge on their own. First off, a small note: our project used C to implement Scheme (a lisp dialect), so it's similar but not exactly the same as this. I'd recommend starting off with reading about the principles and coming up with a solution to each of the problems on your own instead of following a specific pattern as outlined in the book. For example, in our project, we decided to learn about the C basics, then just figure out how to make it 'act' like Scheme if given an input. Eventually, we thought of doing everything in a linked-list style to make organization and recursion easier and more natural, but coming to this conclusion on our own was very helpful. Another thing is valgrind. As far as I could find, the text only mentions valgrind in one paragraph, but it's an excellent tool to check for memory leaks and errors. Also, as mentioned in the book, a bonus is adding in GC. This turns out to be a pretty easy and a fun exploration of the different techniques available if you try a couple out for performance. Our code in case you're interested: https://bitbucket.org/adamcanady/cs251_interpreter/src https://bitbucket.org/adamcanady/cs251_interpreter/src
- rui314 13y agoIf you are interested in this, you may find one of my Lisp implementation interesting too. It's implemented less than 1k lines of heavily-commented C, but it even supports a macro system and copying GC in addition to the common features you would usually see in small Lisps. https://github.com/rui314/minilisp https://github.com/rui314/minilisp
- NAFV_P 13y ago> Cat • cannot speak or program A caption for a picture from chapter 5, preceding a look at the grammar of Doge - DogeLisp anyone?
- halayli 13y agolval* v = malloc(sizeof(lval)); v->type = LVAL_QEXPR; For goodness sake, when teaching C, make sure to check alloc's return values.
- SixSigma 13y agoOn the compiler course taught by Brucee (Bruce Ellis - one half of Mark V. Shaney - the other half being Rob Pike) he got you to do two projects : write a Lisp implementation in C, and a C compiler in Lisp. Most instructive. If you have an HP printer with a Postscript renderer and you can get an image of it, you can find a digitised photograph of him too :)
- pflanze 13y agoI've just begun starting a group to create a Scheme implementation from scratch in London (UK). If you're already somewhat proficient in Lisp/Scheme and interested in participating, see [1] for further info and send me a message through meetup.com or through the link on my contact page. [1] http://www.meetup.com/London-SICP-Study-Group/messages/boards/thread/43167122/#118559022 http://www.meetup.com/London-SICP-Study-Group/messages/board...
- stantona 13y agoThis is extremely cool, for someone with some C experience but wants to dig into writing a lisp.
- mkhattab 13y agoThank you for writing this and sharing it for the common good. I've been wanting to relearn C since I've switched to Python for work. Hopefully this book will be good practice because I've been wanting to implement a Lisp interpreter on a micro controller for quite sometime. I have plenty of PIC18F4550 micro controllers lying around. Also, I liked the cat pictures and hope you'll add more of those in the next edition, perhaps.
- codemonkeymike 13y agoI had made a lisp interpreter using this book I found in my schools library. http://www.amazon.com/Data-Structures-Advanced-Approach-Using/dp/0131988476/ref=sr_1_1?ie=UTF8&qid=1396656827&sr=8-1&keywords=advanced+data+structures+in+c http://www.amazon.com/Data-Structures-Advanced-Approach-Usin...
- gregburd 13y agoMy favorite small and understandable implementation of Lisp in C is by Ian Piumarta. [1] [1] http://piumarta.com/software/lysp/ http://piumarta.com/software/lysp/
- userbinator 13y agoSomeone needs to make a complementary "Learn Lisp and build your own C."