XLISP load

Nyquist / XLISP 2.0 - Contents | Tutorials | Examples | Reference

# load

Type: | - | function (subr)
Source: | - | xlsys.c, xlread.c

## Syntax

(load file [:verbose v-flag] [:print p-flag]))
  file - a string expression or symbol
  v-flag - an optional key-word expression, default is T
  p-flag - an optional key-word expression, default is NIL
  returns - the filename

## Description

The 'load' function opens the 'file', reads and evaluates all the forms within the 'file'. 'file' may be a string expression or a symbol. When 'file' is a string, you may specify a complete file location or extensions like "/usr/local/bin/myfile.lsp" or "A:\LISP\TIM.LSP". If 'file' is a string and includes a file type or an extension [like ".lsp"], then 'load' accesses the specified file. If there is no extension on 'file', it will add ".lsp". If the ':verbose' keyword is present and 'v-flag' is non-NIL , a load message of the form:

    ; loading "xxxx.lsp"

will be printed to *standard-output*. If the ':print' keyword is present and 'p-flag' is non-NIL , the resulting value of each top-level form in 'file' will be printed to *standard-output*. If the file load was successful, then T is returned as the result. If the file load was not successful, a NIL is returned.

Note: in Nyquist, the XLISP 'load' function first tries to load a file from the current directory. A '.lsp' extension is added if there is not already an alphanumeric extension following a period. If that fails, XLISP searches the path, which is obtained from the XLISPPATH environment variable in Unix and HKEY_LOCAL_MACHINE\SOFTWARE\CMU\Nyquist\XLISPPATH under Win32.

## Examples

    (load 'gloop)                     ; prints  ; loading "GLOOP.lsp"
                                      ; returns NIL   there is no file

    (defun foo (x) (print x))         ; create a function
    (savefun foo)                     ; create a file FOO.lsp

    (load 'foo)                       ; prints  ; loading "FOO.lsp"
                                      ; returns T

    (load 'foo :verbose NIL)          ; no printing   returns T

    (load 'foo :print T)              ; prints  FOO   returns T

    (load 'save :verbose T :print T)  ; prints  ; loading "FOO.lsp"
                                      ; prints  FOO   returns T

    (load "foo")                      ; prints  ; loading "foo.lsp"
                                      ; returns NIL - didn't work
                                      ;   because the file is "FOO.lsp"

    (load "FOO")                      ; prints  ; loading "FOO.lsp"
                                      ; returns T - did work

    (load "FOO.lsp")                  ; prints  ; loading "FOO.lsp"
                                      ; returns T - did work

File names: In the PC and DOS world, all file names and extensions ["foo.bat"] are automatically made uppercase. In using XLISP, this means you don't have to worry about whether the name is "foo.bat", "FOO.BAT" or even "FoO.bAt", they will all work. However, in other file systems [UNIX in particular], uppercase and lowercase do make a difference:

This will create a file named FOO-FILE in UNIX, because XLISP uppercases its symbols:

    (open 'foo-file :direction :output)

This will create a file named 'foo-file' because UNIX doesn't uppercase its file names:

    (open "foo-file" :direction :output)

So, if you are having trouble with opening and accessing files, check to make sure the file name is in the proper case.

Common Lisp: Common Lisp has a 'load' function that is similar to XLISP's 'load'. The only difference is that Common Lisp uses an optional keyword parameter ':if-does-not-exist' which XLISP does not support.

Nyquist: in Nyquist, the XLISP 'load' function first tries to load a file from the current directory. A '.lsp' extension is added if there is not already an alphanumeric extension following a period. If that fails, XLISP searches the path, which is obtained from the XLISPPATH environment variable in Unix and HKEY_LOCAL_MACHINE\SOFTWARE\CMU\Nyquist\XLISPPATH under Win32. [The Macintosh version has no search path.]

Note: In XLISP, the keyword parameters are order sensitive. If both ':verbose' and ':print' keywords are used, ':verbose' must come first.

See the load function in the XLISP 2.0 manual.

Back to Top

Nyquist / XLISP 2.0 - Contents | Tutorials | Examples | Reference