This section describes three ways to turn CLISP programs into executable programs, which can be started as quickly as executables written in other languages.
CONFIG_BINFMT_MISC=y#P".fas"
    and #P".lisp" with CLISP; then you can make the
    files executable and run them from the command line.
 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.
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.
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.
CLISP can be used as a script interpreter under the following conditions:
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.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:
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.
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.
interpreter-arguments.Shebang. The UNIX
 Shebang
 interpreter
 directive consists of one interpreter path and one
 interpreter-arguments string.  This means that if the script
 "my-script.lisp" starts with
 
#!/usr/local/bin/clisp-C-Mmy-image.mem-LFrench
the OS will pass clisp the following two arguments:
"-C -M my-image.mem -L
 French""./my-script.lisp"instead of the six arguments:
"-C""-M""my-image.mem""-L""French""./my-script.lisp"that the similar command line would generate.
Argument Splitting. This means that clisp may need to split its first argument on spaces. In fact, clisp does split its first argument when it starts with a dash.
Scripts named with a leading dash. When executing a script named, say, -leading dash.lisp:
 
$ "-leading dash.lisp" maybe with args
 clisp receives as its first argument either an absolute path
 "/home/you/bin/-leading dash.lisp" or a relative path
 "./-leading dash.lisp" - either way it does not
 start with a dash and thus will not be split.
 If, however, the script is run like this:
 
$ clisp "-leading dash.lisp" args
 the file name argument "-leading dash.lisp"
 will be split into two arguments
 
"-leading""dash.lisp"and will fail. There are two workarounds to this problem:
#! line.LOAD (in particular, the name of the script file, which
   is $0 in /bin/sh, can be found in *LOAD-TRUENAME* and
   *LOAD-PATHNAME*).EXT:*ARGS* is bound
   to a LIST of STRINGs, representing the arguments given to the
   Lisp script (i.e., $1 in /bin/sh becomes (FIRST
     EXT:*ARGS*) etc).stdio.h>)
    are used: *STANDARD-INPUT* is bound to stdin,
    *STANDARD-OUTPUT* to stdout, and *ERROR-OUTPUT* to stderr.
    Note Section 25.2.11.1, “Scripting and DRIBBLE”.ERRORs will be turned into WARNINGs
   (using EXT:APPEASE-CERRORS).ERRORs and Control+C interrupts will
   terminate the execution of the Lisp script with an error status
   (using EXT:EXIT-ON-ERROR).-C to the interpreter-arguments.
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.
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.
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.
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.
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-chello.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.49.93+ | Last modified: 2018-02-19 |