1.5

Updates:
  1. none

LISP Programming

Elliott—Artificial Intelligence

Copyright 2021 Clark Elliott All rights reserved


Getting ABCL LISP running on your computer:

  1. Install Java on your computer. Note: we will NOT be programming in Java for LISP clsses. But we need Java installed to support ABCL LISP.

  2. Download the Armed Bear Common Lisp (ABCL) java JAR file (See below, under Resources.) With Java and this JAR (Java Archive File) file you have everything you need to run LISP.

  3. Rename the abcl-bin-1.3.3.jar (or similar) file to ablc.jar for convenience (or not, if you know what you are doing).

  4. Put the abcl.jar file in the directory where you are developing your LISP code.

  5. Open a command shell or terminal window.

  6. Start the LISP environment by executing the command java -jar abcl.jar.

  7. Type (+ 20 3) into the LISP command prompt. If it types 23 back to you, everything is working. Good job, you are running LISP!

Setting up ABCL in a more advanced way:

Mac users read this to learn about setting your default prompt and using Symbolic Links.
  1. Create a shell script / Windows bat file to run ABCL for you no matter what directory you are in. Here is an example aa.bat executable Windows batch script file:
    
    Rem This is aa.bat for running ABCL common lisp
    java -jar C:\ABCL\abcl-bin-1.3.3\abcl.jar
    
  2. Put aa.bat in a directory that is in your execution path so that it is accessible from any command prompt. (In Windows, you can find all of the directories in your path by typing "path" at a command prompt.)

  3. When you type aa.bat at a command prompt you should now see something like:

    c:\abcl\abcl-bin-1.3.3>java -jar abcl.jar
    java -jar abcl.jar
    Armed Bear Common Lisp 1.3.3
    Java 1.8.0_181 Oracle Corporation
    Java HotSpot(TM) 64-Bit Server VM
    Low-level initialization completed in 0.238 seconds.
    Startup completed in 3.41 seconds.
    Type ":help" for a list of available commands.
    CL-USER(1): 
    
Note that there are many versions of Common LISP that will run on your computer. ABCL is only one of them. It is free, it is convenient, and it runs on top of Java so it will run anywhere. Most LISP programs will run the same in any version of Common LISP, though extensions (such as for graphics, networking, and multi-threading) may have to be adapted.


Running LISP programs

Our program, stored in MyFile.lisp:
(defun MyFunction (n) (format t "You typed the number ~a~%" n)) 
At the LISP prompt:
CL-USER(3): (load "MyFile.lisp")
T
CL-USER(4): (MyFunction 23)
You typed the number 23
NIL
CL-USER(5): 
If you make a mistake and get an error message like the following, return to the top level using the number indicated:
CL-USER(6): (MyFunction)
#: Debugger invoked on condition of type PROGRAM-ERROR
  Wrong number of arguments for #; 1 expected -- provided: NIL.
Restarts:
  0: TOP-LEVEL Return to top level.
[1] CL-USER(7): 0
CL-USER(8):

LISP compatible text editors

All students should know how to edit plain text files on their computer. Basic operating system configuration files require that you know how to edit and save text files.

To program in LISP (and to do many other very useul things on computers) you need an editor that can read and write simple text files. For very simple programming you can use the existing text editors that are already installed on Windows, Mac and Unix. It will be extremely helpful, however, if your editor helps you to indent and to balance parentheses, such as is provided by the easy-to-learn Atom editor. For advanced LISP development, or if you are going to use Linux, you will probably want to install and learn emacs.

Word-processing editors like Word and Pages have all sorts of behind-the-scenes formatting characters which cause programs to blow up. For writing programs you need a simple text editor that shows you exactly everything that is going into the file.

Example: When you write "Hello" into a text file, that is exactly what it has in it: five characters from the alphabet. When you write "Hello" in a Word document, it actually saves:


