32.6. Quickstarting delivery with CLISP

32.6.1. Summary
32.6.2. Scripting with CLISP
32.6.3. Desktop Environments
32.6.4. Associating extensions with CLISP via kernel

This section describes three ways to turn CLISP programs into executable programs, which can be started as quickly as executables written in other languages.

32.6.1. Summary

UNIX
CLISP can act as a script interpreter.
Desktop environments such as KDE, Gnome, Mac OS X or Win32.
Files created with CLISP can be associated with the CLISP executable so that clicking on them would make CLISP execute the appropriate code.
Linux kernel with CONFIG_BINFMT_MISC=y
Associate the extensions #P".fas" and #P".lisp" with CLISP; then you can make the files executable and run them from the command line.

Multi-file applications

These three techniques apply to a single #P".lisp" or #P".fas" file. If your application is made up of several #P".lisp" or #P".fas" files, you can simply concatenate them (using cat) into one file; the techniques then apply to that concatenated file.

Lisp-less target

These three techniques assume that the target machine has CLISP pre-installed and thus you can deliver just your own application, not CLISP itself. If you want to deliver applications without assuming anything about your target box, you have to resort to creating executable memory images.

32.6.2. Scripting with CLISP

Platform Dependent: UNIX platform only.

On UNIX, a text file (#P".fas" or #P".lisp") can be made executable by adding a first line of the form

#!interpreter [interpreter-arguments]

and using chmod to make the file executable.

OS Requirements. CLISP can be used as a script interpreter under the following conditions:

  • The interpreter must be the full pathname of CLISP. The recommended path is /usr/local/bin/clisp, and if CLISP is actually installed elsewhere, making /usr/local/bin/clisp be a symbolic link to the real CLISP.
  • The interpreter must be a real executable, not a script. Unfortunately, in the binary distributions of CLISP on Solaris, clisp is a shell script because a C compiler cannot be assumed to be installed on this platform. If you do have a C compiler installed, build CLISP from the source yourself; make install will install clisp as a real executable.
  • On some platforms, the first line which specifies the interpreter is limited in length:

    • max. 32 characters on SunOS 4,
    • max. 80 characters on HP-UX,
    • max. 127 characters on Linux.

    Characters exceeding this limit are simply cut off by the system. At least 128 characters are accepted on Solaris, IRIX, AIX, OSF/1. There is no workaround: You have to keep the interpreter pathname and arguments short.

  • On Solaris and HP-UX, only the first interpreter-arg is passed to the interpreter. In order to pass more than one option (for example, -M and -C) to CLISP, separate them with no-break spaces instead of normal spaces. (But the separator between interpreter and interpreter-arguments must still be a normal space!) CLISP will split the interpreter-arguments both at no-break spaces and at normal spaces.

Script execution. 

If nothing works. Another, quite inferior, alternative is to put the following into a file:

#!/bin/sh
exec clisp <<EOF
(lisp-form)
(another-lisp-form)
(yet-another-lisp-form)
EOF

The problem with this approach is that the return values of each form will be printed to *STANDARD-OUTPUT*. Another problem is that no user input will be available.

32.6.3. Desktop Environments

Platform Dependent: Win32, Gnome, KDE, Mac OS X desktop platforms only.

Notations

Although we use Win32-specific notation, these techniques work on other desktop environments as well.

There are two different ways to make CLISP executables on desktop platforms.

  1. Associate the #P".mem" extension with c:\clisp\clisp.exe -M "%s".
  2. Associate the #P".fas" extension with c:\clisp\clisp.exe -i "%s" Alternatively, you may want to have a function main in your #P".fas" files and associate the #P".fas" extension with c:\clisp\clisp.exe -i %s -x (main).

Then clicking on the compiled lisp file (with #P".fas" extension) will load the file (thus executing all the code in the file), while the clicking on a CLISP memory image (with #P".mem" extension) will start CLISP with the given memory image.

Note

On Win32, CLISP is distributed with a file src/install.bat, which runs src/install.lisp to create a file clisp.lnk on your desktop and also associates #P".fas", #P".lisp", and #P".mem" files with CLISP.

32.6.4. Associating extensions with CLISP via kernel

Platform Dependent: Linux platforms only.

You have to build your kernel with CONFIG_BINFMT_MISC=y and CONFIG_PROC_FS=y. Then you will have a /proc/sys/fs/binfmt_misc/ directory and you will be able to do (as root; you might want to put these lines into /etc/rc.d/rc.local):

# echo ":CLISP:E::fas::/usr/local/bin/clisp:" >> /proc/sys/fs/binfmt_misc/register
# echo ":CLISP:E::lisp::/usr/local/bin/clisp:" >> /proc/sys/fs/binfmt_misc/register

Then you can do the following:

$ cat << EOF > hello.lisp
(print "hello, world!")
EOF
$ clisp -c hello.lisp
;; Compiling file hello.lisp ...
;; Wrote file hello.fas
0 errors, 0 warnings
$ chmod +x hello.fas
$ hello.fas

"hello, world!"

Please read /usr/src/linux/Documentation/binfmt_misc.txt for details.


These notes document CLISP version 2.49Last modified: 2010-07-07