Running MzScheme

The stand-alone version of MzScheme accepts a number of command-line flags.

MzScheme accepts the following flags:

17.1  Flag Conventions

Extra arguments following the last flag are available from the current-command-line-arguments parameter (see section as an immutable vector of immutable strings. The name used to start MzScheme is available from the find-system-path procedure (see section 11.3.2) using 'exec-file. In addition, unless -A is specified, the argument vector is put into the global variable argv, and the name used to start MzScheme is put into the global variable program as an immutable string.

Multiple single-letter flags (the ones preceded by a single dash) can be collapsed into a single flag by concatenating the letters, as long as the the first flag is not --. The arguments for each flag are placed after the collapsed flags (in the order of the flags). For example,

   -vfme file expr


   -v -f file -m -e expr

are equivalent. If a collapsed -- appears before other collapsed flags, it is implicitly moved to the end of the collapsed set.

17.2  Executable Name

If the MzScheme executable is given a name of the form scheme-dialect, then the command line is effectively prefixed with

   -qAeC '(require (lib "" "script-lang" "dialect"))'

The first actual command-line argument thus serves as a file to load. The file is loaded into a namespace that is initialized by the dialect-specific library. The loaded file should define main, which is called with command-line arguments -- starting with the loaded file name -- as a list of immutable strings.

17.3  Initialization

The current-library-collection-paths parameter is initialized (as described in Chapter 16) before any expression or file is evaluated or loaded, unless the -x or --no-lib-path flag is specified.

Unless the -q or --no-init-file flag is specified, a user initialization file is loaded after current-library-collection-paths parameter is initialized and before any other expression or file is evaluated or loaded. The path to the user initialization file is obtained from MzScheme's find-system-path procedure using 'init-file.

Expressions and files are evaluated and loaded in order that they are provided on the command line, including calls to main implied by --main, embeddings loaded by -k, and so on. If an uncaught exception occurs, the remaining expressions and files are skipped. The thread that loads the files and evaluates the expressions is the main thread. When the main thread terminates (or is killed), the MzScheme process exits.

After the command-line files and expressions are loaded and evaluated, the main thread calls read-eval-print-loop, unless the -v, --version, -r, --script, -i, or --script-cd flag is specified.

The exit status for the MzScheme process indicates an error if an error occurs evaluating or loading a command-line expression or file and read-eval-print-loop is not called afterwards, or if the default exit handler is called with an exact integer between 1 and 255.