type: function (subr) location: built-in source file: xlfio.c Common LISP compatible: yes supported on: all machines
(open <file> [ :direction <in-out> ] ) <file> - a string expression or symbol <in-out> - an optional keyword symbol that must either :INPUT or :OUTPUT. The default is :INPUT.
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 form #<File: #99999> is returned as the result. 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.
(setq f (open 'mine :direction :output)); create file MINE (print "hi" f) ; returns "hi" (close f) ; file contains <hi> <NL> (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. So, in UNIX if you do a (open 'foo-file :direction :output), this will create a file named "FOO-FILE" because XLISP uppercases its symbols. If you do a (open "foo-file" :direction :output), this will create a file named "foo-file" because UNIX doesn't uppercase its file names. Another case is if you do (savefun mydefun), this will create the file "MYDEFUN.lsp". 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 COMPATIBILITY: Common LISP supports bidirectional files. So, porting Common LISP code may be difficult to port if it uses these other file types.