Developing a Lisp

Over the last thirty-odd years I have worked with many programming languages including BASIC, Pascal, C, C++, Python and Java. One I had heard about, but never had to deal with is Lisp. Recently I have been reading Metamagical Themas by Douglas R. Hofstadter, who also wrote Gödel, Escher, Bach. I found this book in a charity shop.

Book

This is a compendium of columns he wrote for Scientific American in the 80s. It ranges over subjects from Rubik's Cube to self-describing sentences. It also has a couple of chapters on Lisp and these inspired me to try coding with this old language that dates back to the 50s. I like that it is a very consistent language. Everything is a list and can contain further listed nested within it. This does result in lots of brackets/braces.

This is SBCL 2.0.1.debian, an implementation of ANSI Common Lisp.
More information about SBCL is available at <http://www.sbcl.org/>.

SBCL is free software, provided as is, with absolutely no warranty.
It is mostly in the public domain; some portions are provided under
BSD-style licenses.  See the CREDITS and COPYING files in the
distribution for more information.
* (+ 2 4)
6
* (+ 3 5 7)
15
* (car (reverse (list 1 2 3 4 5)))        
5
* (defun rac (l) (car (reverse l)))
RAC
* (rac (list 4 5 6 7 8))
8
* 

As with languages like BASIC and Python you can enter lines or expressions and get immediate results as well as storing programs in files. I installed this version of Common Lisp on Ubuntu Linux. This seems to have some differences to the version in the book as to what functions are available. It is possible to create new functions that would recreate these, e.g. Common Lisp has the (+ a b) function, but the book uses (add a b). We can define that missing function:

0] (defun add (a b) (+ a b))
; No debug variables for current frame: using EVAL instead of EVAL-IN-FRAME.
ADD
0] (add 2 4)
; No debug variables for current frame: using EVAL instead of EVAL-IN-FRAME.
6
0] 

I am still working out what the messages you get mean. Some errors give lots of lines of error text that is not too readable. I expect there are ways to deal with that. The way functions and variables are defined is different to the book too.

I am looking at some other tutorials such as Lisp Koans and The CL Cookbook.

I am not sure when I would use Lisp, but understanding the different features of various languages can give you insights that can be applied elsewhere. Lisp is used as a scripting language for some applications. It has been used a lot in artificial intelligence, which I expect is where Hofstadter used it. Having extra tools in your toolbox is generally a good thing.

I am only playing with trivial examples for now. I need to find some real world use cases to work on.

Code hard!

H2
H3
H4
3 columns
2 columns
1 column
Join the conversation now
Logo
Center