[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

keyword pairs and OPEN



Speaking of OPEN being the biggest thorn, I owe you a proposal.  Here it
is.

OPEN takes a filename as its first argument.  The rest of its arguments
are keyword/value pairs.

WITH-OPEN-STREAM's first subform is a list of a variable (to be bound to
a stream), a filename, and the rest of the elements are keyword/value
pairs.

The keywords are as follows, with their possible values and defaults:

:DIRECTION	:INPUT (the default), :OUTPUT, :APPEND, :OVERWRITE, :PROBE
	:INPUT - The file is expected to exist.  Output operations are not allowed.
	:OUTPUT - The file is expected to not exist.  A new file is created.  Input
			operations are not allowed.
	:APPEND - The file is expected to exist.  Input operations are not allowed.
			New characters are appened to the end of the existing file.
	:OVERWRITE - The file is expected to exist.  All operations are allowed.
			The "file pointer" starts at the beginning of the file.
	:PROBE - The file may or may not exist.  Neither input nor output operations
			are allowed.  Furthermore, it is not necessary to close the stream.

:CHARACTERS	T (the default), NIL, :DEFAULT
	T - Open the file for reading/writing of characters.
	NIL - Open the file for reading/writing of bytes (non-negative integers).
	:DEFAULT - Let the file system decide, based on the file it finds.

:BYTE-SIZE	a fixnum or :DEFAULT (the default)
	a fixnum - Use this byte size.
	:DEFAULT - Let the file system decide, based on the file it finds.

:IF-EXISTS	:ERROR (the default), :NEW-VERSION, :RENAME,
		:RENAME-AND-DELETE, :OVERWRITE, :APPEND, :REPLACE
	Ignored if direction is not :OUTPUT.  This tells what to do if the file
	that you're trying to create already exists.
	:ERROR - Signal an error.
	:NEW-VERSION - Create a file with the same filename except with "latest" version.
	:RENAME - Rename the existing file to something else and proceed.
	:RENAME-AND-DELETE - Rename the existing file and delete (but don't expunge,
		if your system has undeletion) it, and proceed.
	:OVERWRITE - Open for :OVERWRITE instead.  (If your file system doesn't have
		this, use :RENAME-AND-DELETE if you have undeletion and :RENAME otherwise.)
	:APPEND - Open for :APPEND instead.
	:REPLACE - Replace the existing file, deleting it when the stream is closed.

:IF-DOES-NOT-EXIST	:ERROR (the default), :CREATE
	Ignored if direction is neither :APPEND nor :OVERWRITE
	:ERROR - Signal an error.
	:CREATE - Create the file and proceed.


Notes:

I renamed :READ-ALTER to :OVERWRITE; :READ-WRITE might also be good.

The :DEFAULT values are very useful, although some systems cannot figure
out this information.  :CHARACTERS :DEFAULT is especially useful for
LOAD.  Having the byte size come from the file only when the option is
missing, as the latest Common Lisp manual says, is undesirable because
it makes things harder for programs that are passing the value of that
keyword argument as computed from an expression.

Example of OPEN:
     (OPEN "f:>dlw>lispm.init" :DIRECTION :OUTPUT)

Example of WITH-OPEN-FILE:
     (WITH-OPEN-FILE (STREAM "f:>dlw>lispm.init" :DIRECTION :OUTPUT) ...)

OPEN can be kept Maclisp compatible by recognizing whether the second
argument is a list or not.  Lisp Machine Lisp does this for the benefit
of old programs.  The new syntax cannot be mistaken for the old one.

I removed :ECHO because we got rid of MAKE-ECHO-STREAM at the last
meeting.

Other options that the Lisp Machine will probably have, and which might
be candidates for Common Lisp, are: :INHIBIT-LINKS, :DELETED,
:PRESERVE-DATES, and :ESTIMATED-SIZE.