Can you use emacs to program in common lisp?
Asked Answered
T

4

5

During my course on lisp programming I used the lispworks IDE trial version, which is a very good IDE but it's still a trial version. I searched for a new IDE. And I saw this video https://www.youtube.com/watch?v=VnWVu8VVDbI.

In which he uses slime sbcl and quicklisp to program in common lisp on emacs.

My question is how is that possible?Doesn't emacs come with it's own dialect of lisp which is known as Emacs lisp or are they separate from each other?

Tagore answered 11/7, 2018 at 4:23 Comment(0)
R
9

Setting up Emacs and SBCL can cost you some time.

Update:

Now, I would not answer "portacle" or "lispbox" but Roswell as I explain here!

Previous answer:

I highly recommend you portacle - so to say the newer/younger brother of lispbox. Lispbox is created for 'out of the box'-to go lisp environment using emacs with installed slime-mode readily connected with sbcl and quicklisp-installed (for readers of 'Practical Common Lisp' by Peter Seibel) - kind of emacs-set-up-for-Lisp (or batteries-included-emacs from the perspective of a Lisp-beginner-programmer). I was long searching for this "update" of Lispbox - though meanwhile installed sbcl and quicklisp and slime manually - Actually I think the Lispbox site should link and hint to portacle because this is the up-to-date version of Lispbox - it would have saved me time. The Lisp community should spread the words about portacle. (both provide you with ready-to-go emacs which then is connected to sbcl and also has quicklisp installed - quicklisp for Lisp is like pip for Python, a package manager by which you can pull and install Lisp packages from a central repository - or like melpa for emacs lisp). (quicklisp is in its core asdf, an old package manager, but nobody nowadays uses asdf to install packages directly, but does it via quicklisp).

For Windows users, I highly recommend lispstick which works (in contrast to the current version of portacle for Windows ... I hope they fix it). The author also wrote a nice book (2016, but in German).

For an easier entry to emacs which is very complex and I had also several attempts to get to used to it, I highly recommend you Derek Banas' video tutorial on emacs which is one of the best intro-level tutorial I found for this topic. Also his tutorial for common lisp might give you a good start. I summarized some of the key bindings (a minimal set of key bindings) which I use frequently when programming common lisp in emacs. It is really minimal. Whoever discovers more, can also give me more tipps. Here is the link to a very minimal emacs/SLIME cheat sheet for lisp beginner programmers

The Common Lisp HyperSpec is helpful if you really begin to program in Lisp - it is a necessary tool, I would say - and also the Cookbook page for Lisp initiated by Edi Weitz and also his book with recipes for Common Lisp. However, since Lisp is very different from all the C-derived languages, I highly recommend you to begin with sth which explains you more what lisp is and how it works. A combination of Practical Common Lisp by Peter Seibel and Land of Lisp by Conrad Barski was the starter for me. But although the authors did really a great job, I think a easy-to-read and smooth intro for C-derived language programmer into Lisp is still to be written.

By the way, if you find vim easier to use, there is a nice way to use vim short-cuts in emacs - the evil mode - and even better and fantastic is Spacemacs which has in addition to vim shortcuts - their very specific way to access functions - mostly beginning with pressing the space-button (thus the name spacemacs). It is an open source project.

Unfortunately there is no Portacle-like batteries-included spacemacs for lisp novices. But maybe that is to be set up in near future by some of us :) . Spacemacs is fantastic!

For emacs: I wrote down emacs minimalistics commands for beginners in my GitHubGist.

Rutaceous answered 11/7, 2018 at 8:50 Comment(4)
I thank you for your kind answer and for the recommendations that you provided. The reason for asking this question was because I "think" I have some basic knowledge of common lisp and I finished my lisp course successfully and I want to pursue personal projectsTagore
@jakHunter: My pleasure, if I could help you with the answer. That is great that you covered then the basics! Then, I highly recommend you OnLisp by Paul Graham, and letOverLamda (which is freely available). Both focus on Macros which are the speciality of Lisp - as you might know. For trying out things quickly, I still use CLISP which provides navigation with keys other than sbcl - so user-friendly repl. (And one has not to be able to navigate with emacs shortcuts in CLISP - so it is more intuitive - it feels for lisp a little bit like ipython repl for Python).Rutaceous
By the way, there is also a way to use Jupyter Notebook for Common Lisp Programming, if you are familiar with Jupyter Notebook. But for sure, emacs is way more powerful. You can execute single expressions on the fly, compile etc with emacs shortcuts ...Rutaceous
On some Linux distributions (e.g. Debian) both SBCL & Slime are packaged, so installing them both is quick and easyMeggs
A
5

