HACKER Q&A
📣 priyanshuraj

I want to start learning Lisp. Where do I begin?


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?


  👤 pixelmonkey Accepted Answer ✓
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.


👤 mindcrime
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.


👤 harperlee
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.


👤 BoiledCabbage
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.


👤 AnthonBerg
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
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.


👤 lew89
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. :)


👤 phoe-krk
Common Lisp programmer here.

https://stevelosh.com/blog/2018/08/a-road-to-common-lisp/

That's the best article I know on the matter.


👤 mcint
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
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
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
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.

👤 casi
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.


👤 gkbrk
Emacs will probably be better in the long run for Lisp, but you can use any editor to begin.

For Common Lisp, SBCL [1] is probably the best free option. If you want to learn Scheme instead, Chicken Scheme [2] and Racket [3] are popular and good choices.

[1]: http://www.sbcl.org/

[2]: https://call-cc.org/

[3]: https://racket-lang.org/


👤 dognotdog
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.


👤 frompdx
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
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”


👤 vansul
Michael Nielsen (one of the creators of quantum.country, often cited as a feedback-giver on PG's essays) has a short blog post introducing and exploring Lisp here:

https://michaelnielsen.org/ddi/lisp-as-the-maxwells-equation...

Its on the more academic side and focuses on the Scheme dialect, but is well-written


👤 whalesalad
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)


👤 elitepleb
Why not go through some of the classic lisp programming books like sicp[1] or htdp[2], since both are freely available?

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

[2] https://htdp.org


👤 auganov
The very reason I find Lisps enjoyable is all the things an editor can do for you with a Lisp. Smartparens, rainbow parens, easy eval of forms (+ pprinting, macroexpand, inline replace etc), jump to definition, for Clojure - contextual awareness of the namespace and REPL session you're in. Probably forgetting a number of things. Without these there wouldn't be much for me left to like about programming in a Lisp. As far as I'm concerned, learning to use the editor well is as important as learning the language itself.

I only know Emacs well. Checked out VS code for Clojure a while ago and it wasn't even close. Clojure IDE "Cursive" is supposed to be good, but never tried and not sure if you want to invest time in an ad hoc IDE. It seems to me lispers don't want to discourage people by recommending Emacs, but at the end of the day, most people who stick with it tend to be Emacs users.


👤 DubiousPusher
I don't know what it is about ANSI Common Lisp but it wasn't just a good introduction to something technical, it was fun. I blasted through it in a couple days. I never do that. I usually can't wait to ditch whatever introductory text I'm using and get off the beaten path but I couldn't put it down.

