Skip to content
Advertisement

Running LISP code via CLISP on Linux (Ubuntu WSL)

I am new to LISP and was wondering how to correctly run a simple lisp program on Ubuntu Linux. Currently, I have a LISP file called “intmax.lisp” that contains the following code:

(defun intmax (x y) (if (> x y) x y))

However, when I go to the command line and run:

clisp intmax 2 4

To compare 2 and 4, I get no output. Any suggestions as to what I am doing wrong?

Advertisement

Answer

To get started, use the REPL. That is not the shell command line, but rather something like a command line inside of Lisp.

Start the Lisp system:

clisp

You get a prompt like the following:

[1]>

Load your file:

[1]> (load "intmax.lisp")

Now you can call your function:

[2]> (intmax 2 4)

And it will print:

4

And prompt again:

[3]>

You may want to learn about packages and systems later in order to organize your code.

If you want to call things from the command line, you need to tell clisp to load what is needed, then execute a lisp command. Look at the man page for that. Example:

clisp -q -i intmax.lisp -x '(intmax 2 4)'
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement