When the value of the :application keyword argument is true

The application arguments are the executable name (number 1 in the
list above) and the ones which follow the double dash (number 5 in the
list above). Consider that those arguments are collected as strings in
a list called the
list-of-application-arguments. When
application is true (it defaults to t), the command-line argument information functions
behave as follows:

command-line-argument with
argument n returns the (0 based) nth element of
the list-of-application-arguments. It is an error
to specify a value for n equal to or greater than the length of
list-of-application-arguments.

Examples when :application is true

;; Lisp was started on UNIX with the command line
;; (we assume the mlisp executable is in a directory
;; included in the PATH environment variable):
% mlisp -qq -- init 5 safe
(sys:command-line-argument-count :application t)
RETURNS 4
(sys:command-line-argument-count) ;; :application defaults to T
RETURNS 4
(sys:command-line-arguments)
RETURNS ("mlisp" "init" "5" "safe")
;; or perhaps (/usr/local/acl70/mlisp init 5 safe)
;; assuming mlisp is in /usr/local/acl70/: the directory
;; may or may not be included.
(sys:command-line-argument 0)
RETURNS "mlisp" ;; or perhaps "/usr/local/acl70/mlisp"
(sys:command-line-argument 1)
RETURNS "init"
(sys:command-line-argument 2)
RETURNS "5"
(sys:command-line-argument 3)
RETURNS "safe"
(sys:command-line-argument 4)
ERROR ;; the first argument to sys:command-line-argument
;; must be less than the number of arguments
;; as returned by sys:command-line-argument-count
;; Lisp was started on WINDOWS with the command line
% mlisp.exe +co -qq -- init 5 safe
;; The values returned by the command-line argument functions are the
;; same as on UNIX (except "mlisp.exe" or
;; "C:\\Program Files\\acl70\\mlisp.exe" replaces "mlisp" or
;; "/usr/local/acl70/mlisp".

When the value of the :application keyword argument is nil

All arguments except those beginning with + are considered
command-line arguments by these functions when
application is nil. That
includes the executable name (number 1 in the list above), the -
arguments and their values (number 3 in the list above), the double
dash (number 4 in the queue above), and arguments which follow the
double dash (number 5 in the list above). Consider that those
arguments are collected as strings in a list called the
list-of-arguments. When
application is nil, the
command-line argument information functions behave as follows:

command-line-argument with
argument n returns the (0 based) nth element of
the list-of-arguments. It is an error to specify a
value for n equal to or greater than the length of
list-of-arguments. Note the + arguments are ignored
and will not be returned for any value of n. The
double dash, if present, is considered and will be returned for some
value of n.

command-line-arguments
returns the list list-of-arguments. Note the +
arguments are ignored and thus not included, while the double dash, if
present, is included.

command-line-argument-count returns the
length of the list list-of-arguments. Note the +
arguments are ignored and thus not counted, while the double dash is
counted as an argument.

Examples when :application is nil

;; Lisp was started on UNIX with the command line
;; (we assume the mlisp executable is in a directory
;; included in the PATH environment variable):
% mlisp -qq -- init 5 safe
(sys:command-line-argument-count :application nil)
RETURNS 6
(sys:command-line-arguments :application nil)
RETURNS ("mlisp" -qq -- "init" "5" "safe")
;; or perhaps (/usr/local/acl70/mlisp -qq -- init 5 safe)
;; assuming mlisp is in /usr/local/acl70/: the directory
;; may or may not be included.
(sys:command-line-argument 0)
RETURNS "mlisp" ;; or perhaps "/usr/local/acl70/mlisp"
(sys:command-line-argument 1)
RETURNS "-qq"
(sys:command-line-argument 2)
RETURNS "--"
(sys:command-line-argument 3)
RETURNS "init"
(sys:command-line-argument 4)
RETURNS "5"
(sys:command-line-argument 5)
RETURNS "safe"
(sys:command-line-argument 6)
ERROR ;; the first argument to sys:command-line-argument
;; must be less than the number of arguments
;; as returned by sys:command-line-argument-count
;; Lisp was started on WINDOWS with the command line
% mlisp.exe +co -qq -- init 5 safe
;; The values returned by the command-line argument functions are the
;; same as on UNIX (except "mlisp.exe" or
;; "C:\\Program Files\\acl70\\mlisp.exe" replaces "mlisp" or
;; "/usr/local/acl70/mlisp". The command-line argument functions
;; always ignore the + arguments.

Anomolies when :application is true

If the Allegro CL image was created with dumplisp (or build-lisp-image or generate-application) with the
ignore-command-line-arguments argument
true (the default is nil), then arguments are not processed by Allegro CL
when it starts up and all arguments (regardless of whether a `--'
appears on the command line) are handled by these functions and the
value of the application keyword argument has no
effect.

Anomolies when :application is nil

The system may tack on arguments in addition to those you
specified. In particular, when using the Emacs-Lisp interface, the
arguments -e (start-emacs-lisp-interface t) may be
added (to start in connection between Lisp and Emacs). Do not be
surprised is you see these additional arguments. The system never adds
arguments after a -- (double dash).

The path of the executable

Note that the zeroth argument is the name of the executable as entered
in the command line, with or without path information. That is, the
0th argument may be, say, "mlisp" (without path information) or may
be, say, "/usr/local/acl70/mlisp" (with path information). If path
information is not provided and you need it, evaluating

will typically work. (But that form signals an error when path
information is provided.)

Uses of command-line arguments

You may use this information as you see fit. One possible use, for
example, is to have some function defined and run (perhaps in the
initialization file .clinit.cl) which takes some action (such
as loading specific files) based on the values of the
arguments. Recall again that + arguments are ignored and so their
presence or absence cannot be used to affect behavior once Lisp has
started.

Copyright (c) 1998-2012, Franz Inc. Oakland, CA., USA. All rights reserved.Documentation for Allegro CL version 9.0. This page was not revised from the 8.2 page.Created 2012.5.30.