Next: , Previous: Introduction, Up: Top


2 Interpreter

This section describes the klisp, a Kernel Programming Language stand-alone interpreter.

2.1 Invocation

klisp is invoked like this:

     klisp [options] [script]

2.2 Description

klisp is a stand-alone klisp interpreter for the Kernel Programming Language. It loads and evaluates Kernel programs in textual source form. klisp can be used as a batch interpreter and also interactively. The given options (see Command Line Options) are evaluated and then the klisp program in file script is loaded and evaluated. All evaluations mentioned, including the initialization that is described below, take place in the same (initially) standard environment. All values that result from these evaluation are discarded, but if the root-continuation or error-continuation are passed a value, the evaluation of options is interrupted and klisp terminates. See Exit Status, for a description of the exit status in each case.

The string script together with all arguments are available as a list of strings via the applicative get-script-arguments. If these arguments contain spaces or other characters special to the shell, then they should be quoted (but note that the quotes will be removed by the shell). The complete command line, including the name of the interpreter, options, the script, and its arguments are available as a list of strings via the applicative get-interpreter-arguments.

At the very beginning, before even handling the command line, klisp reads and evaluates the contents of the environment variable KLISP_INIT, if it is defined. To use an init file, just define KLISP_INIT to the following form: (load "/path/to/init-file"). Notice that klisp expects exactly one expression in KLISP_INIT, if it is defined. So it is an error to have no expressions or more than one in KLISP_INIT. The same is true of the argument to the -e option, as both are implemented in terms of string-eval.

In interactive mode, klisp prompts the user, reads expressions from the standard input, and evaluates them as they are read. The default prompt is "klisp> ".

2.3 Options

Options start with - and are described below. You can use -- to signal the end of options. If no arguments are given, then -v -i is assumed when the standard input is a terminal; otherwise, - is assumed. If no script, or option -e or -l is given, -i is assumed.

-
load and execute the standard input as a file, that is, not interactively, even when the standard input is a terminal. .TP
-e expr
evaluate expression expr. You need to quote expr if it contains spaces, quotes, or other characters special to the shell.
-i
enter interactive mode after script is executed.
-l name
evaluate (load "name") before script is executed. Typically used to do environment initialization.
-r name
evaluate (require "name") before script is executed. Typically used to load libraries.
-v
show version and copyright information.

2.4 Exit Status

If the script or stdin reach EOF or if there is no script, EXIT_SUCCESS is returned. If the error-continuation is passed an object during init, arguments or script evaluation EXIT_FAILURE is returned. If the root-continuation is passed an object, klisp tries to convert the value passed to the root-continuation to an exit status as follows:

integer
If the value is an integer it is used as exit status.
boolean
If the value is a boolean then EXIT_SUCCESS is returned for #t and EXIT_FAILURE for #f.
inert
If the value is inert, then EXIT_SUCCESS is returned.
else
In any other case EXIT_FAILURE is returned.

2.5 Environment Variables

The following environment variables affect the behaviour of klisp

KLISP_INIT
A Kernel expression to be evaluated before any arguments to the interpreter. To use an init file, just define KLISP_INIT to the following form (load "/path/to/init-file")
KLISP_PATH
A semicolon separated list of templates for controlling the search of required files. Each template can use the char ? to be replaced by the required name at run-time.