Up: Echo1   [Index]


1.2.1.1 CL Echo1

CCL can be run directly from a terminal prompt. CCL needs to know where the ccl directory is, and uses the environment variable ‘CCL_DEFAULT_DIRECTORY’ to locate it, i.e.

export CCL_DEFAULT_DIRECTORY=/path/to/ccl

A script named ‘$CCL_DEFAULT_DIRECTORY/scripts/ccl’ can be placed into your path whose purpose is to make sure this default directory is properly set, and to invoke the ccl binary.

CCL has a number of command-line options, including ‘-e, --eval’, which will execute some code. Any arguments following the pseudo-argument ‘--’ are not processed, and are made available to Lisp as the value of ‘*unprocessed-command-line-arguments*’.

The easiest way to create a command-line script is to run a shell script which exec’s a call to the ccl binary with one or more ‘--eval’ arguments (the last of which should be the quit command (quit)), followed by the pseudo-element ‘--’ and the command-line arguments ‘$@’.

Common Lisp has three forms of the do structured iteration command:

  1. do
  2. dolist
  3. dotimes

two loop statements:

  1. simple loop
  2. extended loop

and several prog statements:

  1. prog
  2. prog1
  3. prog2
  4. progn

This implementation uses dotimes, which is similar to the Go version using a for-loop that loops over the length of the command-line arguments beginning at zero through ‘length - 1’. It also implements the same string-building construct using string concatenation, and the sep variable that is initially empty, and then is set to a space at the end of the first iteration.

exec ccl --eval '
     (let ((l *unprocessed-command-line-arguments*) s sep)
        (dotimes (i (length l) (prin1 s))
                 (setq s (concatenate (quote string) s sep (string (elt l i))))
                 (setq sep " ")))' \
         --eval '(quit)' \
         -- "$@"

Listing 1.7: cl/ch1/echo1


Up: Echo1   [Index]