top | item 25441664

Ask HN: I want to start learning Lisp. Where do I begin?

222 points| priyanshuraj | 5 years ago | reply

There are multiple versions of Lisp. Multiple compilers. What is a good one for someone new to pick?

I use VS Code and Vim. Are they suitable for learning Lisp?

204 comments

order
[+] pixelmonkey|5 years ago|reply
Racket Scheme & SICP is a fun way to start playing, especially if you are into theoretical concepts of CS and programming, like higher order programming and abstraction.

The documentation for Racket is excellent, see e.g.

https://docs.racket-lang.org/quick/index.html

... and many people have created online resources to adapt SICP to Racket, as well as other learning texts. I like Beautiful Racket, e.g.

https://beautifulracket.com/explainer/lists.html

You can use #lang sicp and start playing around with the free online reformatted SICP text here:

http://sarabander.github.io/sicp/

I recommend getting a print copy of SICP, though, and working through the examples in a real DrRacket environment on your computer.

IMO, if you end up going deep in the "lispy" direction after playing with Racket, you'll probably be drawn to Clojure as it is the Lisp with the biggest "production use" community at the moment. So long as you can put up with some JVM warts, it, too, will be a good experience.

[+] masukomi|5 years ago|reply
I have to second this. Racket is absolutely the best place to start. There are great books for beginners, and the documentation is top notch.

it comes with its own editor (Dr. Racket) that does some really helpful things for beginners, like hovering over a variable and seeing lines drawn to where it's being used.

It's not the fastest lisp, but that's ok. It's spectacular for learning and has a huge ecosystem too. My "daily driver" is Chicken Scheme, but i wouldn't recommend it to a beginner. The docs just aren't helpful to newbs (and frequently frustrating to me even though it has one of the better set of docs)

Vim is meh for Lisp & Scheme, and I'm a Vim fan. Emacs is great. If you're a Vim user check out Doom Emacs. It's great for us geeks who love vim but want more power and better lisp support. But... start with Dr. Racket for now.

Others have mentioned the SICP book, and it is good but i wouldn't suggest it as as "how to start with lisp" book. Also, watch the free lectures of the course from MIT. Very good, and make it way easier to work through the book.

