Incremental programming style

Discussion of Common Lisp
Post Reply
J.Owlsteam
Posts: 21
Joined: Wed Jul 29, 2015 7:25 am

Incremental programming style

Post by J.Owlsteam » Wed Aug 26, 2015 10:17 am

Hello there :)
I wuold like to pose you a question about the way you use to carry out an incremental programming style with emacs, or in general with the repl... at my very first steps, being used to have a structured-file-to-compile, I asked you how to execute a file from the repl, however after some weeks of little practice, I see that working first with the repl could be quite more enjoyable and productive. So I wuold like to ask you: how do you use to carry out your work? Do you start coding into a file and then loading and testing it from the repl? Or do you code in the repl and then copy and paste it into a file? Or maybe do you have tools that automate these actions for you? That final case wuold be the one of most interest... by the way, what is the strategy you wuold want to suggest?

edgar-rft
Posts: 226
Joined: Fri Aug 06, 2010 6:34 am
Location: Germany

Re: Incremental programming style

Post by edgar-rft » Wed Aug 26, 2015 2:33 pm

The following is not intended to be an "Emacs with SLIME" commercial, but "If you are looking for a good Common Lisp IDE you have the choice between Emacs with SLIME, Emacs with SLIME, and Emacs with SLIME." I would like to give credits to the original author of this citation, but stupidly I have forgotten where I have read it.

When I started with Lisp I used JEdit (a Java-based text editor that I already knew at that time) to write my Lisp code, then I saved the file to disk, and LOADed the file from the Lisp REPL, running in a shell window. Although possible, it was rather tedious to work this way because I had to switch back and forth between the editor and the REPL rather often.

Today, using Emacs with SLIME, there is not much difference between working from a file or in the REPL because the REPL functionality is available in all Common Lisp file buffers (the Emacs window containing the text of the file), where the main differences and advantages of using Emacs and SLIME over JEdit and the REPL are:
  • In an Emacs buffer containing Common Lisp code I can evaluate every single Common Lisp expression without LOADing the file, as if I were in the Common Lisp REPL. This way I can write and test code incrementally and interactively directly from the file buffer without switching to the REPL every time.
  • If an error happens, an additional debugger window appears automatically, showing the backtrace (how the error happened) and all available restarts (how to continue).
  • If my code has produced errors, SLIME underlines the part of the Lisp code that has caused the error, and if I move the mouse pointer over the underlined code, a small tooltip window appears showing the related error message. This way it's dead-easy to see which code has produced what error.
  • SLIME has an integrated debugger and inspector (to investigate all sort of Lisp data at run-time), and a CLOS class browser.
Learning Emacs is a thing of its own. Because Emacs is based on Emacs Lisp (what is older and in some ways different from Common Lisp), most things can be re-programmed at run-time, too. There are Emacs Lisp extensions available that re-program Emacs beyond recognition. SLIME is also not a small Emacs extension, that cannot be learned within five minutes. I started learning Emacs and SLIME more than once until I finally got used to both, but today I think it was very much worth the effort.

Again I'm not such a nerd who thinks that Emacs is the "best text editor ever", but Emacs Lisp is similar to Common Lisp, and I often start prototyping simple things in Emacs Lisp and later switch to Common Lisp (mainly because Emacs Lisp has rather poor math support). Such things are not possible with Vim and slimv. That's not because I think that Emacs is "better" than Vim in all aspects, but Lisp development is easier with Emacs.

Here are some videos for people who want to see Emacs and SLIME in action:
and here is some text:
As a rule of thumb one can say that working with a familiar text editor is good for the beginning, just simply because learning Common Lisp is already complicated enough. As soon as switching back and forth between the editor and the REPL starts to become real pain, it's worth to look at Emacs and SLIME.

- edgar

J.Owlsteam
Posts: 21
Joined: Wed Jul 29, 2015 7:25 am

Re: Incremental programming style

Post by J.Owlsteam » Wed Aug 26, 2015 3:54 pm

Perfect perfect! :) You don't need to convince me as I've already started to use Emacs when I understood what it was... just... I've postponed the time in wich I'll really learn how to use it. Until now I've simply gone having two buffers, one with the repl and the other with a lisp file, so I was searching a way to make the two cooperate. I didn't realize to have all what I need in the SLIME menu :D quite embarassing... but the Tom Briggs video resolved my troubles.
As ever, many thanks! ;)

Post Reply