How To Learn Lisp
March 3rd, 2008 | by Peter |In the spirit of my last post, I decided to turn one of my favorite long comments on Hacker News into a blog post in the hopes that someone would find it useful. There was a good discussion last week about how to learn Lisp, and since I was a little late to the thread, most of the things I wanted to say had already been said. So, in an effort to pull it all together, I made a nice long summary comment, which is reproduced and cleaned up below.
Before I started learning Lisp, I have (in reverse chronological order) worked with .Net for several years, disliked C++ in college, loved Pascal in high school, dabbled in (Assembly?) programming my TI-82 graphing calculator, and started with Hypercard. Here’s my advice based on ~1 year of part-time Lisp education.
- To learn “lispiness”, functional programming, and get a feel for the computational approach to programming, read The Little Schemer and The Seasoned Schemer. Also, use the resources for the MIT Intro course Structure and Interpretation of Computer Programs. Watch the video lectures (30 well spent hours) and if you’re ambitions, read the book (Amazon). Doing these things will help keep you from writing PHP in Lisp.
- To put it into practical perspective and learn the nuts and bolts of modern common Lisp, read Practical Common Lisp (Amazon).
- If you read PCL, you will run into Emacs and SLIME (the generally preferred [NO FLAMES, PLEASE. I KNOW VI IS AWESOME TOO] open source way to edit Lisp files). I wrote some resources to help with that:
- I’m surprised no one has mentioned PAIP (Peter Norvig’s Paradigms of Artificial Intelligence Programming). Probably because there’s no free version online and it’s a pricey book. I got it for myself for Christmas and it’s well worth the price. It’s half AI book, half tutorial on Lisp programming and Lisp style. It’s a good read with lots of example programs written in good Lisp Style.
There are three hurdles people usually run into when learning Lisp:
- The language looks different - this goes away with practice and familiarity. It starts looking normal fast. The parentheses are a bit tough to manage unless you use a capable editor, which leads to:
- Emacs is different - really powerful, fun to use, but it takes investment in learning. It’s really tempting to quit when starting, but worth getting over the hump. Once you do that:
- The way of thinking is different in Lisp - Lisp seems a little awkward to use until you get (don’t need to master them, just get the idea) the following ideas: 1) code can be manipulated as data because the syntax is so simple, 2) creating your own syntax (using macros - code that writes code) means that you can express your program in a way that closely matches the problem you’re trying to solve. Some good articles to help get these points are:
Don’t worry if you don’t get these “big picture” things at first, they click at some point and everything makes a lot more sense. You can speed that up by putting a lot more Lisp in your head in the meantime.
Does anyone have any more tips on learning Lisp?
Also: read comments on this post at comp.lang.lisp, reddit, Hacker News