👤 jcubic
I would start with Scheme or Racket that is based on Scheme. I would start with any Scheme interpreter like Kawa or Guile. If I would recommend any book it would be Sketchy Scheme by Nils M Holm (that I've read recently) https://www.t3x.org/sketchy/ it start with basics but it have lot of details and advanced stuff about Scheme and how it works. It also as title suggest intro to functional programming.

If you would like to learn on line (maybe using pdf book) you can try my Scheme REPL bookmarklet https://lips.js.org/#bookmark so you don't need to install anything on your computer, you can do that later.


👤 Tomte
On Lisp by Paul Graham is a good start: http://www.paulgraham.com/onlisp.html

Edit: I meant ANSI Common Lisp. Thanks everyone!

(I wouldn't even recommend On Lisp as a second text, too much macrology).


👤 joubert

👤 npsimons
Lot of comments here, many good, so I'll try not to duplicate, but:

  1. Emacs is a hurdle, but one that's worth it when you use SLIME.
  2. I went through Barski's "Land of Lisp" and enjoyed it, but couldn't get the web server to work, so I tweaked it to use Hunchentoot[0]
[0] - https://github.com/npsimons/land-of-lisp-using-hunchentoot/c...

👤 mark_l_watson
Pardon my plugging my own book, but you can read it free online: https://leanpub.com/lovinglisp and checkout the GitHub repo with examples. There are much better Common Lisp books for a broad coverage of the language. My book is a short tutorial followed by many example programs. The book is released under a Creative Commons license so you can find copies on the web, but probably better to read the latest version online.

👤 nnadams
This is a bit tangential but what helped me most in picking up Lisp was writing my own. Until I worked through Make A Lisp [0] I don't think I really "got" Lisp. You can work in whatever language you're familiar with. You build a Lisp similar to Clojure and learn a lot of important concepts by implementing them.

[0] https://github.com/kanaka/mal


👤 mimixco
For anyone who needs a "download and go" way to play with Lisp, Allegro offers a free version. It's one installation. For VS Code, I'd wire-up SBCL as others have said. It's a little touchy to get setup but we produced our product with it so it does work.

The whole issue of "flavors" largely comes down to one concept: Do you like the idea of functions and variables being in the same namespace (that's called a Lisp 1 like Scheme) or different (a Lisp 2 like CL). If you don't care, it doesn't matter which you pick.

If you're going to extend your Lisp app into production, you might want some of the many libraries that are available for CL. These cover just about every known topic and algorithm in comp sci and they're old and proven and just work everywhere, so that can be a benefit as you move to a non-trial app.

If you're going to distribute something written in Lisp (like an executable), then the flavor and implementation you pick will need to work all the way down your distribution path, and that can be challenging to get setup. One proven path is SBCL + Node.js + Electron to wrap your app for all three platforms.

Hope you love Lisp and get great things out of it!


👤 garren
I'm currently taking another stab at lispy-languages. I've tried it a few times in the past and I've always had a hard time coming back to it when something else intervenes. Usually self-inflicted because of some complex and unecessary environment setup involved.

I've lately had some success using vanilla emacs, Geiser and Guile (or MIT) Scheme. If you want to work through sicp, the little schemer [1], or my current favorite "Essentials of Programming Languages"[2], then that's the perfect setup. Racket will work too, but if you're using emacs anyway then it's just as easy to get going with Guile or MIT.

I'd recommend getting familiar with largely vanilla emacs[0] rather than a curated kit, but it will require a little bit of additional investment. Additionally, you'll be getting acquainted with emacs-lisp (elisp), so you'll be swimming in lisp languages.

I'm not a fan of VS Code and only use it for work when I have to (and then only when I can't use vim). I'm sure it'd work, vim too, but there are an awful lot of emacs/lisp resources out there and it's helpful to take advantage of what's available.

[0] https://sanemacs.com

[1] https://www.amazon.com/Little-Schemer-Daniel-P-Friedman/dp/0...

[2] https://www.amazon.com/Essentials-Programming-Languages-Dani...


👤 wmoser
Land of lisp by Conrad barski is a pretty great book too.

👤 kopos
Do you plan to learn as a LISP dialect as a purely academic exercise or to build something with it?

If you want build it as a tool, I’d recommend Clojure.

I’ll be happy to teach if you’re interested

https://twitter.com/akakopos/status/1331613484623093765


👤 asdfsfa
If you're set on using vim slime is great. Basically you bring up the REPL in another tmux or screen split then you can just pipe your forms to it.

https://github.com/jpalardy/vim-slime

Here's a few previews for fun books I enjoyed, land of lisp and realm of racket by conrad barski

https://books.google.ca/books/about/Realm_of_Racket.html?id=...

https://books.google.ca/books?id=9apQfCRhvm0C&printsec=front...


👤 emeraldd
It took building a lisp for me to finally understand them .. I recommend http://peter.michaux.ca/articles/scheme-from-scratch-introdu...

👤 da39a3ee
Switch from vim to use evil-mode in emacs, perhaps via the spacemacs or doom emacs emacs starter projects. These present the vim editing interface, but implemented in emacs.

Then you're using emacs. Play around with emacs lisp customizing it and writing utilities for yourself to do editing tasks and whatever else you can think of. The community of emacs lisp programmers has lots of common lisp programmers. It's a serious-enough lisp to get started with, with sophisticated macros and several features from common lisp.

Make sure you use paredit. It's basically essential when learning lisp to use an editor that automatically matches parens and keeps them balanced. Beginners who complain about the parens are making that mistake.


👤 ragnese
If you want to learn a LISP dialect just for fun and/or enlightenment, I would say you want either a Scheme (Guile or Racket) or Clojure.

Some people will argue that Clojure isn't a real LISP, which is fine. They're probably right. But it's an elegant and well-designed language that has a lot of the same features and feeling of a LISP/Scheme.

I know I could be burned alive for saying it, but Common Lisp is pretty ugly, IMO. It's "pragmatic" and has a bunch of libraries and functionality and whatnot, but it's not as fun or elegant as a minimal, pure, Scheme.


👤 hprotagonist
drracket is one of the more impressive pedagological IDEs i’ve ever seen.

👤 klibertp
About the editor:

In general you can use any editor, but there are some features which your editor should have to make your life easier. I wrote a blog post about it some time ago: https://klibert.pl/posts/tools_for_lisp_syntax.html

Basically, syntax highlighting, automatic matching paren insertion, ability to jump to a matching paren are the baseline. If you can get those with a plugin to VSCode or Vim, you're good to go.


👤 DoreenMichele
You might be interested in this old discussion:

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


👤 mimixco
The Lisp Tutor Jr was amazing. It gave you problems and "watched" as you type the solutions in Lisp. It seems to be down![0]

Does anyone know if there's a mirror somewhere? I'd gladly host this in a droplet and make it public if someone has the source.

[0]http://reed.cs.depaul.edu/peterh/Tools/lisptutor.html


👤 lisp4fun
Check out Gerbil Scheme. It has a lot of great features included in its standard library[0], and is currently the fastest Scheme around[1]. The only downside is no Windows support at the moment.

[0] https://cons.io/

[1] https://ecraven.github.io/r7rs-benchmarks/


👤 bloopernova
I asked this in Reddit a while ago and got these answers: https://www.reddit.com/r/lisp/comments/iwz36s/list_of_lisp_e...

VSCode will be fine for editing Lisp, there's a good syntax highlighter extension too.


👤 pava
I thought The Little Schemer was a fun text that is presented in a unique way. There's also another fun one called The Land of Lisp.

👤 michaelsbradley
How to Design Programs, Second Edition

https://htdp.org/2020-8-1/Book/index.html

It's a good introduction to programming in general and uses a series of "student language" dialects of Racket, which is in the Scheme/Lisp family.


👤 priyanshuraj
I forgot to ask in my main question. I can't edit it anymore.

I am seriously thinking of learnijg common lisp. Thank you for all the suggestions.

Is it possible to build web apps in common lisp or any lisp? Any frameworks available?

Is it possible to build multithreaded apps that use multiple CPU cores for performance? What is used? POSIX threads?


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

Better install Portacle, that's the only thing you need to install to edit, compile, and debug Common Lisp code.

Then you can learn by reading a good book like a "Gentle introduction to Symbolic Computation" or "Practical Common Lisp".


👤 aespinoza
This book made me fall in love with Lisp: Land of Lisp - https://nostarch.com/lisp.htm

I found it super helpful understanding everything there is about Lisp, and you can move from there.


👤 SeeManDo
I would start with Dr Scheme (now called Racket/PLT Scheme). That is what CS301 at UT Austin started with https://plt-scheme.org/ back when I was an undergrad in 2000

👤 User23
Is there a full featured editor that's hosted in the SBCL image itself? I vaguely recall CMUCL had something of the sort. It used to be you had to actually specify GNU Emacs, but nowadays it's pretty much the only Emacs anyone means.

👤 AndyMcConachie
I worked my way through Land of Lisp a few years ago and had a good time with it. I had already done some Lisp programming before, but I learned a bunch from Land of Lisp and had fun in the process.

👤 evanb
Somewhat orthogonal to the question, but if you're looking for good programming exercises (for any language!) Advent of Code adventofcode.com is always a great place to look.

👤 gorjusborg
I really enjoyed reading 'The Little Schemer' book. It teaches the Scheme language, which is a Lisp-1. It was entertaining due to the novelty of its format.

👤 yodsanklai
I'm just wondering, besides being more knowledgeable about languages in general, are there any use cases for Lisp dialects nowadays?

👤 susam
Here are my recommendations on this topic:

- Choose Common Lisp because it has been the most popular dialect of Lisp in the overall history of Lisp. It is more convenient than Scheme if one decides to develop serious software in Lisp. Clojure appears to be more popular in the technology industry than Common Lisp among organizations (my workplace included) that use Lisp. I still recommend Common Lisp because I believe that it is more likely that one would work on an independent open source or hobby Lisp project than one would encounter one of the rare organizations who use Clojure at work.

- Choose SBCL (Steel Bank Common Lisp) as the implementation.[1][2] It is the most popular[3] Common Lisp implementation and is recommended in many online discussions. CCL (Clozure CL, not to be confused with Clojure which is a separate dialect) is also another very good implementation.

- Work through this book: Practical Common Lisp: http://www.gigamonkeys.com/book/ (available in print too if you search online). Just use a modern alternative to Lisp in a box when you reach Chapter 2. In fact, I encourage using vanilla Emacs and setting it up with SLIME and Paredit yourself. See Emacs4CL for example.[4]

- A Vim user may consider installing Slimv or Vlime[5]. Slimv and Vlime offer an environment similar to Emacs/SLIME. They display the REPL in a Vim buffer. Slimv also comes with Paredit mode that makes typing and executing S-expressions quite convenient.

- In case you want to postpone setting up Emacs + SLIME or Vim + Slimv/Vlime until a time you have become more familiar with the language, you can also execute your Lisp source code files from the shell.[6]

- Optionally, keep another implementation of Common Lisp. Common Lisp is a standard that is implemented by various implementations. Each implementation may have its own extensions or implementation-specific behaviour regarding error handling, command line options, FASL format, unspecified behaviour, etc. Experimenting with concepts with another implementation of Lisp occasionally may offer some perspective about how some things could be different in different implementations. I keep CLISP around for this purpose.[7][8]

[1]: Install SBCL on macOS: brew install sbcl

[2]: Install SBCL on Debian-based distro: apt-get install sbcl

[3]: State of Common Lisp Survey 2020: https://docs.google.com/forms/d/e/1FAIpQLSfg7UJRKrkI3OjOHWL4...

[4]: Emacs4CL: https://github.com/susam/emacs4cl

[5]: Lisp in Vim with Slimv or Vlime: https://susam.in/blog/lisp-in-vim-with-slimv-or-vlime/

[6]: Load (execute) code in a file and exit: sbcl --script foo.lisp

[7]: Install CLISP on macOS: brew install clisp

[8]: Install CLISP on Debian-based distro: apt-get install clisp

Disclosure: I am the author of [4] and [5].


👤 slaymaker1907
Racket is explicitly designed as a teaching language and I would highly recommend Beautiful Racket as a starting point.


👤 pagade
SICP and umb-scheme is how I learned as part of the university course with fairly advanced exercises.

👤 threatofrain
Has anyone found a good beginners up and going setup for Lisp and VSC?

👤 jb1991
Scheme or Clojure. Get The Little Schemer book.

👤 bitwize
Probably the best way to get started just to install SBCL and start typing stuff in at the REPL. Lisp is a very immediate language; you can type an expression in and the REPL will instantly evaluate it and show you the results. Many other languages, such as Python, Ruby, and JavaScript, actually borrowed this feature from Lisp.

You're going to need an editor to write long-form programs. Vim and Visual Studio Code are fine, but the ne plus ultra of Lisp editors is Emacs ( https://www.gnu.org/software/emacs ). Emacs comes with an excellent Vim-emulation mode, so if you cannot leave behind your vi muscle memory, that's always available to you. Another feature of Emacs is, it contains, and much of it is written in, its own dialect of Lisp! The upshot of this is you can usefully extend and customize your editor by evaluating a few Lisp expressions. Playing with Emacs Lisp is a great way to learn how to use the language to do "real work" during your experimentation. Emacs has a package available called SLIME, which allows it to talk to a standalone Lisp environment such as SBCL, send it expressions to evaluate, and get results. SLIME also has LSP-like features to show documentation on the Lisp functions you've defined. Vim and Visual Studio Code can speak SLIME's protocol with the proper add-ons, but the integration is not as tight as with Emacs.

If Lisp seems overwhelming, it's because it's more of an idea than a specific language. There are three varieties of Lisp you should be aware of. Well, four if you count Emacs Lisp, but the standalone ones are:

* Common Lisp

* Scheme

* Clojure

Of these, the best place to start is probably Common Lisp. It is a comprehensive language which has been used in real-world software engineering projects since the 1980s, and it has a very strong community surrounding it. There are a few implementations, both open source and proprietary. The most favored one today is SBCL: https://www.sbcl.org

Scheme is much simpler. It is more of a language core used for teaching, and for providing a basis for a more feature-rich programming language. There are many implementations, most of which provide their own extensions to the core language; my favorite for getting work done in a Unix-like environment is GNU Guile: https://www.gnu.org/software/guile

Clojure is a language that is designed to interoperate well with the JVM, and to promote Rich Hickey's ideas on functional programming. It is a very opinionated language, more so than the other two, and you may find yourself struggling more if you don't do things the Clojure way. Personally, I like it less than the other two, but that's a matter of taste and you may find it more useful.

Over time I hope you will have the opportunity to try all three. Each has something different to offer and each can be learned from.


👤 xyproto
If you're on Arch Linux, you can install the `lisp` package from AUR, then type `lispi` and then `(+ 1 2)` for adding 1 and 2. Don't type in the backtick quotes. Press `ctrl-c` to quit.

If you install `clojure` you can start the interpreter with `clj` and also type in similar expressions, like:

  (* 3 7)
There are a couple of differences to Common Lisp, though.

The fun thing about Lisp is that you can pass any number of parameters to functions, like "+", so that expressions like this also works fine:

  (* 1 2 3 4 5 6 7)
The next thing to know is that the first element within () is interpreted as the function, while the rest are interpreted as parameters. Then how do you represent a list like (1 2 3) without Lisp thinking that "1" is the function, you surely ask? You prefix it with ', like this: '(1 2 3). If you type '(1 2 3) into the `lispi` or `clj` prompt, they will print (1 2 3) right back at you.

A fundamental concept in Lisp is to get the first element of a list (the head) or the rest of the elements (the tail). For historical reasons the head is called CAR and the tail is called CDR in lisp. Everyone has just accepted that this is the way of Common Lisp by now. In Clojure, "first" and "rest" are used instead of CAR and CDR, as the heathens they are.

Since regular for loops are for wimps and snowflakes, iterating in traditional Lisp mainly centers around how to do the same thing using CAR, CDR and recursion.

Before we can do that, let's define a function that adds 2 to the given number:

  (defun addtwo (x) (+ x 2))
Note that "defun" is the function for creating functions that takes, roughly speaking, three parameters: the function name, the function parameters and the function expression.

If you type it into "lispi" you can use the function afterwards, and get the result 42:

  (addtwo 40)
Also, all lists in lisp are really just the head and the rest, so creating lists can be done by combining a head with the rest of a list, using cons, like this:

  (cons 1 ())
Which is equivalent to this (but signifies that quoting was intended):

  (cons 1 '())
And this:

  (cons 1 nil)
All three of the above expressions returns a list with one element (1), which means a head of 1 combined with an empty tail. Lists are constructed by appending heads to existing (or empty) tails.

Creating a function that takes apart a list into a head and a tail and then combines them again can be done like this:

  (defun combine (xs) (cons (car xs) (cdr xs)))
"xs" is the name of the function parameter, which is a list.

The combine function can be called like this:

  (combine '(1 2 3))
And will return:

  (1 2 3)
If you wish to edit code in a file instead of interactively, where the arrow keys may not always work, try putting this in a file named "main.lsp":

  (defun hello ()
    (write-line "Hello, World!"))
Then run the desired function with:

lisp main.lsp hello

Now to create a for-loop replacement in Common Lisp, for people with hair under their arms, using CAR and CDR and recursion. This program will print each number in the given list, with an axe emoji after each number (HN removed it, please insert an appropriate unicode emoji instead of the x):

  (defun lumberprint (n)
    (write n)
    (write-line "x"))
  
  (defun f (xs)
    (unless (null xs)
      (lumberprint (car xs))
      (f (cdr xs))))
  
  (defun main ()
    (f '(1 2 3)))
Save as "main.lsp" and run with "lisp main.lsp".

"unless" takes a condition and a list of statements. "null" checks if a list is empty. "write" outputs the given argument, but not a newline. "write-line" outputs the given argument and also a newline.

This should be enough to get you started. Then read SICP and draw the rest of the owl.

Best of luck!


👤 willcipriano
If you want to learn C at the same time I can suggest "Build your own Lisp"

http://www.buildyourownlisp.com/


👤 roberthahn
I remember wanting to learn lisp. I got stuck and reached out to the community for help.

And found them to be very hostile.

I decided I had better things to do with my time.


👤 Indy9000
Implement Lisp parser and a repl in your fav language. It's not difficult.

I made a series of videos how to do it in typescript. That was fun!

Here's the link if you're interested: https://youtube.com/playlist?list=PLP_fzAt_4T3QVlW_7Zr3CYLmV...