Where to learn how to practically use Common Lisp

LispCommon Lisp

Lisp Problem Overview


I am a C++ programmer trying to learn Common Lisp. I have looked at some books like Land of Lisp and read numerous online articles about the various virtues of Lisp. However, I need some advice.

Almost everything I have read about Common Lisp has to do with how amazing it is and how amazingly fast you can get stuff done with it and how it amazingly solved many problems with modern programming languages 30 years ago. Also how amazing macros are, and how every every programming paradigm (OO, functional, actor based or whatever, etc) can be used in Lisp, and how lists are the ultimate data structure. Basically treating Lisp like a research language and saying how different and revolutionary it is.

And all that stuff is probably true, but the problem is I haven't seen much stuff how to do practical things like read a file and split it into words and do some processing on it. I'm not interested in learning Common Lisp for the sake of learning Common Lisp, but for the sake of getting thing that I used to do in C++ done faster and with fewer errors.

So my question is what is the best resource (be it a website, book, anything) that focuses on teaching how to use Common Lisp to do common programming tasks like

  • How to read files
  • How to read a file, replace words in the file, and write the result back to the file
  • Iterate the files in a directory and other filesystem stuff
  • Interact with an SQL db
  • Do communications over sockets
  • Threading for stuff like a webserver
  • Create GUIs
  • Perform operations on binary files
  • Write a parser (not an interpreter for Lisp in Lisp, which as I understand is like 5 lines of Lisp)
  • Interact with the operating system (i.e. stuff written in C or C++) to do stuff Lisp can't do natively
  • How to write Lisp extensions in C (is that possible?)
  • Embed a lua interpreter (is that possible?)

And also on a less immediately practical note, how to implement common data structures in lisp such as an heap, stack, binary search tree, etc. However that may be just using Lisp's list operations like car and cdr in the right way. I don't know.

I highly doubt that any of this (with the unlikely exception of the last two in the list) is impossible with Lisp or people wouldn't love it so much. And the aforementioned stuff that I've read mentions plenty of real world software written in Lisp (Yahoo! web store comes to mind).

However, having programming in a (the?) imperative language before, I am anxious to get to using what new knowledge I get to write real-world applications. So what's the quickest way to learn writing practical software with Lisp?

By the way, I have seen Peter Seibel's Practical Common Lisp but, judging by the TOC, it only touches on some of the things I would like to learn to use Lisp to do.

One more question if I may (sorry if this is combining two questions into one), where can I find a reference to Lisp's functions and stuff?

And I really want to like Lisp.

Lisp Solutions


Solution 1 - Lisp

I would propose reading 'Practical Common Lisp', since it already answers some of your questions.

There are probably three to four books you should read:

Common Lisp Reference

Manuals

Now the next thing you should check out is the manual of your Lisp implementation. It describes a lot of specific extensions: networking, threads, ...

Documentation for Common Lisp implementations:

SLIME (the Emacs-based Lisp-IDE) has a SLIME User Manual.

Documentation for Common Lisp libraries:

Libraries

For libraries use

Now looking at some of your points:

  • How to read files

See the files and streams dictionary in the HyperSpec. WITH-OPEN-STREAM, READ, READ-LINE, READ-CHAR, READ-BYTE, READ-SEQUENCE, ...

  • How to read a file, replace words in the file, and write the result back to the file

Use above. See also: WRITE and related.

  • Iterate the files in a directory and other filesystem stuff

See above. DIRECTORY, pathnames, ...

  • Interact with an SQL db

Use for example the CLSQL library.

  • Do communications over sockets

See the manual of your Lisp or use one of the portable libraries. See Quicklisp.

  • Threading for stuff like a webserver

See the manual of your Lisp or use one of the portable libraries. See Quicklisp.

  • Create GUIs

Depends. See Quicklisp or an implementation specific library.

  • Perform operations on binary files

See Hyperspec for file and stream operations. WRITE-BYTE, READ-BYTE. Open a stream as a binary stream.

  • Write a parser (not an interpreter for Lisp in Lisp, which as I understand is like 5 lines of Lisp)

Use one of the existing tools for that. Study existing parsers. There are many parsers written in Lisp, but not much in books about that (other than natural language parsers, which are described in the AI literature).

  • Interact with the operating system (i.e. stuff written in C or C++) to do stuff Lisp can't do natively

Depends. See Quicklisp or an implementation specific library.

  • How to write Lisp extensions in C (is that possible?)

Depends. See Quicklisp or an implementation specific library. -> FFI

Final advice: Read code from other authors.

Study other Lisp code. There is enough very diverse Lisp code out there. From web servers to music composition software.

Solution 2 - Lisp

Check out Cliki the Common Lisp wiki it provides a list of libraries available for Common Lisp which will help you accomplish all your items.

Also, you're going to want to check out the Common Lisp Cookbook (there's also a more updated version). It has a bunch of code for common tasks such as reading a file one line at a time, and Foreign Function Interfaces for interacting with libraries written in C.

You can write extensions for Lisp in C depending on which implementation you're using. Emacs-Lisp for example allows you to do that though it isn't Common Lisp. Usually what you want to do is write the code in Common Lisp and then optimize it as much as possible using different Lisp compiler declarations, or the other method where you use a foreign function interface.

Threading depends on which implementation you use, but I think most of them have threads now.

Hunchentoot is one of the best Lisp web servers and is pretty easy to get started with. You don't have to write any threading code yourself, you just have to write the HTTP request handler functions.

Someone compiled a list of GUI options for Lisp:

  • cl-gtk2, an interface to the GTK gui library
  • McClim
  • Garnet
  • Common Qt
  • EQL

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionNewLisperView Question on Stackoverflow
Solution 1 - LispRainer JoswigView Answer on Stackoverflow
Solution 2 - Lispuser9903View Answer on Stackoverflow