Even though there are already a few good answers to the question, I'd like to add here an answer myself, mostly to mention a great alternative to SLIME for Common Lips development in Emacs.

SLY is a fork of SLIME and contains the following improvements upon it:

  • Completely redesigned REPL based on Emacs's own full-featured comint.el
  • Live code annotations via a new sly-stickers contrib
  • Consistent interactive button interface. Everything can be copied to the REPL.
  • Doesn't need an extra package to work with company (a popular (code) completion package)
  • Contribs are are enabled by default, and loaded with ASDF on demand
  • Support for NAMED-READTABLES, macrostep.el and quicklisp

SLY tracks SLIME's bugfixes and all its familar features (debugger, inspector, xref, etc...) are still available , but with better integration.

Seems to me SLY is the best way to get started with Common Lisp under Emacs these days, so I encourage people to check it out.

Argentine answered 11/7, 2018 at 11:15 Comment(1)
Let's add that the latest Portacle includes both Slime and Sly.Mismatch
M
4

Emacs is an extensible editor (scriptable in Elisp). Read its documentation.

Its slime-mode (written in Elisp on emacs side, and in Common Lisp on your Lisp system's side) is able to interact with Common Lisp implementations. But you need to install that. Read the documentation of slime. Some Linux distributions are packaging slime (e.g. Debian has some slime package).

Emacs has many other modes (i.e. extensions, provided in Elisp) able to interact with various other programming languages implementations and other applications (shells, email, version control, ...).

BTW, Common Lisp HyperSpec is freely available. Read it. And SBCL is also documented.

You don't need any IDE to use SBCL (or Clisp, or most Common Lisp implementations....). You can use the REPL (inside of emacs or outside of it) and perhaps some editor (e.g. emacs -without even slime-, vim, gedit, ....). When I try some simple code with SBCL, I don't use SLIME (just the REPL, perhaps copy/paste from some editor, and editing a Lisp file then load-ing in Lisp). SLIME is convenient, but is a luxury that you can avoid. However, it is more easy to you to use some editor capable of matching parenthesis (and of skipping lisp comments). But you could code some Common Lisp program -even with many thousands of lines and several dozens of files- even with an editor as simplistic as Notepad on Windows (or Leafpad or nano on Linux). Your editor don't need to "know" Lisp (e.g. have some mode, or some syntactic variant, for it), since lisp syntax is very regular and simple.

Notice that a programming language is a specification (given in some technical report, often in English - the HyperSpec) and should not be confused by its implementation (e.g. some software like SBCL or Clisp).

I actually wrote all my Lisp programs with emacs but without slime. And I developed a Lisp dialect (GCC MELT) and implemented it -it is free software that I abandoned, but you can still download it- with emacs but without using Slime. So Slime is really not a requirement, even to code a Lisp program of dozens of thousands of lines. Slime is a luxury you can avoid. The Lisp-mode of emacs is more than enough (even to code a program of several thousands of Common Lisp lines).

PS. The largest program I have written in Common Lisp was the prebootstrap primordial compiler of GCC MELT, since I bootstrapped GCC MELT I have lost all that large program (because I didn't need it any more). IIRC that thing -prebootstrap MELT- had a dozen of thousands lines of Common Lisp. GCC MELT had more than 120KLOC.

PPS. I actually recommend to not use any IDE in Common Lisp if you are a newbie. Use just the REPL and some editor (and of course a good Common Lisp implementation such as SBCL). Leave slime to Lisp experts. Only start using slime when you are fluent enough in Common Lisp (and its REPL).

Meggs answered 11/7, 2018 at 4:27 Comment(1)
install rlwrap ($ sudo apt install rlwrap) and do $rlwrap sbcl that gives you some clisp-like navigation in terminal for sbclRutaceous
M
2

Well yes, Emacs is the "go to" Common Lisp editor :)

We can still use more editors: https://lispcookbook.github.io/cl-cookbook/editor-support.html Atom and Sublime don't have great support though (no interactive debugger yet, even if it's in development for Atom). Lem is a Common Lisp editor written… in Common Lisp, with also other modes (a Go mode, a directory mode,…). It exists for the console and has an Electron interface.

This is an up to date guide on how to install a Lisp implementation and Quicklisp: https://lispcookbook.github.io/cl-cookbook/getting-started.html (it might not be complete for windows).

Other nice Lisp resources:

Mismatch answered 11/7, 2018 at 10:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.