FunctionPackage: systemToCDocOverviewCGDocRelNotesFAQIndexPermutedIndex
Allegro CL version 10.0
Unrevised from 9.0 to 10.0.
9.0 version

command-line-argument-count

Arguments: &key application

This function and its relatives, command-line-arguments and command-line-argument-count provide information about the command line that invoked Allegro CL. Their precise behavior depends on the value of the application keyword argument.

The command line includes the following, in the order specified:

  1. The executable name. This may include directory information (i.e. /usr/local/acl/mlisp) or may not (just mlisp).
  2. Command-line arguments prefixed by a +. these are used on Windows only.
  3. command-line arguments prefixed by a - and, when appropriate, the values of those arguments.
  4. the special marker -- (a double dash).
  5. any arguments whatsoever that follow the double-dash.

See Command line arguments in startup.htm for a list of command-line arguments accepted by Allegro CL.

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:

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:

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

(translate-logical-pathname (concatenate 'string "sys:"
(sys:command-line-argument 0)))

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-2019, Franz Inc. Oakland, CA., USA. All rights reserved.
This page was not revised from the 9.0 page.
Created 2015.5.21.

ToCDocOverviewCGDocRelNotesFAQIndexPermutedIndex
Allegro CL version 10.0
Unrevised from 9.0 to 10.0.
9.0 version