Lisp Programming with Cusp - Getting Started: Your First Lisp Program

Creating Lisp Project

Writing Code and Basic Navigation

Open file main.lisp and scroll to the end of the file. For now ignore the code that the wizard has generated. Type opening bracket '(' and notice how Cusp automatically inserts closing bracket. Lisp code contains many brackets and Cusp has many features dealing with bracketed expressions (s-expressions). This behavior is optional and can be customized in Cusp preferences:

Continue typing '(defun)':

If you now press space bar the code automatically expanded (AutoEdit) and argument tip is shown:

The AutoEdits are customizable in preferences on AutoEdits page. Continue entering code as follows:


Save the file (Ctrl+S). As file is saved your new code is immediately compiled. You can check this by typing in lower part of REPL (f) and pressing Ctrl+Enter or clicking on Send button:



The result is displayed in upper part of REPL:



The function f is defined in package new-lisp1. To see this change package to default CL-USER by first clicking on 'Change package' button:

And then selecting package CL-USER:

Note: the other way to change package is evaluating (in-package 'cl-user) in REPL.
From other packages the function f from new-lisp1 is called by (new-lisp1::f). Notice '::' - this means that the function is internal to the package. To export the function f from the package new-lisp1 do the following (these operations are overkill for such a short source code, but they show important navigation features of Cusp IDE):





Quitting And Restarting


Once you tired of coding you will want to close Eclipse. Go ahead and just close it, you don't need to do anything special to your Lisp session.

To get back to your code, open Eclipse, then make sure that you are in Lisp Perspective, if not select it. Before you can continue coding your program, you need to load it. To do this, right click any project file or folder project and select Load Project :



This will compile and load all files for your project, and also will change REPL to your package. You can check this by running (f)

Building Executable


One often asked question by people starting learning Lisp is "How do I create executable?" The answers to this question that can be found on the net are not very useful, since traditionally Lisp programs are executed inside Lisp image (virtual machine) and experts don't see use of executables. However, since this is a very common question, Cusp provides very simple means of creating single executable file from your Lisp code (this feature currently works only with SBCL).

Before you can create executable you need to define a top level form: this is a function that doesn't take arguments and returns integer (0 if success). This top level form is the entry point to your program (function that is called first when executable starts).

By default the 'New Lisp Project' wizard creates example function that can be used as a top level form 'main' (it also shows how to pass arguments into Lisp program).

Let's crate an executable that uses the function generated by the wizard. To do this, right click on any file in the project or its folder and select 'Create Exe':


This brings up 'Create Executable' wizard. Adjust path where you want executable to be created and press 'Finish':


After executable is created it can be run from shell (notice that I redirect stderr to null, since I don't want to see starting warning message from SBCL running on Windows):


Note: The executable is about 20MB large because it contains whole Lisp system including compiler and debugger. If Lisp is already installed on the system it is possible to create executable script. This feature is not yet provided by Cusp. See cl-launch.

Back to table of contents