Star Sapphire Common LISP Home

Download Star Saphire
Index

LISP: ODDP

C: Loddp

min args: 1

max args: 1

[F][CLTL 12]

SYNOPSIS:

oddp integer

DESCRIPTION:

This predicate is true if the argument integer is odd (not divisible by two), and otherwise is false. It is an error if the argument is not an integer.

LISP: OPEN

C: L_Open

min args: 1

max args: -1

[F][CLTL 23]

SYNOPSIS:

open filename &key :direction :element-type :if-exists :if-does-not-exist :external-format

DESCRIPTION:

This returns a stream that is connected to the file specified by filename. The filename is the name of the file to be opened; it may be a string, a pathname, or a stream. (If the filename is a stream, then it is not closed first or otherwise affected; it is used merely to provide a file name for the opening of a new stream). The keyword arguments specify what kind of stream to produce and how to handle errors:

:direction

This argument specifies whether the stream should handle input, output, or both. This keyword takes one of several arguments, which are themselves keywords. Valid arguments are:

:input

The result will be an input stream. This is the default.

:output

The result will be an output stream.

:io

The result will be a bidirectional stream.

:probe

The result will be a no-directional stream (in effect, the stream is created and then closed). This is useful for determining whether a file exists without actually setting up a complete stream.

:if-exists

this argument specifies the action to be taken if the :direction is :output or :io and a file of the specified name already exists. If the direction is :input or :probe, this argument is ignored. This keyword takes one of the following arguments, which are with one exception likewise keywords:

:error

Signal an error.

:overwrite

the existing file is used, and output operations on the stream will destructively modify the file. If :direction is :io, the file is opened in a bidirectional mode that allows both reading and writing. The file pointer is initially positioned at the beginning of the file; however, the file is not truncated back to length zero when it is opened. This mode is most useful when the file-position function is to be used on the stream.

:append

The existing file is used, and output operations on the stream will destructively modify the file. The file pointer is initially positioned at the end of the file. If the :direction is :io, the file is opened in a bidirectional mode that allows both reading and writing.

nil

Does not create a file or even a stream. Instead, simply return nil to indicate failure.

:if-does-not-exist

This argument specifies the action to be taken if a file of the specified name does not already exist. This keyword takes one of the following arguments, which are with one exception likewise keywords:

:error

Signals an error. This is the default if the :direction is :input, or if the :if-exists argument is :overwrite or :append.

:create

Create an empty file with the specified name, and then proceed as if it had already existed (but do not perform any processing directed by the :if-exists argument). This is the default if the :direction is :output or :io, and the :if-exists argument is anything but :overwrite or :append.

nil

Do not create a file or even a stream . Instead, simply return nil to indicate failure. This is the default if the :direction is :probe.

:external-format

This keyword, which is new to ANSI Common LISP, allows an implementation to define its own formats. Star Sapphire LISP allows three options here: :default, :text, and :binary. :default and :text do the same thing, which is to handle files with newlines mapped to carriage-return/line-feed combinations; these files are standard DOS ASCII files and the default mode for a stream opened using open.

Note that the :default keyword is specified by ANSI, :text and :binary are Star Sapphire exensions and may not be portable (although they are certainly useful).

If :external-format :binary is used, then the resulting stream is opened in binary mode.

In this case every byte put to the file will count as exactly one character; newline will be mapped to the ASCII carriage-return character. This allows random-access files.

NOTE:

When the caller is finished with the stream, the file should be closed using the close function. The with-open-file macro (normally initialized by loading wofile.fsl at startup) does this automatically, and so is preferred for most purposes. All open options work with with-open-file. open should be used only when the control structure of the program necessitates opening and closing of a file in some way more complex than provided by with-open-file. It is suggested that any program that uses open directly should use the special form unwind-protect to close the file if an abnormal exit occurs.

There are several other options specified by Common LISP; these options are not supported by Star Sapphire since they do not correspond to DOS file system features (in particular file versions). However, if you use the set of operations defined here (with the exception of :text and :binary) your code will most likely be portable to a wide range of LISP systems.

LISP: OR

C: EOr

min args: 0

max args: -1

[M][CLTL 6]

SYNOPSIS:

or {form}*

DESCRIPTION:

The or macro evaluates each of its forms sequentially from left to right. If any form other than the last evaluates to a non-nil value, or immediately returns that value without evaluating any successive forms. If every form but the last evaluates to nil, or returns whatever last form in the argument list returned.

Therefore or can be used both for logical operations, where nil stands for false and non-nil values stand for true, and also as a conditional expression.

The or macro acts like a sequence of || clauses in C; it effectively short-circuits the evaluation if the test is not met at any point in the sequence. In this respect it is unlike the Pascal or Ada or operator, which always evaluates both arguments.

As a base case,

(or) => NIL,

which is an identity for this operation. Also note that

(or x)=>x.

 

One can define or in terms of cond in this way:

(or a b c ... m) == (cond (a) (b) (c) ... (t m))

SEE ALSO:

if and unless, which are recommended rather than or for conditional purposes. If it is necessary to test whether a predicate is true of one or more elements of a list or vector then the function some may be useful.

LISP: OR (typespec)

min args: 0

max args: -1

[Typespec][CLTL 4]

SYNOPSIS:

or {typespec}*

DESCRIPTION:

The or type specifier can occur at the car of a type specifier list.

An or typespec denotes the union of the specified types. That is, an object is of the type '(or type1 type2 type3) if it is of one of the three types type1, type2 and type3.

More precisely, each typespec in turn is compared with the given object and t is returned when the first matching typespec is encountered. Otherwise nil is returned.

As a base case '(or) matches no object whatsoever.

LISP: OUTPUT-STREAM-P

C: POutputStrm

min args: 1

max args: 1

[F][CLTL 21]

SYNOPSIS:

output-stream-p stream

DESCRIPTION:

The argument to this function must be a stream object.

This predicate returns t if the stream is an output stream and nil otherwise.