32.5. Quickstarting delivery with CLISP
Prev | Chapter 32. Platform Specific Extensions | Next

## 32.5. Quickstarting delivery with CLISP

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.5.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.5.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.

- The script should contain Lisp forms, except in the `#!` line.
- The file is loaded normally, through the function `LOAD` (in particular, the name of the script file, which is `$0` in /bin/sh, can be found in `*LOAD-TRUENAME*` and `*LOAD-PATHNAME*`).
- Before it is loaded, the variable `EXT:*ARGS*` is bound to a `LIST` of `STRING`s, representing the arguments given to the Lisp script (i.e., `$1` in /bin/sh becomes `(`FIRST` `EXT:*ARGS*`)` etc).
- The standard UNIX i/o facilities (see <`stdio.h`>) are used: `*STANDARD-INPUT*` is bound to `stdin`, `*STANDARD-OUTPUT*` to `stdout`, and `*ERROR-OUTPUT*` to `stderr`. Note Section 25.2.10.1, “Scripting and `DRIBBLE`”.
- The continuable `ERROR`s will be turned into `WARNING`s (using `EXT:APPEASE-CERRORS`).
- Non-continuable `ERROR`s and Control+C interrupts will terminate the execution of the Lisp script with an error status (using `EXT:EXIT-ON-ERROR`).
- If you wish the script's contents to be compiled during loading, add `-C` to the `interpreter-arguments`.

See also the manual.

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.5.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.5.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.lisp
    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.45 | Last modified: 2008-05-14

Enter your search termsSubmit search form
Webclisp.cons.orgclisp.podval.orgwww.lisp.org

Prev | Up | Next
32.4. Socket Streams | Home | 32.6. Shell, Pipes and Printing