Dec 282017
 
Public Domain eXperimental LISP.
File XLISPPC.ZIP from The Programmer’s Corner in
Category Miscellaneous Language Source Code
Public Domain eXperimental LISP.
File Name File Size Zip Size Zip Type
XLISP.DOC 84107 16590 deflated
XLISP.EXE 135976 51375 deflated

Download File XLISPPC.ZIP Here

Contents of the XLISP.DOC file








XLISP: An Object-oriented Lisp

Version 2.0

February 6, 1988


by
David Michael Betz
127 Taylor Road
Peterborough, NH 03458

(603) 924-6936 (home)

Copyright (c) 1988, by David Michael Betz
All Rights Reserved
Permission is granted for unrestricted non-commercial use














































XLISP TABLE OF CONTENTS Page 2


Table of Contents


TABLE OF CONTENTS 2

INTRODUCTION 4

A NOTE FROM THE AUTHOR 5

XLISP COMMAND LOOP 6

BREAK COMMAND LOOP 7

DATA TYPES 8

THE EVALUATOR 9

LEXICAL CONVENTIONS 10

READTABLES 11

LAMBDA LISTS 12

OBJECTS 14

SYMBOLS 17

EVALUATION FUNCTIONS 18

SYMBOL FUNCTIONS 19

PROPERTY LIST FUNCTIONS 21

ARRAY FUNCTIONS 22

LIST FUNCTIONS 23

DESTRUCTIVE LIST FUNCTIONS 26

PREDICATE FUNCTIONS 27

CONTROL CONSTRUCTS 29

LOOPING CONSTRUCTS 31

THE PROGRAM FEATURE 32

DEBUGGING AND ERROR HANDLING 33

ARITHMETIC FUNCTIONS 34

BITWISE LOGICAL FUNCTIONS 36

STRING FUNCTIONS 37









XLISP TABLE OF CONTENTS Page 3


CHARACTER FUNCTIONS 39

INPUT/OUTPUT FUNCTIONS 41

THE FORMAT FUNCTION 42

FILE I/O FUNCTIONS 43

STRING STREAM FUNCTIONS 44

SYSTEM FUNCTIONS 45

EXAMPLES 47


















































XLISP INTRODUCTION Page 4


INTRODUCTION

XLISP is an experimental programming language combining some of
the features of Common Lisp with an object-oriented extension
capability. It was implemented to allow experimentation with
object-oriented programming on small computers.

There are currently implementations of XLISP running on the IBM-
PC and clones under MS-DOS, on the Macintosh, the Atari-ST and
the Amiga. It is completely written in the programming language
'C' and is easily extended with user written built-in functions
and classes. It is available in source form to non-commercial
users.

Many Common Lisp functions are built into XLISP. In addition,
XLISP defines the objects 'Object' and 'Class' as primitives.
'Object' is the only class that has no superclass and hence is
the root of the class heirarchy tree. 'Class' is the class of
which all classes are instances (it is the only object that is
an instance of itself).

This document is a brief description of XLISP. It assumes some
knowledge of LISP and some understanding of the concepts of
object-oriented programming.

I recommend the book "LISP" by Winston and Horn and published by
Addison Wesley for learning Lisp. The first edition of this
book is based on MacLisp and the second edition is based on
Common Lisp. XLISP will continue to migrate towards
compatibility with Common Lisp.

You will probably also need a copy of "Common Lisp: The
Language" by Guy L. Steele, Jr., published by Digital Press to
use as a reference for some of the Common Lisp functions that
are described only briefly in this document.




























XLISP A NOTE FROM THE AUTHOR Page 5


A NOTE FROM THE AUTHOR

If you have any problems with XLISP, feel free to contact me for
help or advice. Please remember that since XLISP is available
in source form in a high level language, many users have been
making versions available on a variety of machines. If you call
to report a problem with a specific version, I may not be able
to help you if that version runs on a machine to which I don't
have access. Please have the version number of the version that
you are running readily accessible before calling me.

If you find a bug in XLISP, first try to fix the bug yourself
using the source code provided. If you are successful in fixing
the bug, send the bug report along with the fix to me. If you
don't have access to a C compiler or are unable to fix a bug,
please send the bug report to me and I'll try to fix it.

Any suggestions for improvements will be welcomed. Feel free to
extend the language in whatever way suits your needs. However,
PLEASE DO NOT RELEASE ENHANCED VERSIONS WITHOUT CHECKING WITH ME
FIRST!! I would like to be the clearing house for new features
added to XLISP. If you want to add features for your own
personal use, go ahead. But, if you want to distribute your
enhanced version, contact me first. Please remember that the
goal of XLISP is to provide a language to learn and experiment
with LISP and object-oriented programming on small computers. I
don't want it to get so big that it requires megabytes of memory
to run.



































XLISP XLISP COMMAND LOOP Page 6


XLISP COMMAND LOOP

When XLISP is started, it first tries to load the workspace
"xlisp.wks" from the current directory. If that file doesn't
exist, XLISP builds an initial workspace, empty except for the
built-in functions and symbols.

Then XLISP attempts to load "init.lsp" from the current
directory. It then loads any files named as parameters on the
command line (after appending ".lsp" to their names).

XLISP then issues the following prompt:

>

This indicates that XLISP is waiting for an expression to be
typed.

When a complete expression has been entered, XLISP attempts to
evaluate that expression. If the expression evaluates
successfully, XLISP prints the result and then returns to the
initial prompt waiting for another expression to be typed.









































XLISP BREAK COMMAND LOOP Page 7


BREAK COMMAND LOOP

When XLISP encounters an error while evaluating an expression,
it attempts to handle the error in the following way:

If the symbol '*breakenable*' is true, the message corresponding
to the error is printed. If the error is correctable, the
correction message is printed.

If the symbol '*tracenable*' is true, a trace back is printed.
The number of entries printed depends on the value of the symbol
'*tracelimit*'. If this symbol is set to something other than a
number, the entire trace back stack is printed.

XLISP then enters a read/eval/print loop to allow the user to
examine the state of the interpreter in the context of the
error. This loop differs from the normal top-level
read/eval/print loop in that if the user invokes the function
'continue', XLISP will continue from a correctable error. If
the user invokes the function 'clean-up', XLISP will abort the
break loop and return to the top level or the next lower
numbered break loop. When in a break loop, XLISP prefixes the
break level to the normal prompt.

If the symbol '*breakenable*' is nil, XLISP looks for a
surrounding errset function. If one is found, XLISP examines
the value of the print flag. If this flag is true, the error
message is printed. In any case, XLISP causes the errset
function call to return nil.

If there is no surrounding errset function, XLISP prints the
error message and returns to the top level.































XLISP DATA TYPES Page 8


DATA TYPES

There are several different data types available to XLISP
programmers.

o lists
o symbols
o strings
o integers
o characters
o floats
o objects
o arrays
o streams
o subrs (built-in functions)
o fsubrs (special forms)
o closures (user defined functions)














































XLISP THE EVALUATOR Page 9


THE EVALUATOR

The process of evaluation in XLISP:

Strings, integers, characters, floats, objects, arrays, streams,
subrs, fsubrs and closures evaluate to themselves.

Symbols act as variables and are evaluated by retrieving the
value associated with their current binding.

Lists are evaluated by examining the first element of the list
and then taking one of the following actions:

If it is a symbol, the functional binding of the symbol is
retrieved.

If it is a lambda expression, a closure is constructed for
the function described by the lambda expression.

If it is a subr, fsubr or closure, it stands for itself.

Any other value is an error.

Then, the value produced by the previous step is examined:

If it is a subr or closure, the remaining list elements are
evaluated and the subr or closure is called with these
evaluated expressions as arguments.

If it is an fsubr, the fsubr is called using the remaining
list elements as arguments (unevaluated).

If it is a macro, the macro is expanded using the remaining
list elements as arguments (unevaluated). The macro
expansion is then evaluated in place of the original macro
call.



























XLISP LEXICAL CONVENTIONS Page 10


LEXICAL CONVENTIONS

The following conventions must be followed when entering XLISP
programs:

Comments in XLISP code begin with a semi-colon character and
continue to the end of the line.

Symbol names in XLISP can consist of any sequence of non-blank
printable characters except the following:

( ) ' ` , " ;

Uppercase and lowercase characters are not distinguished within
symbol names. All lowercase characters are mapped to uppercase
on input.

Integer literals consist of a sequence of digits optionally
beginning with a '+' or '-'. The range of values an integer can
represent is limited by the size of a C 'long' on the machine on
which XLISP is running.

Floating point literals consist of a sequence of digits
optionally beginning with a '+' or '-' and including an embedded
decimal point. The range of values a floating point number can
represent is limited by the size of a C 'float' ('double' on
machines with 32 bit addresses) on the machine on which XLISP is
running.

Literal strings are sequences of characters surrounded by double
quotes. Within quoted strings the '\' character is used to
allow non-printable characters to be included. The codes
recognized are:

\\ means the character '\'
\n means newline
\t means tab
\r means return
\f means form feed
\nnn means the character whose octal code is nnn























XLISP READTABLES Page 11


READTABLES

The behaviour of the reader is controlled by a data structure
called a "readtable". The reader uses the symbol *READTABLE* to
locate the current readtable. This table controls the
interpretation of input characters. It is an array with 128
entries, one for each of the ASCII character codes. Each entry
contains one of the following things:

NIL Indicating an invalid character
:CONSTITUENT Indicating a symbol constituent
:WHITE-SPACE Indicating a whitespace character
(:TMACRO . fun) Terminating readmacro
(:NMACRO . fun) Non-terminating readmacro
:SESCAPE Single escape character ('\')
:MESCAPE Multiple escape character ('|')

In the case of :TMACRO and :NMACRO, the "fun" component is a
function. This can either be a built-in readmacro function or a
lambda expression. The function should take two parameters.
The first is the input stream and the second is the character
that caused the invocation of the readmacro. The readmacro
function should return NIL to indicate that the character should
be treated as white space or a value consed with NIL to indicate
that the readmacro should be treated as an occurance of the
specified value. Of course, the readmacro code is free to read
additional characters from the input stream.

XLISP defines several useful read macros:

' == (quote )
#' == (function )
#(...) == an array of the specified expressions
#x == a hexadecimal number (0-9,A-F)
#o == an octal number (0-7)
#b == a binary number (0-1)
#\ == the ASCII code of the character
#| ... |# == a comment
#: == an uninterned symbol
` == (backquote )
, == (comma )
,@ == (comma-at )





















XLISP LAMBDA LISTS Page 12


LAMBDA LISTS

There are several forms in XLISP that require that a "lambda
list" be specified. A lambda list is a definition of the
arguments accepted by a function. There are four different
types of arguments.

The lambda list starts with required arguments. Required
arguments must be specified in every call to the function.

The required arguments are followed by the &optional arguments.
Optional arguments may be provided or omitted in a call. An
initialization expression may be specified to provide a default
value for an &optional argument if it is omitted from a call.
If no initialization expression is specified, an omitted
argument is initialized to NIL. It is also possible to provide
the name of a 'supplied-p' variable that can be used to
determine if a call provided a value for the argument or if the
initialization expression was used. If specified, the supplied-
p variable will be bound to T if a value was specified in the
call and NIL if the default value was used.

The &optional arguments are followed by the &rest argument. The
&rest argument gets bound to the remainder of the argument list
after the required and &optional arguments have been removed.

The &rest argument is followed by the &key arguments. When a
keyword argument is passed to a function, a pair of values
appears in the argument list. The first expression in the pair
should evaluate to a keyword symbol (a symbol that begins with a
':'). The value of the second expression is the value of the
keyword argument. Like &optional arguments, &key arguments can
have initialization expressions and supplied-p variables. In
addition, it is possible to specify the keyword to be used in a
function call. If no keyword is specified, the keyword obtained
by adding a ':' to the beginning of the keyword argument symbol
is used. In other words, if the keyword argument symbol is
'foo', the keyword will be ':foo'.

The &key arguments are followed by the &aux variables. These
are local variables that are bound during the evaluation of the
function body. It is possible to have initialization
expressions for the &aux variables.




















XLISP LAMBDA LISTS Page 13


Here is the complete syntax for lambda lists:

(...
[&optional [ | ( [ []])]...]
[&rest ]
[&key
[ | ([ | ( )] [ []])]...
&allow-other-keys]
[&aux
[ | ( [])]...])

where:

is a required argument symbol
is an &optional argument symbol
is the &rest argument symbol
is a &key argument symbol
is a keyword symbol
is an auxiliary variable symbol
is an initialization expression
is a supplied-p variable symbol










































XLISP OBJECTS Page 14


OBJECTS

Definitions:

o selector - a symbol used to select an appropriate method
o message - a selector and a list of actual arguments
o method - the code that implements a message

Since XLISP was created to provide a simple basis for
experimenting with object-oriented programming, one of the
primitive data types included is 'object'. In XLISP, an object
consists of a data structure containing a pointer to the
object's class as well as an array containing the values of the
object's instance variables.

Officially, there is no way to see inside an object (look at the
values of its instance variables). The only way to communicate
with an object is by sending it a message.

You can send a message to an object using the 'send' function.
This function takes the object as its first argument, the
message selector as its second argument (which must be a symbol)
and the message arguments as its remaining arguments.

The 'send' function determines the class of the receiving object
and attempts to find a method corresponding to the message
selector in the set of messages defined for that class. If the
message is not found in the object's class and the class has a
super-class, the search continues by looking at the messages
defined for the super-class. This process continues from one
super-class to the next until a method for the message is found.
If no method is found, an error occurs.

A message can also be sent from the body of a method by using
the current object, but the method lookup starts with the
object's superclass rather than its class. This allows a
subclass to invoke a standard method in its parent class even
though it overrides that method with its own specialized
version.

When a method is found, the evaluator binds the receiving object
to the symbol 'self' and evaluates the method using the
remaining elements of the original list as arguments to the
method. These arguments are always evaluated prior to being
bound to their corresponding formal arguments. The result of
evaluating the method becomes the result of the expression.

















XLISP OBJECTS Page 15


THE 'Object' CLASS

Classes:

Object THE TOP OF THE CLASS HEIRARCHY

Messages:

:show SHOW AN OBJECT'S INSTANCE VARIABLES
returns the object

:class RETURN THE CLASS OF AN OBJECT
returns the class of the object

:isnew THE DEFAULT OBJECT INITIALIZATION ROUTINE
returns the object

:sendsuper ... SEND SUPERCLASS A MESSAGE
the message selector
the message arguments
returns the result of sending the message










































XLISP OBJECTS Page 16


THE 'Class' CLASS

Class THE CLASS OF ALL OBJECT CLASSES (including itself)

Messages:

:new CREATE A NEW INSTANCE OF A CLASS
returns the new class object

:isnew [ []] INITIALIZE A NEW CLASS
the list of instance variable symbols
the list of class variable symbols
the superclass (default is Object)
returns the new class object

:answer ADD A MESSAGE TO A CLASS
the message symbol
the formal argument list (lambda list)
a list of executable expressions
returns the object


When a new instance of a class is created by sending the message
':new' to an existing class, the message ':isnew' followed by
whatever parameters were passed to the ':new' message is sent to
the newly created object.

When a new class is created by sending the ':new' message to the
object 'Class', an optional parameter may be specified
indicating the superclass of the new class. If this parameter
is omitted, the new class will be a subclass of 'Object'. A
class inherits all instance variables, class variables, and
methods from its super-class.






























XLISP SYMBOLS Page 17


SYMBOLS

o self - the current object (within a method context)
o *obarray* - the object hash table
o *standard-input* - the standard input stream
o *standard-output* - the standard output stream
o *error-output* - the error output stream
o *trace-output* - the trace output stream
o *debug-io* - the debug i/o stream
o *breakenable* - flag controlling entering break loop on errors
o *tracelist* - list of names of functions to trace
o *tracenable* - enable trace back printout on errors
o *tracelimit* - number of levels of trace back information
o *evalhook* - user substitute for the evaluator function
o *applyhook* - (not yet implemented)
o *readtable* - the current readtable
o *unbound* - indicator for unbound symbols
o *gc-flag* - controls the printing of gc messages
o *gc-hook* - function to call after garbage collection
o *integer-format* - format for printing integers ("%d" or "%ld")
o *float-format* - format for printing floats ("%g")
o *print-case* - symbol output case (:upcase or :downcase)

There are several symbols maintained by the read/eval/print
loop. The symbols '+', '++', and '+++' are bound to the most
recent three input expressions. The symbols '*', '**' and '***'
are bound to the most recent three results. The symbol '-' is
bound to the expression currently being evaluated. It becomes
the value of '+' at the end of the evaluation.


































XLISP EVALUATION FUNCTIONS Page 18


EVALUATION FUNCTIONS

(eval ) EVALUATE AN XLISP EXPRESSION
the expression to be evaluated
returns the result of evaluating the expression

(apply ) APPLY A FUNCTION TO A LIST OF ARGUMENTS
the function to apply (or function symbol)
the argument list
returns the result of applying the function to the arguments

(funcall ...) CALL A FUNCTION WITH ARGUMENTS
the function to call (or function symbol)
arguments to pass to the function
returns the result of calling the function with the arguments

(quote ) RETURN AN EXPRESSION UNEVALUATED
the expression to be quoted (quoted)
returns unevaluated

(function ) GET THE FUNCTIONAL INTERPRETATION
the symbol or lambda expression (quoted)
returns the functional interpretation

(backquote ) FILL IN A TEMPLATE
the template
returns a copy of the template with comma and comma-at
expressions expanded

(lambda ...) MAKE A FUNCTION CLOSURE
formal argument list (lambda list) (quoted)
expressions of the function body
returns the function closure

(get-lambda-expression ) GET THE LAMBDA EXPRESSION
the closure
returns the original lambda expression

(macroexpand
) RECURSIVELY EXPAND MACRO CALLS
the form to expand
returns the macro expansion

(macroexpand-1 ) EXPAND A MACRO CALL
the macro call form
returns the macro expansion


















XLISP SYMBOL FUNCTIONS Page 19


SYMBOL FUNCTIONS

(set ) SET THE VALUE OF A SYMBOL
the symbol being set
the new value
returns the new value

(setq [ ]...) SET THE VALUE OF A SYMBOL
the symbol being set (quoted)
the new value
returns the new value

(psetq [ ]...) PARALLEL VERSION OF SETQ
the symbol being set (quoted)
the new value
returns the new value

(setf [ ]...) SET THE VALUE OF A FIELD
the field specifier (quoted):
set value of a symbol
(car ) set car of a cons node
(cdr ) set cdr of a cons node
(nth ) set nth car of a list
(aref ) set nth element of an array
(get ) set value of a property
(symbol-value ) set value of a symbol
(symbol-function ) set functional value of a symbol
(symbol-plist ) set property list of a symbol
the new value
returns the new value

(defun ...) DEFINE A FUNCTION
(defmacro ...) DEFINE A MACRO
symbol being defined (quoted)
formal argument list (lambda list) (quoted)
expressions constituting the body of the
function (quoted)
returns the function symbol

(gensym []) GENERATE A SYMBOL
string or number
returns the new symbol

(intern ) MAKE AN INTERNED SYMBOL
the symbol's print name string
returns the new symbol

(make-symbol ) MAKE AN UNINTERNED SYMBOL
the symbol's print name string
returns the new symbol

(symbol-name ) GET THE PRINT NAME OF A SYMBOL
the symbol
returns the symbol's print name









XLISP SYMBOL FUNCTIONS Page 20


(symbol-value ) GET THE VALUE OF A SYMBOL
the symbol
returns the symbol's value

(symbol-function ) GET THE FUNCTIONAL VALUE OF A SYMBOL
the symbol
returns the symbol's functional value

(symbol-plist ) GET THE PROPERTY LIST OF A SYMBOL
the symbol
returns the symbol's property list

(hash ) COMPUTE THE HASH INDEX FOR A SYMBOL
the symbol or string
the table size (integer)
returns the hash index (integer)















































XLISP PROPERTY LIST FUNCTIONS Page 21


PROPERTY LIST FUNCTIONS

(get ) GET THE VALUE OF A PROPERTY
the symbol
the property symbol
returns the property value or nil

(putprop ) PUT A PROPERTY ONTO A PROPERTY LIST
the symbol
the property value
the property symbol
returns the property value

(remprop ) REMOVE A PROPERTY
the symbol
the property symbol
returns nil














































XLISP ARRAY FUNCTIONS Page 22


ARRAY FUNCTIONS

(aref ) GET THE NTH ELEMENT OF AN ARRAY
the array
the array index (integer)
returns the value of the array element

(make-array ) MAKE A NEW ARRAY
the size of the new array (integer)
returns the new array

(vector ...) MAKE AN INITIALIZED VECTOR
the vector elements
returns the new vector

















































XLISP LIST FUNCTIONS Page 23


LIST FUNCTIONS

(car ) RETURN THE CAR OF A LIST NODE
the list node
returns the car of the list node

(cdr ) RETURN THE CDR OF A LIST NODE
the list node
returns the cdr of the list node

(cxxr ) ALL CxxR COMBINATIONS
(cxxxr ) ALL CxxxR COMBINATIONS
(cxxxxr ) ALL CxxxxR COMBINATIONS

(first ) A SYNONYM FOR CAR
(second ) A SYNONYM FOR CADR
(third ) A SYNONYM FOR CADDR
(fourth ) A SYNONYM FOR CADDDR
(rest ) A SYNONYM FOR CDR

(cons ) CONSTRUCT A NEW LIST NODE
the car of the new list node
the cdr of the new list node
returns the new list node

(list ...) CREATE A LIST OF VALUES
expressions to be combined into a list
returns the new list

(append ...) APPEND LISTS
lists whose elements are to be appended
returns the new list

(reverse ) REVERSE A LIST
the list to reverse
returns a new list in the reverse order

(last ) RETURN THE LAST LIST NODE OF A LIST
the list
returns the last list node in the list

(member &key :test :test-not) FIND AN EXPRESSION IN A LIST
the expression to find
the list to search
:test the test function (defaults to eql)
:test-not the test function (sense inverted)
returns the remainder of the list starting with the expression

(assoc &key :test :test-not) FIND AN EXPRESSION IN AN A-LIST
the expression to find
the association list
:test the test function (defaults to eql)
:test-not the test function (sense inverted)
returns the alist entry or nil









XLISP LIST FUNCTIONS Page 24


(remove &key :test :test-not) REMOVE ELEMENTS FROM A LIST
the element to remove
the list
:test the test function (defaults to eql)
:test-not the test function (sense inverted)
returns copy of list with matching expressions removed

(remove-if ) REMOVE ELEMENTS THAT PASS TEST
the test predicate
the list
returns copy of list with matching elements removed

(remove-if-not ) REMOVE ELEMENTS THAT FAIL TEST
the test predicate
the list
returns copy of list with non-matching elements removed

(length ) FIND THE LENGTH OF A LIST, VECTOR OR STRING
the list, vector or string
returns the length of the list, vector or string

(nth ) RETURN THE NTH ELEMENT OF A LIST
the number of the element to return (zero origin)
the list
returns the nth element or nil if the list isn't that long

(nthcdr ) RETURN THE NTH CDR OF A LIST
the number of the element to return (zero origin)
the list
returns the nth cdr or nil if the list isn't that long

(mapc ...) APPLY FUNCTION TO SUCCESSIVE CARS
the function or function name
a list for each argument of the function
returns the first list of arguments

(mapcar ...) APPLY FUNCTION TO SUCCESSIVE CARS
the function or function name
a list for each argument of the function
returns a list of the values returned

(mapl ...) APPLY FUNCTION TO SUCCESSIVE CDRS
the function or function name
a list for each argument of the function
returns the first list of arguments

(maplist ...) APPLY FUNCTION TO SUCCESSIVE CDRS
the function or function name
a list for each argument of the function
returns a list of the values returned













XLISP LIST FUNCTIONS Page 25


(subst &key :test :test-not) SUBSTITUTE EXPRESSIONS
the new expression
the old expression
the expression in which to do the substitutions
:test the test function (defaults to eql)
:test-not the test function (sense inverted)
returns the expression with substitutions

(sublis &key :test :test-not) SUBSTITUTE WITH AN A-LIST
the association list
the expression in which to do the substitutions
:test the test function (defaults to eql)
:test-not the test function (sense inverted)
returns the expression with substitutions

















































XLISP DESTRUCTIVE LIST FUNCTIONS Page 26


DESTRUCTIVE LIST FUNCTIONS

(rplaca ) REPLACE THE CAR OF A LIST NODE
the list node
the new value for the car of the list node
returns the list node after updating the car

(rplacd ) REPLACE THE CDR OF A LIST NODE
the list node
the new value for the cdr of the list node
returns the list node after updating the cdr

(nconc ...) DESTRUCTIVELY CONCATENATE LISTS
lists to concatenate
returns the result of concatenating the lists

(delete &key :test :test-not) DELETE ELEMENTS FROM A LIST
the element to delete
the list
:test the test function (defaults to eql)
:test-not the test function (sense inverted)
returns the list with the matching expressions deleted

(delete-if ) DELETE ELEMENTS THAT PASS TEST
the test predicate
the list
returns the list with matching elements deleted

(delete-if-not ) DELETE ELEMENTS THAT FAIL TEST
the test predicate
the list
returns the list with non-matching elements deleted

(sort ) SORT A LIST
the list to sort
the comparison function
returns the sorted list


























XLISP PREDICATE FUNCTIONS Page 27


PREDICATE FUNCTIONS

(atom ) IS THIS AN ATOM?
the expression to check
returns t if the value is an atom, nil otherwise

(symbolp ) IS THIS A SYMBOL?
the expression to check
returns t if the expression is a symbol, nil otherwise

(numberp ) IS THIS A NUMBER?
the expression to check
returns t if the expression is a number, nil otherwise

(null ) IS THIS AN EMPTY LIST?
the list to check
returns t if the list is empty, nil otherwise

(not ) IS THIS FALSE?
the expression to check
return t if the value is nil, nil otherwise

(listp ) IS THIS A LIST?
the expression to check
returns t if the value is a cons or nil, nil otherwise

(endp ) IS THIS THE END OF A LIST
the list
returns t if the value is nil, nil otherwise

(consp ) IS THIS A NON-EMPTY LIST?
the expression to check
returns t if the value is a cons, nil otherwise

(integerp ) IS THIS AN INTEGER?
the expression to check
returns t if the value is an integer, nil otherwise

(floatp ) IS THIS A FLOAT?
the expression to check
returns t if the value is a float, nil otherwise

(stringp ) IS THIS A STRING?
the expression to check
returns t if the value is a string, nil otherwise

(characterp ) IS THIS A CHARACTER?
the expression to check
returns t if the value is a character, nil otherwise

(arrayp ) IS THIS AN ARRAY?
the expression to check
returns t if the value is an array, nil otherwise










XLISP PREDICATE FUNCTIONS Page 28


(streamp ) IS THIS A STREAM?
the expression to check
returns t if the value is a stream, nil otherwise

(objectp ) IS THIS AN OBJECT?
the expression to check
returns t if the value is an object, nil otherwise

(boundp ) IS A VALUE BOUND TO THIS SYMBOL?
the symbol
returns t if a value is bound to the symbol, nil otherwise

(fboundp ) IS A FUNCTIONAL VALUE BOUND TO THIS SYMBOL?
the symbol
returns t if a functional value is bound to the symbol,
nil otherwise

(minusp ) IS THIS NUMBER NEGATIVE?
the number to test
returns t if the number is negative, nil otherwise

(zerop ) IS THIS NUMBER ZERO?
the number to test
returns t if the number is zero, nil otherwise

(plusp ) IS THIS NUMBER POSITIVE?
the number to test
returns t if the number is positive, nil otherwise

(evenp ) IS THIS INTEGER EVEN?
the integer to test
returns t if the integer is even, nil otherwise

(oddp ) IS THIS INTEGER ODD?
the integer to test
returns t if the integer is odd, nil otherwise

(eq ) ARE THE EXPRESSIONS IDENTICAL?
the first expression
the second expression
returns t if they are equal, nil otherwise

(eql ) ARE THE EXPRESSIONS IDENTICAL?
(WORKS WITH ALL NUMBERS)
the first expression
the second expression
returns t if they are equal, nil otherwise

(equal ) ARE THE EXPRESSIONS EQUAL?
the first expression
the second expression
returns t if they are equal, nil otherwise











XLISP CONTROL CONSTRUCTS Page 29


CONTROL CONSTRUCTS

(cond ...) EVALUATE CONDITIONALLY
pair consisting of:
( ...)
where
is a predicate expression
evaluated if the predicate
is not nil
returns the value of the first expression whose predicate
is not nil

(and ...) THE LOGICAL AND OF A LIST OF EXPRESSIONS
the expressions to be ANDed
returns nil if any expression evaluates to nil,
otherwise the value of the last expression
(evaluation of expressions stops after the first
expression that evaluates to nil)

(or ...) THE LOGICAL OR OF A LIST OF EXPRESSIONS
the expressions to be ORed
returns nil if all expressions evaluate to nil,
otherwise the value of the first non-nil expression
(evaluation of expressions stops after the first
expression that does not evaluate to nil)

(if []) EVALUATE EXPRESSIONS CONDITIONALLY
the test expression
the expression to be evaluated if texpr is non-nil
the expression to be evaluated if texpr is nil
returns the value of the selected expression

(when ...) EVALUATE ONLY WHEN A CONDITION IS TRUE
the test expression
the expression(s) to be evaluted if texpr is non-nil
returns the value of the last expression or nil

(unless ...) EVALUATE ONLY WHEN A CONDITION IS FALSE
the test expression
the expression(s) to be evaluated if texpr is nil
returns the value of the last expression or nil

(case ...) SELECT BY CASE
the selection expression
pair consisting of:
( ...)
where:
is a single expression or a list of
expressions (unevaluated)
are expressions to execute if the
case matches
returns the value of the last expression of the matching case











XLISP CONTROL CONSTRUCTS Page 30


(let (...) ...) CREATE LOCAL BINDINGS
(let* (...) ...) LET WITH SEQUENTIAL BINDING
the variable bindings each of which is either:
1) a symbol (which is initialized to nil)
2) a list whose car is a symbol and whose cadr
is an initialization expression
the expressions to be evaluated
returns the value of the last expression

(flet (...) ...) CREATE LOCAL FUNCTIONS
(labels (...) ...) FLET WITH RECURSIVE FUNCTIONS
(macrolet (...) ...) CREATE LOCAL MACROS
the function bindings each of which is:
( ...)
where:
the function/macro name
formal argument list (lambda list)
expressions constituting the body of
the function/macro
the expressions to be evaluated
returns the value of the last expression

(catch ...) EVALUATE EXPRESSIONS AND CATCH THROWS
the catch tag
expressions to evaluate
returns the value of the last expression the throw expression

(throw []) THROW TO A CATCH
the catch tag
the value for the catch to return (defaults to nil)
returns never returns

(unwind-protect ...) PROTECT EVALUATION OF AN EXPRESSION
the expression to protect
the cleanup expressions
returns the value of the expression
Note: unwind-protect guarantees to execute the cleanup expressions
even if a non-local exit terminates the evaluation of the
protected expression
























XLISP LOOPING CONSTRUCTS Page 31


LOOPING CONSTRUCTS

(loop ...) BASIC LOOPING FORM
the body of the loop
returns never returns (must use non-local exit)

(do (...) ( ...) ...)
(do* (...) ( ...) ...)
the variable bindings each of which is either:
1) a symbol (which is initialized to nil)
2) a list of the form: ( [])
where:
is the symbol to bind
is the initial value of the symbol
is a step expression
the termination test expression
result expressions (the default is nil)
the body of the loop (treated like an implicit prog)
returns the value of the last result expression

(dolist ( []) ...) LOOP THROUGH A LIST
the symbol to bind to each list element
the list expression
the result expression (the default is nil)
the body of the loop (treated like an implicit prog)

(dotimes ( []) ...) LOOP FROM ZERO TO N-1
the symbol to bind to each value from 0 to n-1
the number of times to loop
the result expression (the default is nil)
the body of the loop (treated like an implicit prog)
































XLISP THE PROGRAM FEATURE Page 32


THE PROGRAM FEATURE

(prog (...) ...) THE PROGRAM FEATURE
(prog* (...) ...) PROG WITH SEQUENTIAL BINDING
the variable bindings each of which is either:
1) a symbol (which is initialized to nil)
2) a list whose car is a symbol and whose cadr
is an initialization expression
expressions to evaluate or tags (symbols)
returns nil or the argument passed to the return function

(block ...) NAMED BLOCK
the block name (symbol)
the block body
returns the value of the last expression

(return []) CAUSE A PROG CONSTRUCT TO RETURN A VALUE
the value (defaults to nil)
returns never returns

(return-from []) RETURN FROM A NAMED BLOCK
the block name (symbol)
the value to return (defaults to nil)
returns never returns

(tagbody ...) BLOCK WITH LABELS
expression(s) to evaluate or tags (symbols)
returns nil

(go ) GO TO A TAG WITHIN A TAGBODY OR PROG
the tag (quoted)
returns never returns

(progv ...) DYNAMICALLY BIND SYMBOLS
list of symbols
list of values to bind to the symbols
expression(s) to evaluate
returns the value of the last expression

(prog1 ...) EXECUTE EXPRESSIONS SEQUENTIALLY
the first expression to evaluate
the remaining expressions to evaluate
returns the value of the first expression

(prog2 ...) EXECUTE EXPRESSIONS SEQUENTIALLY
the first expression to evaluate
the second expression to evaluate
the remaining expressions to evaluate
returns the value of the second expression

(progn ...) EXECUTE EXPRESSIONS SEQUENTIALLY
the expressions to evaluate
returns the value of the last expression (or nil)










XLISP DEBUGGING AND ERROR HANDLING Page 33


DEBUGGING AND ERROR HANDLING

(trace ) ADD A FUNCTION TO THE TRACE LIST
the function to add (quoted)
returns the trace list

(untrace ) REMOVE A FUNCTION FROM THE TRACE LIST
the function to remove (quoted)
returns the trace list

(error []) SIGNAL A NON-CORRECTABLE ERROR
the error message string
the argument expression (printed after the message)
returns never returns

(cerror []) SIGNAL A CORRECTABLE ERROR
the continue message string
the error message string
the argument expression (printed after the message)
returns nil when continued from the break loop

(break [ []]) ENTER A BREAK LOOP
the break message string (defaults to "**BREAK**")
the argument expression (printed after the message)
returns nil when continued from the break loop

(clean-up) CLEAN-UP AFTER AN ERROR
returns never returns

(top-level) CLEAN-UP AFTER AN ERROR AND RETURN TO THE TOP LEVEL
returns never returns

(continue) CONTINUE FROM A CORRECTABLE ERROR
returns never returns

(errset []) TRAP ERRORS
the expression to execute
flag to control printing of the error message
returns the value of the last expression consed with nil
or nil on error

(baktrace []) PRINT N LEVELS OF TRACE BACK INFORMATION
the number of levels (defaults to all levels)
returns nil

(evalhook []) EVALUATE WITH HOOKS
the expression to evaluate
the value for *evalhook*
the value for *applyhook*
the environment (default is nil)
returns the result of evaluating the expression












XLISP ARITHMETIC FUNCTIONS Page 34


ARITHMETIC FUNCTIONS

(truncate ) TRUNCATES A FLOATING POINT NUMBER TO AN INTEGER
the number
returns the result of truncating the number

(float ) CONVERTS AN INTEGER TO A FLOATING POINT NUMBER
the number
returns the result of floating the integer

(+ ...) ADD A LIST OF NUMBERS
the numbers
returns the result of the addition

(- ...) SUBTRACT A LIST OF NUMBERS OR NEGATE A SINGLE NUMBER
the numbers
returns the result of the subtraction

(* ...) MULTIPLY A LIST OF NUMBERS
the numbers
returns the result of the multiplication

(/ ...) DIVIDE A LIST OF NUMBERS
the numbers
returns the result of the division

(1+ ) ADD ONE TO A NUMBER
the number
returns the number plus one

(1- ) SUBTRACT ONE FROM A NUMBER
the number
returns the number minus one

(rem ...) REMAINDER OF A LIST OF NUMBERS
the numbers
returns the result of the remainder operation

(min ...) THE SMALLEST OF A LIST OF NUMBERS
the expressions to be checked
returns the smallest number in the list

(max ...) THE LARGEST OF A LIST OF NUMBERS
the expressions to be checked
returns the largest number in the list

(abs ) THE ABSOLUTE VALUE OF A NUMBER
the number
returns the absolute value of the number

(gcd ...) COMPUTE THE GREATEST COMMON DIVISOR
the first number (integer)
the second number(s) (integer)
returns the greatest common divisor









XLISP ARITHMETIC FUNCTIONS Page 35


(random ) COMPUTE A RANDOM NUMBER BETWEEN 1 and N-1
the upper bound (integer)
returns a random number

(sin ) COMPUTE THE SINE OF A NUMBER
the floating point number
returns the sine of the number

(cos ) COMPUTE THE COSINE OF A NUMBER
the floating point number
returns the cosine of the number

(tan ) COMPUTE THE TANGENT OF A NUMBER
the floating point number
returns the tangent of the number

(expt ) COMPUTE X TO THE Y POWER
the floating point number
the floating point exponent
returns x to the y power

(exp ) COMPUTE E TO THE X POWER
the floating point number
returns e to the x power

(sqrt ) COMPUTE THE SQUARE ROOT OF A NUMBER
the floating point number
returns the square root of the number

(< ...) TEST FOR LESS THAN
(<= ...) TEST FOR LESS THAN OR EQUAL TO
(= ...) TEST FOR EQUAL TO
(/= ...) TEST FOR NOT EQUAL TO
(>= ...) TEST FOR GREATER THAN OR EQUAL TO
(> ...) TEST FOR GREATER THAN
the first number to compare
the second number to compare
returns the result of comparing with ...

























XLISP BITWISE LOGICAL FUNCTIONS Page 36


BITWISE LOGICAL FUNCTIONS

(logand ...) THE BITWISE AND OF A LIST OF NUMBERS
the numbers
returns the result of the and operation

(logior ...) THE BITWISE INCLUSIVE OR OF A LIST OF NUMBERS
the numbers
returns the result of the inclusive or operation

(logxor ...) THE BITWISE EXCLUSIVE OR OF A LIST OF NUMBERS
the numbers
returns the result of the exclusive or operation

(lognot ) THE BITWISE NOT OF A NUMBER
the number
returns the bitwise inversion of number














































XLISP STRING FUNCTIONS Page 37


STRING FUNCTIONS

(string ) MAKE A STRING FROM AN INTEGER ASCII VALUE
the integer
returns a one character string

(string-trim ) TRIM BOTH ENDS OF A STRING
a string containing characters to trim
the string to trim
returns a trimed copy of the string

(string-left-trim ) TRIM THE LEFT END OF A STRING
a string containing characters to trim
the string to trim
returns a trimed copy of the string

(string-right-trim ) TRIM THE RIGHT END OF A STRING
a string containing characters to trim
the string to trim
returns a trimed copy of the string

(string-upcase &key :start :end) CONVERT TO UPPERCASE
the string
:start the starting offset
:end the ending offset + 1
returns a converted copy of the string

(string-downcase &key :start :end) CONVERT TO LOWERCASE
the string
:start the starting offset
:end the ending offset + 1
returns a converted copy of the string

(nstring-upcase &key :start :end) CONVERT TO UPPERCASE
the string
:start the starting offset
:end the ending offset + 1
returns the converted string (not a copy)

(nstring-downcase &key :start :end) CONVERT TO LOWERCASE
the string
:start the starting offset
:end the ending offset + 1
returns the converted string (not a copy)

(strcat ...) CONCATENATE STRINGS
the strings to concatenate
returns the result of concatenating the strings

(subseq []) EXTRACT A SUBSTRING
the string
the starting position (zero origin)
the ending position + 1 (defaults to end)
returns substring between and









XLISP STRING FUNCTIONS Page 38


(string< &key :start1 :end1 :start2 :end2)
(string<= &key :start1 :end1 :start2 :end2)
(string= &key :start1 :end1 :start2 :end2)
(string/= &key :start1 :end1 :start2 :end2)
(string>= &key :start1 :end1 :start2 :end2)
(string> &key :start1 :end1 :start2 :end2)
the first string to compare
the second string to compare
:start1 first substring starting offset
:end1 first substring ending offset + 1
:start2 second substring starting offset
:end2 second substring ending offset + 1
returns t if predicate is true, nil otherwise
Note: case is significant with these comparison functions.

(string-lessp &key :start1 :end1 :start2 :end2)
(string-not-greaterp &key :start1 :end1 :start2 :end2)
(string-equalp &key :start1 :end1 :start2 :end2)
(string-not-equalp &key :start1 :end1 :start2 :end2)
(string-not-lessp &key :start1 :end1 :start2 :end2)
(string-greaterp &key :start1 :end1 :start2 :end2)
the first string to compare
the second string to compare
:start1 first substring starting offset
:end1 first substring ending offset + 1
:start2 second substring starting offset
:end2 second substring ending offset + 1
returns t if predicate is true, nil otherwise
Note: case is not significant with these comparison functions.


































XLISP CHARACTER FUNCTIONS Page 39


CHARACTER FUNCTIONS

(char ) EXTRACT A CHARACTER FROM A STRING
the string
the string index (zero relative)
returns the ascii code of the character

(upper-case-p ) IS THIS AN UPPER CASE CHARACTER?
the character
returns true if the character is upper case, nil otherwise

(lower-case-p ) IS THIS A LOWER CASE CHARACTER?
the character
returns true if the character is lower case, nil otherwise

(both-case-p ) IS THIS AN ALPHABETIC (EITHER CASE) CHARACTER?
the character
returns true if the character is alphabetic, nil otherwise

(digit-char-p ) IS THIS A DIGIT CHARACTER?
the character
returns the digit weight if character is a digit, nil otherwise

(char-code ) GET THE ASCII CODE OF A CHARACTER
the character
returns the ASCII character code (integer)

(code-char ) GET THE CHARACTER WITH A SPECFIED ASCII CODE
the ASCII code (integer)
returns the character with that code or nil

(char-upcase ) CONVERT A CHARACTER TO UPPER CASE
the character
returns the upper case character

(char-downcase ) CONVERT A CHARACTER TO LOWER CASE
the character
returns the lower case character

(digit-char ) CONVERT A DIGIT WEIGHT TO A DIGIT
the digit weight (integer)
returns the digit character or nil

(char-int ) CONVERT A CHARACTER TO AN INTEGER
the character
returns the ASCII character code

(int-char ) CONVERT AN INTEGER TO A CHARACTER
the ASCII character code
returns the character with that code













XLISP CHARACTER FUNCTIONS Page 40


(char< ...)
(char<= ...)
(char= ...)
(char/= ...)
(char>= ...)
(char> ...)
the first character to compare
the second character(s) to compare
returns t if predicate is true, nil otherwise
Note: case is significant with these comparison functions.

(char-lessp ...)
(char-not-greaterp ...)
(char-equalp ...)
(char-not-equalp ...)
(char-not-lessp ...)
(char-greaterp ...)
the first string to compare
the second string(s) to compare
returns t if predicate is true, nil otherwise
Note: case is not significant with these comparison functions.










































XLISP INPUT/OUTPUT FUNCTIONS Page 41


INPUT/OUTPUT FUNCTIONS

(read [ [ []]]) READ AN EXPRESSION
the input stream (default is standard input)
the value to return on end of file (default is nil)
recursive read flag (default is nil)
returns the expression read

(print []) PRINT AN EXPRESSION ON A NEW LINE
the expression to be printed
the output stream (default is standard output)
returns the expression

(prin1 []) PRINT AN EXPRESSION
the expression to be printed
the output stream (default is standard output)
returns the expression

(princ []) PRINT AN EXPRESSION WITHOUT QUOTING
the expressions to be printed
the output stream (default is standard output)
returns the expression

(pprint []) PRETTY PRINT AN EXPRESSION
the expressions to be printed
the output stream (default is standard output)
returns the expression

(terpri []) TERMINATE THE CURRENT PRINT LINE
the output stream (default is standard output)
returns nil

(flatsize ) LENGTH OF PRINTED REPRESENTATION USING PRIN1
the expression
returns the length

(flatc ) LENGTH OF PRINTED REPRESENTATION USING PRINC
the expression
returns the length
























XLISP THE FORMAT FUNCTION Page 42


THE FORMAT FUNCTION

(format ...) DO FORMATTED OUTPUT
the output stream
the format string
the format arguments
returns output string if is nil, nil otherwise

The format string can contain characters that should be copied
directly to the output and formatting directives. The
formatting directives are:

~A print next argument using princ
~S print next argument using prin1
~% start a new line
~~ print a tilde character















































XLISP FILE I/O FUNCTIONS Page 43


FILE I/O FUNCTIONS

(open &key :direction) OPEN A FILE STREAM
the file name string or symbol
:direction :input or :output (default is :input)
returns a stream

(close ) CLOSE A FILE STREAM
the stream
returns nil

(read-char []) READ A CHARACTER FROM A STREAM
the input stream (default is standard input)
returns the character

(peek-char [ []]) PEEK AT THE NEXT CHARACTER
flag for skipping white space (default is nil)
the input stream (default is standard input)
returns the character (integer)

(write-char []) WRITE A CHARACTER TO A STREAM
the character to write
the output stream (default is standard output)
returns the character

(read-line []) READ A LINE FROM A STREAM
the input stream (default is standard input)
returns the string

(read-byte []) READ A BYTE FROM A STREAM
the input stream (default is standard input)
returns the byte (integer)

(write-byte []) WRITE A BYTE TO A STREAM
the byte to write (integer)
the output stream (default is standard output)
returns the byte (integer)


























XLISP STRING STREAM FUNCTIONS Page 44


STRING STREAM FUNCTIONS

These functions operate on unnamed streams. An unnamed output
stream collects characters sent to it when it is used as the
destination of any output function. The functions 'get-output-
stream-string' and string or a list of characters.

An unnamed input stream is setup with the 'make-string-input-
stream' function and returns each character of the string when
it is used as the source of any input function.

(make-string-input-stream [ []])
the string
the starting offset
the ending offset + 1
returns an unnamed stream that reads from the string

(make-string-output-stream)
returns an unnamed output stream

(get-output-stream-string )
the output stream
returns the output so far as a string
Note: the output stream is emptied by this function

(get-output-stream-list )
the output stream
returns the output so far as a list
Note: the output stream is emptied by this function


































XLISP SYSTEM FUNCTIONS Page 45


SYSTEM FUNCTIONS

(load &key :verbose :print) LOAD A SOURCE FILE
the filename string or symbol
:verbose the verbose flag (default is t)
:print the print flag (default is nil)
returns the filename

(save ) SAVE WORKSPACE TO A FILE
the filename string or symbol
returns t if workspace was written, nil otherwise

(restore ) RESTORE WORKSPACE FROM A FILE
the filename string or symbol
returns nil on failure, otherwise never returns

(dribble []) CREATE A FILE WITH A TRANSCRIPT OF A SESSION
file name string or symbol
(if missing, close current transcript)
returns t if the transcript is opened, nil if it is closed

(gc) FORCE GARBAGE COLLECTION
returns nil

(expand ) EXPAND MEMORY BY ADDING SEGMENTS
the number of segments to add
returns the number of segments added

(alloc ) CHANGE NUMBER OF NODES TO ALLOCATE IN EACH SEGMENT
the number of nodes to allocate

returns the old number of nodes to allocate

(room) SHOW MEMORY ALLOCATION STATISTICS
returns nil

(type-of ) RETURNS THE TYPE OF THE EXPRESSION
the expression to return the type of
returns nil if the value is nil otherwise one of the symbols:
SYMBOL for symbols
OBJECT for objects
CONS for conses
SUBR for built-in functions
FSUBR for special forms
CLOSURE for defined functions
STRING for strings
FIXNUM for integers
FLONUM for floating point numbers
CHARACTER for characters
FILE-STREAM for file pointers
UNNAMED-STREAM for unnamed streams
ARRAY for arrays












XLISP SYSTEM FUNCTIONS Page 46


(peek ) PEEK AT A LOCATION IN MEMORY
the address to peek at (integer)
returns the value at the specified address (integer)

(poke ) POKE A VALUE INTO MEMORY
the address to poke (integer)
the value to poke into the address (integer)
returns the value

(address-of ) GET THE ADDRESS OF AN XLISP NODE
the node
returns the address of the node (integer)

(exit) EXIT XLISP
returns never returns
















































XLISP EXAMPLES Page 47


FILE I/O FUNCTIONS

Input from a File

To open a file for input, use the OPEN function with the keyword
argument :DIRECTION set to :INPUT. To open a file for output,
use the OPEN function with the keyword argument :DIRECTION set
to :OUTPUT. The OPEN function takes a single required argument
which is the name of the file to be opened. This name can be in
the form of a string or a symbol. The OPEN function returns an
object of type FILE-STREAM if it succeeds in opening the
specified file. It returns the value NIL if it fails. In order
to manipulate the file, it is necessary to save the value
returned by the OPEN function. This is usually done by
assigning it to a variable with the SETQ special form or by
binding it using LET or LET*. Here is an example:

(setq fp (open "init.lsp" :direction :input))

Evaluating this expression will result in the file "init.lsp"
being opened. The file object that will be returned by the OPEN
function will be assigned to the variable "fp".

It is now possible to use the file for input. To read an
expression from the file, just supply the value of the "fp"
variable as the optional "stream" argument to READ.

(read fp)

Evaluating this expression will result in reading the first
expression from the file "init.lsp". The expression will be
returned as the result of the READ function. More expressions
can be read from the file using further calls to the READ
function. When there are no more expressions to read, the READ
function will return NIL (or whatever value was supplied as the
second argument to READ).

Once you are done reading from the file, you should close it.
To close the file, use the following expression:

(close fp)

Evaluating this expression will cause the file to be closed.




















XLISP EXAMPLES Page 48


Output to a File

Writing to a file is pretty much the same as reading from one.
You need to open the file first. This time you should use the
OPEN function to indicate that you will do output to the file.
For example:

(setq fp (open "test.dat" :direction :output))

Evaluating this expression will open the file "test.dat" for
output. If the file already exists, its current contents will
be discarded. If it doesn't already exist, it will be created.
In any case, a FILE-STREAM object will be returned by the OPEN
function. This file object will be assigned to the "fp"
variable.

It is now possible to write to this file by supplying the value
of the "fp" variable as the optional "stream" parameter in the
PRINT function.

(print "Hello there" fp)

Evaluating this expression will result in the string "Hello
there" being written to the file "test.dat". More data can be
written to the file using the same technique.

Once you are done writing to the file, you should close it.
Closing an output file is just like closing an input file.

(close fp)

Evaluating this expression will close the output file and make
it permanent.






























XLISP EXAMPLES Page 49


A Slightly More Complicated File Example

This example shows how to open a file, read each Lisp expression
from the file and print it. It demonstrates the use of files
and the use of the optional "stream" argument to the READ
function.

(do* ((fp (open "test.dat" :direction :input))
(ex (read fp) (read fp)))
((null ex) nil)
(print ex))



















































 December 28, 2017  Add comments

Leave a Reply