0000 0000 0000 0000 00b4 94cb 6ec2 3010  .........
00000240: 45f7 95fa 0f91 b755 62e8 a2aa 2a02 8b3e 
00000250: 962d 52e9 0718 7b02 56fd 92c7 bcfe be13 
00000260: 0251 5501 910a 6c22 2533 f7de 3356 c683 
[Etc. for another 120 lines...]

So you can see why programs written in a word processor blow up!

  • Atom runs on Windows, Mac and Linux. With it you can easily edit plain text files. It will balance your parentheses and indent for you, which makes things MUCH easier when developing LISP programs. For students who do not plan on doing much programming this is a good option because (a) it is powerful enough, and (b) the learning curve is not steep.

  • For programmers, you can probably use your IDE editor for one language or another. Eclipse, Intellij, and so on are all powerful enough, and will allow you to edit text files.

  • For students who plan on using computers in their education and career, Emacs is the native editor for working with LISP. In fact, it is largely written in LISP. It runs on every operating system, and for people like me it is the preferred editor for everything because it is extremely efficient. I use it all day on Windows, Mac and Unix. However, there is a steeper learning curve. I provide help pages for installing Emacs and for configuring it in a way that makes it much easier to use: See Emacs at DePaul to get started with a very powerful editor that works natively with LISP. (I strongly recommend that you use my .emacs startup initialization file to start.) If you are going to develop advanced programs in LISP (or are going to be working on Linux) I recommend learning emacs. If you are only going to write a couple of simple assignments in LISP I recommend using one of the other options instead. However, note that I have taught many non-programmers to use emacs and have heard from many that this has remained as their preferred editor for years (and even decades).

  • Notepad++ runs natively on Windows (Windows key | Notepad++). Be SURE you are using the ++ version which balances parentheses. In theory there is a way to set up auto-indent to work, but I haven't figured it out. It does give you a minimal bit of help with indentation with some shadow guide lines. When you use File | Save As you MUST put double quotes around your file name "MyFile.lisp" otherwise Notepad++ will save it as "MyFile.lisp.txt".

  • ne ("nice editor") is an extremely basic text editor that runs on Mac and Unix. It's only feature is that you can actually edit text files and that it takes three minutes to figure out how to load and save files. Beyond that, it will give you no help whatsoever.

  • TextEdit runs on the Mac. It provides no help with parentheses but is more powerful than ne. BUT you must always tell it to save your program files as TEXT. To do this on the Mac use: Format | Make Plain Text before you save. Warning: you will have to spend some time getting the settings right: (a) save as a plain text file, (b) Don't add ".txt" to the end of files you save. (c) change the name of the file by hovering the mouse over the existing name. (d) etc.

  • Sublime Text Editor also has good reviews, though I have not tested it.

  • I believe that the Eclipse (with plugin) and IntelliJ IDE environments work with LISP, but I have not used them myself. You will have to configure them. (Generally this is for programers.)

  • Some students have successfully used Visual Studio

  • Send me other suggestions and I will add them here.
Use the ".lisp" file extensions for your LISP files.

LISP resources

Download Armed Bear Common LISP (ABCL):
  • abcl.jar ←Not current but should be fine for class.
  • Latest version . ←You want the "bin" file, not the "contrib" file. Includes ABCL manual. After download, rename the file to abcl.jar
For our class purposes, you can directly download an abcl.jar file that contains a slightly older version of Armed Bear Common LISP (known as ABCL). Or, you can download the latest version of ABCL ABCL runs in the Java virtual machine. If you download the latest version you want the "bin" file not the "contrib" file. This download will also include the ABCL manual.

If you are having any trouble, you can get Extended Help with setting up LISP, directories, paths, manipulating file systems, using Windows and Mac operating systems and integrating LISP with Emacs.

If you know the name of the Lisp function, just use Google to search for it to get usage help: e.g.: "lisp defun"

Some Online LISP manuals and books: