XLISP open

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

# open

Type: | - | function (subr)
Source: | - | xlfio.c

## Syntax

(open file [:direction in-out])
  file - a string expression or symbol
  in-out - an optional keyword symbol that must be either ':input' or ':output'. The default is ':input'.
  returns - a stream

## Description

The 'open' function opens the 'file' for input or output. The 'file' may be a string expression or a symbol. Following the 'file', there is an optional keyword, ':direction'. The argument following this is either ':input' or ':output' which specifies the direction of the file. If no ':direction' is specified, the default is ':input'. When 'file' is a string, you may specify a complete file location or extensions like "/usr/local/bin/myfile.lsp" or "A:\LISP\TIM.BAT". If the file open was successful, then a file pointer of the following form is returned as the result:

    #<File: #99999>

If the file open was not successful, a NIL is returned. For an input file, the file has to exist, or an error will be signaled.

## Examples

    (setq f (open 'mine :direction :output))  ; create file named MINE
    (print "hi" f)                            ; returns "hi"
    (close f)                                 ; file contains "hi" <newline>
    (setq f (open 'mine :direction :input))   ; open MYFILE for input
    (read f)                                  ; returns "hi"
    (close f)                                 ; close it

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 supports bidirectional files. So, porting Common Lisp code may be difficult to port if it uses these other file types.

See the open function in the XLISP 2.0 manual.

Back to Top

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