[+] estsauver|5 years ago|reply
SICP is also a fantastic book because such a high percentage of all of the interview questions you'll be asked are represented there, but you end up really quite fundamentally understanding the solutions and I think that translates really well into the code people write in interviews.
[+] slgeorge|5 years ago|reply
ClojureScript which targets JavaScript as the host language (https://clojurescript.org/) is a good option on the Clojure side.

ClojureScript is great if you're drawn towards the "production use" side as pixelmonkey said and already have knowledge of the Javascript / Node ecosystem.

[+] coold|5 years ago|reply
Can I read SICP while learning Clojure? Is lisp very different?
[+] mindcrime|5 years ago|reply
There are obviously many possible paths, so I can only really tell you what I've done. I can't say it's necessarily the best approach.

For me, I decided to start with Common Lisp. I installed SBCL, Slime for Emacs, and started working through the book Practical Common Lisp. By and large this seems to be a workable approach, but I will offer up this caveat. The PCL book is very much "project based" in that the author walks you through building a couple of actual applications. This is a Good Thing™ for the most part, but it does mean that you don't necessarily get things in the order you might expect.

There's a part of me that almost wishes I'd started with a book that takes more of an approach of "programming is ultimately sequence, selection and iteration. Here's how you do sequence in Lisp. Here's how you do selection. Here's how you do iteration. Now here's all the Fancy Lisp Stuff™".

The reason I say that, is because if you have at least the primitives for sequence, selection, and iteration (and maybe some I/O) in your mental toolbox, you can start building more or less arbitrary programs. With the PCL book structure you don't get to, for example, iteration, until moderately deep into the book. You do get there of course, but the early parts left me with an uneasy feeling like "geez, I don't even know how to write a loop in this language yet, when am I ever going to be able to just start coding in Lisp on my own?" if that makes sense.

Possibly one could complement PCL with another book, or online materials, but so far I've mostly just been grinding through PCL and haven't looked at any other Lisp books.

HTH.

[+] nemoniac|5 years ago|reply
I wouldn't focus too much on "sequencing, selection, and iteration". That's only the start of it. It's how you think if you're programming Python or Java or C or whatever.

With Lisp you can better think in terms of abstractions. In particular how do you do data abstraction, how do you do functional abstraction (that's the control flow: sequencing selection and iteration) and how do you do syntactic abstraction?

That last one is where Lisp (any Lisp) really comes into its own. It's where you go beyond the expressiveness of those other programming languages. Whether you go with defmacro or define-syntax, it opens up a whole other world.

And the expressiveness here isn't meant to suggest that you can write programs that you can't in other languages (they're all Turing complete) but that you can write new kinds of control flow and scoping constructs so you're not limited to the sequencing selection and iteration that the language provides.

[+] ragnese|5 years ago|reply
This is a bit off-topic, but something you said resonated with me.

> The PCL book is very much "project based" in that the author walks you through building a couple of actual applications. This is a Good Thing™ for the most part, but it does mean that you don't necessarily get things in the order you might expect. > > There's a part of me that almost wishes I'd started with a book that takes more of an approach of "programming is ultimately sequence, selection and iteration. Here's how you do sequence in Lisp. Here's how you do selection. Here's how you do iteration. Now here's all the Fancy Lisp Stuff™".

I feel like I'm in the minority in that I prefer to NOT learn things by just "diving in". I am much more successful when I start from the absolute fundamentals. There are objective pros and cons to either approach, but I suspect the success factor is based on one's personality (or some such).

If you start with the fundamentals, it's hard to know if you have any mastery until you try to do something "real". And then you might get frustrated because nobody taught you, e.g., how to do a network call in this programming language. It's also less rewarding because you can spend hours/days/weeks before actually "doing" anything.

If you start by diving in to a project, it's hard to know if you're doing things "the right way" or if you're just porting over bad habits from some other language you're familiar with. Sure, I got it to work, but is it good, or did I just cement in some bad habits?

The first time I drove a standard transmission car, I didn't stall it a single time. Because I read on the internet for a week about how car transmissions work and the difference between a manual and automatic gearbox. I do the same thing with programming languages. The first thing I want to know is what is the memory model approximately like (everything is a reference, values + references, are allocations cheap or expensive), what is the "philosophy" of the language (everything is an object, function composition is the blessed approach, mutability is bad, types are most/least important), etc. Then I want basic mechanisms: loops, iterators, lists or arrays, threads/futures/coroutines. Etc, etc.

That being said, SICP is kind of nice in that it finds an interesting middle ground where you're definitely learning details of the scheme language (applicative order vs normal order, recursion, etc) while it also feels like the details of the language is not the entire point.

No real point here. Just inspired by your comment and thought I'd share my own experience.

[+] _ph_|5 years ago|reply
Seconded. PCL ist in my eyes one of the best and most "modern" Common Lisp books around. SBCL is probably the best Common LIsp compiler and free on top of that. Paired with Slime and Emacs you have a professional development environment. I use it regularly.
[+] jjav|5 years ago|reply
> I installed SBCL, Slime for Emacs, and started working through the book Practical Common Lisp.

This is exactly the approach I took (~15 years ago) when I went all-in on Lisp for a few years. Don't know if it is still the best today, but it was a solid approach at the time.

[+] harperlee|5 years ago|reply
If you mean Common Lisp, I'd say install SBCL and start playing with with the repl. Choose the editor you know best; even notepad is useful to copy and paste expressions to/from the repl. Any editor that's suited for programming will have a way to send expressions to the repl with a keystroke, which is much more comfortable. So basically, just pick VSCode.

With that, you're ready to go. Take just one book and work through it, you don't need the best book, but a book will be better structured and more complete than multiple blog posts from different people. Practical Common Lisp (http://www.gigamonkeys.com/book/) is good and freely available. I used ANSI Common Lisp (http://www.paulgraham.com/acl.html), from Paul Graham (https://news.ycombinator.com/user?id=pg), long time ago and it's also good.

If you are open to non-common-lisp lisps, I'd say pick up clojure instead of common lisp, it's more modern and thus you will find more community and up-to-date resources. Clojure for the Brave and True is a book that has been praised, but I did not read it. It has some jokes and humorous examples that might or might not suit you.

[+] farias0|5 years ago|reply
I'm doing Clojure for the Brave and True right now and it has been an amazing resource. It even incentivized me to get into Emacs as well, which has been a blast. I'm not a fan of the humor, but it does not get in the way at all.
[+] _ph_|5 years ago|reply
SBCL is great, but one should not use an editor, which doesn't have proper paren matching and some indentation support. That is just making your life miserable. So SBCL+Slime+Emacs is a great combination. Or alternatively, get the free version of Lispworks.
[+] priyanshuraj|5 years ago|reply
"If you mean Common Lisp, I'd say install SBCL and start playing with with the repl"

I meant any lisp. Common lisp, clojure, ccl. I am new to this so did not have a choice. But in this thread I get the feeling that common lisp is the most suggested.

[+] BoiledCabbage|5 years ago|reply
A whole lot of answers but very few questions - most importantly "Why do you want to learn Lisp?"

Are you new to functional programming and have heard that's the parent language? Do you know a statically typed functional language and want to learn a dynamically typed? Are you looking for something practical you can interop easily with other languages with? Are you looking for a good language to follow SICP with? Do you already know scheme but want to learn a true lisp?

Depending on the reason why there are lots of different recommendations. For example If you know Java, and want a more practical language with modern library support from the lisp family someone may actually say Clojure is the best choice for you. But if you know scheme and are wanting to learn an actual lisp, then that wouldn't match your needs.

Always be wary of people telling you what you should do without them knowing why you want to do it. Not because they don't mean well, but because the only way they can answer is by projecting their own reason "why" onto you - which in most cases isn't applicable.

[+] flavio81|5 years ago|reply
Yes, "Why do you want to learn Lisp?" is a good question.

If the author wants to use Lisp because he/she thinks metaprogramming is interesting, or has read about the benefits of interactive programming, Common Lisp is the choice here.

If the author wants to use Lisp as a way to get a deeper understanding of important computer science topics, I think Scheme is the best choice and with this, following the SICP book.

If the author is interested specifically in functional programming and wants to get easy employment doing it, he/she should take a look at Clojure, Ocaml, and F#.

[+] flavio81|5 years ago|reply
Yes, "Why do you want to learn Lisp?" is a good question.

If the author wants to use Lisp because he/she thinks metaprogramming is interesting, or has read about interact

[+] AnthonBerg|5 years ago|reply
Since you're a Vim user like me: I've found Emacs Lisp a good way to accidentally learn Lisp!

Like there are many Lisps, there are many Vims. Spacemacs is a Vim for Emacs or inside Emacs: https://www.spacemacs.org/

It's quite powerful. And it can be argued that Emacs is highly extensible - because it's written in a Lisp. Looking under the hood and hacking on the editor is a lot of fun and very informative. And also horrible and bad. But in a good way!

And almost completely unrelated: I very much enjoy the Structure and Interpretation of Computer Programs book and online lectures: https://ocw.mit.edu/courses/electrical-engineering-and-compu...

The video lectures were recorded in 1986!: https://ocw.mit.edu/courses/electrical-engineering-and-compu...

And they're still amazing.

(But people all think very differently and what works for me may not be your cup of tea!)

[+] mumblemumble|5 years ago|reply
There are a lot of classics such as SICP and The Little Schemer, and I dearly love them all and consider them all to be canon that everybody should read at least twice. But, for an easy/fun on-ramp, I think that there are three new contenders that are much better for getting a feel for things. Pick one according to your tastes, or burn through them all in a couple weekends and then decide.

If "functional programming for the enterprise" sounds good to you, read Clojure for the Brave and True.

If you're more interested in a truly mature language with a more academic community, read Land of Lisp.

If you're looking for a simple language that's easy to learn, or if metaprogramming is really your jam, read Realm of Racket.

As far as editors go, just start with whichever one you personally like best. They're all fine. I wouldn't bother spending much time worrying about that until after you've confirmed you want to stick with it.

[+] rscho|5 years ago|reply
Re language choice, you should be aware that CL is a massive language and requires you to know a lot of things about it to be efficient. With Scheme (Racket), you'll be able to ramp up easily as it requires less knowledge (as long as you are not doing metaprogramming). You also have the option of using Scheme itself to have something even simpler (Chez, gerbil, lots of choices here).

So you should ask yourself what your use for Lisp is. If it's just for fun, I'd go with the simplest.

[+] Scarbutt|5 years ago|reply
Realm of Racket doesn't teach you about metaprogramming though.
[+] tarsinge|5 years ago|reply
I didn't go far with Lisp but I had fun with The Little Schemer as a first contact.
[+] lew89|5 years ago|reply
First you have to choose your flavor. If you want to use JVM, probably clojure. Otherwise Scheme, Common Lisp and Racket. Scheme is rather minimalistic, Common Lisp is very functional and Racket is the most modern one I guess. I ended up with Common Lisp and I rather don't look for change. SBCL is implementation I use and like it. Probably the best one and quite portable.

Emacs seems the best choice for Lisp, since it is scripted in Lisp and it's best adapted to it probably. However when I started, I was already so used to vim that I kept going with it. Maybe not the best option, but it's ok, maybe just a little bit more effort to automatize some stuff.

If you choose Common Lisp, this is probably the best book for start: http://www.gigamonkeys.com/book/ . Anyway be prepared, Lisp is not easy to grasp at first, but as soon you do, you will probably love it and appreciate way it is. :)

[+] cat199|5 years ago|reply
> Lisp is very functional

just to point out i believe 'functional' here means 'has lots of functionality' not 'more suited to functional programming' - in that regard scheme (and racket) are more 'functional' than CL

[+] mcint|5 years ago|reply
When hackers[1] wax poetic about lisp, they focus on the core properties of the language (-family) that aren’t found in other languages. The meta-circular evaluator (lisp interpreter/compiler in lisp), “homoiconic” syntax (enabling easy modification of code), and others. These are what stuck with me most strongly.

ClojureScript (cljs) (and Clojure) I would recommend as practical, but simple and approachable dialects.

Scheme is a good, simple dialect to learn if you’re just looking to grok lisp in “maxwell’s equations” elegance (but not work in it). Not nearly as many libraries written for it as Common Lisp has, or Clojure with JVM interop, or CLJS with javascript+node interop).

Whether you use Scheme or cljs (or another~), I recommend SICP[2] “Structure and Interpretation of Computer Programs”, free online from MIT press. There’s even an interactive, editable version online [3] (though it doesn’t support saving reader code)

[1]: http://www.paulgraham.com/lisp.html

[2]: https://mitpress.mit.edu/sites/default/files/sicp/index.html

[3]: https://xuanji.appspot.com/isicp/

[+] yissp|5 years ago|reply
Haven't seen it mentioned, Paradigms of AI Programming by Peter Norvig is another good introduction to Common Lisp. It focuses on classic AI algorithms which showcase the strengths of the language well. It's available online here https://github.com/norvig/paip-lisp
[+] SkyMarshal|5 years ago|reply
The Little Schemer series is a good introduction to Lisp/Scheme parenthesis-style recursive programming.

https://mitpress.mit.edu/books/little-schemer-fourth-edition

https://mitpress.mit.edu/books/seasoned-schemer-second-editi...

https://mitpress.mit.edu/books/reasoned-schemer-second-editi...

They’re written in a Socratic way, as a series of questions and answers. A good way to learn is to follow along and answer them yourself using Racket (before turning the page and seeing the answer). Racket is quick and easy to setup and use:

https://racket-lang.org/

[+] st1x7|5 years ago|reply
Is there a good argument against Clojure in this case? My impression is that it's a good lisp and you can get actual work done in it which is an advantage over some of the other options.
[+] simongray|5 years ago|reply
The main issue with Clojure is probably its tight integration with the various host platforms. When you get a stack trace in Clojure/ClojureScript, you basically get a Java or JavaScript stack trace, so there is some expectation of familiarity with the host platform. If you already have some experience with the host, then this shouldn't be a big issue, but it's a dealbreaker for some people.

Another issue has to do with startup time. The Clojure application bootstrap process is relatively slow, i.e. start-up might take 1 second, so it's great for server applications, but less great for Android apps or other CLI scripts that expect require instant startup. It has been approached in different ways, e.g. compiling Clojure with Graalvm native image or using ClojureScript instead of JVM Clojure. The latest solution is Babashka which provides a variant of Clojure specifically for writing CLI scripts.

Otherwise, Clojure is an excellent language which both modernises Lisp syntax significantly and implements a very well thought out standard library for doing functional programming. There are many great features, but the standout ones are probably the persistent data structures (which syntactically act both as data structures and functions) and parallelism/concurrency support. It's also very natural to do interop with the host platforms (Java, JS, .NET) and the data-oriented style of programming makes communication between backend (Clojure) and frontend (ClojureScript) extremely simple. So it's pretty much the perfect full-stack language for information systems. I would take a look at the rationale: https://clojure.org/about/rationale

[+] flavio81|5 years ago|reply
>Is there a good argument against Clojure in this case?

I use Common Lisp and my main argument will be that Clojure isn't an "interactive programming" language like Common Lisp, Smalltalk (and Pharo, Squeak, Scratch) are. And, for me, this is removing one of the main, core advantages of Lisp.

Dispensing with the interactive programming features is, IMO, a step backwards in the state-of-the-art. Common Lisp ADDED all the improvements in the state of the art: Interactive programming from Smalltalk, lexical scoping from Scheme, various high performance/low level features from StarLisp and ZetaLisp, a very powerful OOP system, etc. And then, thanks to it being highly extensive, almost any feature can be added to it.

Clojure features like threading macros, immutable seqences, software transactional memory, and others, are already available in Common Lisp by just importing (loading) the respective library.

One of Clojure's main advantage is to be able to call Java libraries. But, surprise, you can do this in Common Lisp too, easily, by using the Armed Bear Common Lisp (ABCL) implementation. Which runs on the JVM too and makes the process of calling Java libs really, really easy. I have made a working example here, calling all the Swing UI library (java) from lisp:

https://github.com/defunkydrummer/abcl-jazz

It's true that Clojure has more widespread adoption in the industry and more libraries. However the library ecosystem on Common Lisp is decent.

>and you can get actual work done in it which is an advantage over some of the other options

This implies you can't do "actual work" in, for example, Common lisp. Which is not true, since there are companies that, in this very moment, are doing well paid, critical commercial work using Common Lisp.

[+] vindarel|5 years ago|reply
I tried Clojure a bit and, compared to CL, I find it bloated :S Installing a library takes ages, a lot of memory, and I can't do it from the REPL (so I must quit my development environment, and start it again). CL feels very snappy. I can even install a new library to a running web app. I know it's dangerous, but it works and it helped me already :)
[+] phoe-krk|5 years ago|reply
One argument I can think of is that if your problem is not shaped in a functional way, then a functional programming language might be a poor fit for the job.

Common Lisp is multi-paradigm language that is pretty bendy with regard to absorbing new ways of doing programming. It gets actual work done as well.

[+] firepoet|5 years ago|reply
How is the VSCode support? I've only used IntelliJ + Cursive for Clojure and am quite spoiled. That's the only reason I might not recommend Clojure for a VSCode user. Now, if said user is interested in switching to Emacs or IntelliJ, I'd think it would be a perfect fit.
[+] casi|5 years ago|reply
Emacs and slime are great for lisp, but my experience is that learning all three at once is too much. Stick to vscode and install the lisp extensions (or sublime and sublime repl was what I learnt on) and work through the lisp koans (search on github you’ll find the repo).

Once you have the basics down then look into setting up slime and jumping down the emacs rabbit hole.

[+] dognotdog|5 years ago|reply
I think you can use whatever to do Lisp. I'd start with something simple like Scheme, and definitely by watching and doing the SICP lecture recordings from now 34 (!) years ago: https://ocw.mit.edu/courses/electrical-engineering-and-compu...

Once you think you grok it, you can pick a Lisp that's closest to what other tools and frameworks you're used to. For me, I never actually did anything in Lisp for production use, but learned a lot from playing with various flavors of it.

[+] da39a3ee|5 years ago|reply
> I think you can use whatever to do Lisp.

I'm not sure about that. You need an editor that automatically matches parens and other paired delimiters and keeps them balanced, like paredit.

[+] frompdx|5 years ago|reply
At this point I don't see how I could make a suggestion that hasn't already been made. My only regret is waking up in the wrong timezone and being late to the party. I think it is great to see so much interest and so many answers to this question here on HN.

I suppose one suggestion I might make is to take a look at Janet after you have a chance to do some reading on lisp. It is practical and multi-paradigm like Common Lisp but adopts syntax similar to Clojure. Plus it comes in a small package and the docs for the core library are really nice.

https://janet-lang.org/

[+] billsix|5 years ago|reply
Books

-ANSI Common Lisp by Paul Graham -On Lisp by Paul Graham -Simply Scheme -The Little Schemer -Structure And Interpretation Of Computer Programs -Paradigms of Artificial Intelligence Programming

Implementations

Common Lisp - any should be fine, I’ve used sbcl and clisp

Scheme - I like gambit scheme. It has a macro system that can be used like described in “On Lisp”

[+] ralfd|5 years ago|reply
The Hacker News Paul Graham?
[+] whalesalad|5 years ago|reply
I’d start with Clojure if I were you. Then the leap to a more traditional lisp will be much easier.

That being said you might have no desire to leap at all - Clojure is a powerful language with a great ecosystem (especially if you rope in Java interop)