24 Responses to “How To Learn Lisp”
By TheGZeus on Mar 4, 2008 | Reply
Hmm, I understand that Emacs is the preferred method of working with, and the fact that it’s core is a text editor makes the next step “HEY!!! What about VI!!!???” but why does NO ONE seem to know about Eclipse/Cusp?
I’d have been actually DOING REAL PROGRAMMING by now if someone had told me about this sooner…
I started out using AppleLogo to draw weird images, fractals and weird recursions on a //c and did basically nothing for 12+ years because no one ever bothered to tell me that programming is for people, not ‘programmers.’
Yes, Cusp can do everything SLIME can. It can do more, from what I can tell. Granted, you’ll need to know how to extend it if you want to…
By Peter on Mar 4, 2008 | Reply
True, cusp/eclipse is sort of the unwanted stepchild of Lisp editing, because it’s fairly new, it’s not part of a holy war, and the cool kids (Yegge et al) have nothing nice to say about Eclipse. Having said that, it’s probably an easier transition, especially coming from Java or .Net/Visual Studio.
I decided to go with Emacs over Eclipse because while Eclipse would probably make me more productive in the short run, I was jealous of the old hat Emacs guys and the great stories they tell. I’m looking 1-10 years in the future and I think that over that period, the time I spend learning and extending Emacs will payoff more. That’s one luxury a day job provides!
By Phil on Mar 4, 2008 | Reply
As someone mentioned CUSP, I thought I’d mention my own pet project ABLE (http://phil.nullable.eu/). A lot of newbies have told me that it helped them to start learning CL where they would otherwise have been put off by Emacs. Of course, you can always move on to SLIME at a later date when you’re comfortable with the language.
By she on Mar 4, 2008 | Reply
To be honest, we are all kinda a victim to the vim vs emacs wars in the past.
It was a reason why Eclipse, as slow and bloated as it may be, won.
I dont like Eclipse but I endorse it as a cross-plattform solution with a GUI. Not everyone wants to learn either vim or emacs (i gave up on vim after 2 years, and emacs i gave up after 3 weeks. I simply felt that the few things I’d really need are scriptable tasks which shouldnt be specific to any editor anyway…)
By TheGZeus on Mar 4, 2008 | Reply
The reason I mention Cusp everywhere is the main complaint I see from people who don’t com off as (pardon my french) assholes is NOT the syntax, it’s the fact that you’re stuck with Emacs or you’re up the creek without a paddle.
Not only that, but people who ask why often get something akin to “why would you want anything else? Emacs can…” response.
I know a professional programmer who’s done professorships and contract work for the US government. He uses Vi for quick little scripts, but anything that requires alot of work, he uses Eclipse or another major IDE. I wish I could remember the other IDE. He uses a Mac, but it’s not Xcode, as I think he’s doing mainly cross-platform…not that you can’t do that in Xcode…maybe it WAS Xcode… I digress.
Books on Eclipse are often the same thickness as the O’Reilly Emacs book, and cover a large portion of basic Java programming as well.
Emacs is a powerful program, but it’s, at the least, intimidating the a beginner (like me) and we need more beginners in the Lisp community. Much like Freemasonry (of which I was a member until I became an atheist and left) it gives off the impression as being ‘uncool’ or ‘a bunch of weird old guys.’ People may rightfully dislike the idea of using ‘cool’ as a selling point. The kids who gave me shit in high school were ‘cool’ at the time (they push shopping carts and never smile now), but the sad fact is that if you get 1% more CL users that way you might get another 2% who now have confidence in the libraries etc.
Communities are subject to flock/pack/school(fish) mentalities, to a degree. Might as well get as many users as possible.
Again, I’m not here to bash Emacs (though I’m a kate/vim user for the most part), I’m just suggesting that we start promoting the use of Cusp/Eclipse to beginners and to people new to the language. I know someone who’s a great programmer, he used to program physical modeling of the oceans in C++. When I told him the main IDE for Common Lisp was Emacs he looked like I’d told him my family tree led back to a real tree.
Think of it this way: What’s worse, losing one person to the cult of emacs, or losing both that and a potential Lisper?
By Anon on Mar 4, 2008 | Reply
I’ve found the best way to learn is to minimize the time spent on the computer. Try solving a problem using a pencil, spiral notebook, and reference book.
Writing and revising on paper allows more time to think, and the notebook lets you to flip between sections easily and resume after interruptions. It may take 20 pages of writing to get 2 pages of finished code. Then when you’re finished or stuck, test it or search the web.
After tackling some projects this way, you’ll have more interest and comfort to explore how to design it better next time or how to be more productive with new editors.
By fendres on Mar 4, 2008 | Reply
My problem ist not learning Lisp. It is easy to understand. My problem with lisp is, that there seems to be no standard way. E.g. first I have to decide which lisp implementation to use. And if I want to solve complex problems in an efficient way, I need good libraries to do that. I do not want to reimplement linear algebra functionality, gaussian processes, computer vision algorithms, a visualy pleasing gui that fits nicely into my desktop environment and a lot of things more. So I would have to search everytime for hours to find something suitable (if at all).
Maybe here popular languages have an unfair advantage, because there are more people working on libraries and more people using it (which makes it easier to “follow the herd” to the good ones).
But my problem about lisp is definitely not the syntax or the programming environment. It is getting productive in a programming area where I have to rely on other peoples code. And keep in mind, that even though I learned the syntax of lisp and can write a program, I still lack the experience solving all the minor issues arising with libraries and implementations.
By joe on Mar 4, 2008 | Reply
I went through the first 200 pages of PCL and discovered I couldn’t make minor changes to the sample code without blowing everything up. The problem was the weird semantics of macros, which look just like functions. I couldn’t just substitute things the way I would if it was all functions.
Here’s one thing I ran into:
CL-USER> (setf (slot-value *account* ‘balance) 1000)
1000
CL-USER> (defun fbalance (acct) (slot-value acct ‘balance))
FBALANCE
CL-USER> (setf (fbalance *account*) 1000)
; Evaluation aborted
So basically, you can’t just look at code using unfamiliar macros, and know by looking at it how you can fiddle with it. You have to learn the libraries just to understand the basic semantics of the code.
This wasn’t spelled out in PCL at all. So here’s what I think we need: some kind of tutorial that gives you the basics, and then pretty early on spells out in detail what you can and can’t do with various common macros, and why.
By Telman Yusupov on Mar 4, 2008 | Reply
Nice summary, thanks Peter!
I took a slightly different book path to learning Lisp:
1. Read “Gentle Introduction to Symbolic Computation” by Dave Touretzky. This is one of the best introductory books for computer programming in any language (if not the best IMHO). It explains Common Lisp in a very clear way, it has a lot of exercises (with answers!) and several programming projects of higher levels of difficulty (with answers too!). The books is available for download from the author’s site for free.
2. Read Practical Common Lisp by Peter Seibel. After Touretzky’s book this one was much easier to go through, as I had a firm grasp on the fundamental concepts.
3. Paul Graham’s “ANSI Common Lisp” is a good one to finish the introductory book round. No new concepts after PCL and it took me some time to get used to PG’s programming style.
PAIP and “On Lisp” are on my to-do list.
To make the learning curve a little flatter and concentrate just on Common Lisp instead of going through Emacs AND Lisp at the same time, I’ve downloaded learning edition of LispWorks. It comes with a nice IDE on all platforms (I’m on Mac) that takes only several minutes to figure out.
Using LispWorks allowed me to go through Touretzky’s book without struggling with Emacs. Now I switched to using Aquamacs (Mac friendly version of Emacs) with Slime on top of Allegro (as I’m still learning, will go to SBCL later on).
Emacs is really powerful! I also use it for coding in other languages now.
My 2c…
Cheers,
Telman
By Abhijith on Mar 4, 2008 | Reply
Gentle Introduction to Symbolic Computation is a good book for people who are new to programming or even functional programming for that matter.
By Peter on Mar 4, 2008 | Reply
Nice! This is what I was hoping to get - angry people, skeptical people, enthusiastic people, frustrated people. Big thanks to whoever put this on reddit - I didn’t think it would resonate so much!
Phil, She, TheGZeus - I think I’ve seen the error of my ways. I’m far enough over the Emacs hump that I’ll stick with it, but at some point I’ll give Eclipse/Cusp a try to see where it fits on the continuum between Visual Studio and Emacs. I will also definitely recommend it to new users looking to tackle one thing at a time. Zeus, I definitely agree with you about the importance of increasing the user base. I’ve got a big post in me about that topic that I’ll write someday.
fendres - That is definitely a problem, one that I have some ideas about and have a bit of a plan for. I think the tipping point will be when one of the open source CL implementations works on Windows/Linux/Mac, and includes full threads and unicode support (I’m keeping an eye on the experimental SBCL Windows port). Once one of the implementations hits that point, it will become the de facto default and break down one big barrier for new users. The other important ingredient will be the right documentation, which is where I hope to make a contribution.
joe - OnLisp (Paul Graham’s second book) spends ~15 chapters on macros. He wrote it because in every other text, macros got only cursory treatment. It’s a free download in .ps or .pdf at http://www.paulgraham.com/onlisp.html or it’s online at http://www.bookshelf.jp/texi/onlisp/onlisp.html
Telman - Several people have mentioned GISC. I’ll have to take a look at it. It’s also a free download at http://www.cs.cmu.edu/~dst/LispBook/ so it should get more views (as opposed to PAIP). I’ll mention it more often and try to introduce its acronym (GISC) into the lexicon. Worked for SICP, AIMA, PAIP, and PCL!
By Sesh on Mar 4, 2008 | Reply
“will keep you from writing PHP in LISP” - could you please explain this. My english is not that good.
By Peter on Mar 4, 2008 | Reply
Sesh - There’s a saying that “You can write Fortran in any language.” (see http://www.codinghorror.com/blog/archives/000272.html ) This just means that learning the syntax of a language doesn’t mean much, you have to learn the new idioms and patterns that a new language lets you use. In the case of Lisp, this would be code-as-data, recursion, functional programming, symbolic computation, syntactic abstraction, etc. You could take a PHP (or VB, C, Pascal, etc) program and pretty much translate it verbatim into Lisp, but you’d be missing out on the best features that Lisp has to offer. Any new language you learn should change and expand the way you think about programming.
By TheGZeus on Mar 4, 2008 | Reply
I looked back at my second post and… I come off as a dick, I think.
Just thought I’d apologise for being just kinda rude in general.
Not that I didn’t mean what I said, it’s just not all of it was relevant, and that can sound accusatory and ignorant.
…also ling-winded.
…I’ll be quiet.
By Peter on Mar 4, 2008 | Reply
TheGZeus - Maybe a little crude, but I’m glad you said what you said. And about the long windedness, remember that this post was a comment somewhere else and I just cleaned up the links!
By koolmoe on Mar 5, 2008 | Reply
+1 for GISC.
Having used Emacs for LaTeX editing in grad school, I personally prefer Emacs over Eclipse/Cusp. I have looked at Cusp, and it seems like it would be useful if I didn’t already know the basic key-bindings to be effective in Emacs.
One of the things I found useful in learning was to attack Project Euler type problems in Lisp. A good resource I found indirectly through lispjobs.wordpress.com were the problems on streamtech’s job board:
http://www.streamtech.nl/site/problem+set
I’m not interested in a job there, but the problems were fun to work on. I actually laughed out loud at how easy it was to solve some of them in Lisp compared to what I would have done in Java.
By John Tobler on Mar 5, 2008 | Reply
The book, Structure and Interpretation of Computer Programs (SICP), recommended above, is available online for free here:
http://mitpress.mit.edu/sicp/full-text/book/book.html
It has been made available in connection with MIT’s OpenCourseware “6.001 Structure and Interpretation of Computer Programs” course:
http://ocw.mit.edu/OcwWeb/Electrical-Engineering-and-Computer-Science/6-001Spring-2005/CourseHome/
It’s free. Yes, it represents a nefarious scheme (pun fully intended) to turn you into an above average programmer. No excuses accepted!
By TheGZeus on Mar 10, 2008 | Reply
http://xahlee.org/emacs/emacs_fun.html [EDIT: Changed to an accessible URL]
I agree with this, but mainly because I live in a persistent irony bubble.
I had planned to post this in my original post, but couldn’t find it. Just came down the Lisp/Scheme/Emacs Pipe.
By Grant Rettke on Apr 3, 2008 | Reply
Folks new to Lisp should try DrScheme.
By Glenn on Apr 23, 2008 | Reply
Another great way to learn SLIME and Emacs, if you use a Mac, is to download and install the Carbon version of Emacs. This is a port of Emacs to the Mac, with a Mac look and feel. It is _very_ nice. SLIME comes packaged by default, and what is really nice is that SLIME is a menu bar entry. You can find the SLIME commands in the menu, along with their short cut keys. I had been putting off learning SLIME/Emacs and going with Eclipse/CUSP (which is also very nice). Now we have 2 great choices.
You can find CUSP for Eclipse at:
http://bitfauna.com/projects/cusp/
and Carbon Emacs at:
http://www.apple.com/downloads/macosx/unix_open_source/carbonemacspackage.html
(or)
Their home page is:
http://homepage.mac.com/zenitani/emacs-e.html
By Daniel Weinreb on May 10, 2008 | Reply
“Practical Common Lisp” by Peter Seibel is great. When we hire new hackers who don’t know Lisp, we just give them that. The other thing to do is find very good Lisp programmers and read their code. Lots and lots of code. Ask the writer questions like “why did you choose to do it this way?” and “what is this construct for?”.
Common Lisp is a lot easier to learn than many people think. Of course, being a virtuoso takes longer, but that’s true in any language.