home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari FTP
/
ATARI_FTP_0693.zip
/
ATARI_FTP_0693
/
Languages
/
Xlisp2.1
/
xlispdoc.txz
/
xlispdoc
Wrap
Text File
|
1992-10-30
|
174KB
|
3,916 lines
XLISP: An Object-oriented Lisp
Version 2.0
February 6, 1988
by
David Michael Betz
P.O. Box 144
Peterborough, NH 03458
(603) 924-4145 (home)
Copyright (c) 1988, by David Michael Betz
All Rights Reserved
Permission is granted for unrestricted non-commercial use
Additions to the manual u_n_d_e_r_l_i_n_e_d_, by Tom Almy October 26, 1990.
This distributed version has the added functions of XLISP 2.1
incorporated, as well as other enhancements, all of which can be
eliminated via compilation options.
Table of Contents
INTRODUCTION . . . . . . . . . . . . . . . . . . . . . . . . . . 1
A NOTE FROM THE AUTHOR . . . . . . . . . . . . . . . . . . . . . 2
XLISP COMMAND LOOP . . . . . . . . . . . . . . . . . . . . . . . 3
BREAK COMMAND LOOP . . . . . . . . . . . . . . . . . . . . . . . 5
DATA TYPES . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
THE EVALUATOR . . . . . . . . . . . . . . . . . . . . . . . . . . 8
HOOK FUNCTIONS . . . . . . . . . . . . . . . . . . . . . . . . . 9
LEXICAL CONVENTIONS . . . . . . . . . . . . . . . . . . . . . . . 10
READTABLES . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
LAMBDA LISTS . . . . . . . . . . . . . . . . . . . . . . . . . . 14
OBJECTS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
SYMBOLS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
EVALUATION FUNCTIONS . . . . . . . . . . . . . . . . . . . . . . 21
SYMBOL FUNCTIONS . . . . . . . . . . . . . . . . . . . . . . . . 23
PROPERTY LIST FUNCTIONS . . . . . . . . . . . . . . . . . . . . . 26
ARRAY FUNCTIONS . . . . . . . . . . . . . . . . . . . . . . . . . 27
SEQUENCE FUNCTIONS . . . . . . . . . . . . . . . . . . . . . . . 28
LIST FUNCTIONS . . . . . . . . . . . . . . . . . . . . . . . . . 32
DESTRUCTIVE LIST FUNCTIONS . . . . . . . . . . . . . . . . . . . 36
ARITHMETIC FUNCTIONS . . . . . . . . . . . . . . . . . . . . . . 37
BITWISE LOGICAL FUNCTIONS . . . . . . . . . . . . . . . . . . . . 40
STRING FUNCTIONS . . . . . . . . . . . . . . . . . . . . . . . . 41
CHARACTER FUNCTIONS . . . . . . . . . . . . . . . . . . . . . . . 43
STRUCTURE FUNCTIONS . . . . . . . . . . . . . . . . . . . . . . . 45
OBJECT FUNCTIONS . . . . . . . . . . . . . . . . . . . . . . . . 47
PREDICATE FUNCTIONS . . . . . . . . . . . . . . . . . . . . . . . 49
XLISP 2.0 Table of Contents
CONTROL CONSTRUCTS . . . . . . . . . . . . . . . . . . . . . . . 52
LOOPING CONSTRUCTS . . . . . . . . . . . . . . . . . . . . . . . 55
THE PROGRAM FEATURE . . . . . . . . . . . . . . . . . . . . . . . 56
INPUT/OUTPUT FUNCTIONS . . . . . . . . . . . . . . . . . . . . . 58
THE FORMAT FUNCTION . . . . . . . . . . . . . . . . . . . . . . . 60
FILE I/O FUNCTIONS . . . . . . . . . . . . . . . . . . . . . . . 61
STRING STREAM FUNCTIONS . . . . . . . . . . . . . . . . . . . . . 63
DEBUGGING AND ERROR HANDLING FUNCTIONS . . . . . . . . . . . . . 64
SYSTEM FUNCTIONS . . . . . . . . . . . . . . . . . . . . . . . . 66
ADDITIONAL FUNCTIONS AND UTILITIES . . . . . . . . . . . . . . . 69
EXAMPLES: FILE I/O FUNCTIONS . . . . . . . . . . . . . . . . . . 73
INDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
XLISP 2.0 INTRODUCTION Page 1
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 2.0 A NOTE FROM THE AUTHOR Page 2
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 2.0 XLISP COMMAND LOOP Page 3
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, o_r_
t_h_e_ "_-_w_"_ f_l_a_g_ i_s_ i_n_ t_h_e_ c_o_m_m_a_n_d_ l_i_n_e_,_ XLISP builds an initial
workspace, empty except for the built-in functions and symbols.
Then,_ p_r_o_v_i_d_i_n_g_ x_l_i_s_p_._w_k_s_ w_a_s_ n_o_t_ l_o_a_d_e_d_,_ 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). I_f_ t_h_e_ "_-_v_"_ f_l_a_g_ i_s_ i_n_ t_h_e_ c_o_m_m_a_n_d_ l_i_n_e_,_ t_h_e_n_ t_h_e_ f_i_l_e_s_ a_r_e_
l_o_a_d_e_d_ v_e_r_b_o_s_e_l_y_._ T_h_e_ o_p_t_i_o_n_ "_-_t_ f_i_l_e_n_a_m_e_"_ w_i_l_l_ o_p_e_n_ a_ t_r_a_n_s_c_r_i_p_t_ f_i_l_e_
o_f_ t_h_e_ n_a_m_e_ "_f_i_l_e_n_a_m_e_"_._
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.
T_h_e_ f_o_l_l_o_w_i_n_g_ c_o_n_t_r_o_l_ c_h_a_r_a_c_t_e_r_s_ c_a_n_ b_e_ u_s_e_d_ w_h_i_l_e_ X_L_I_S_P_ i_s_ w_a_i_t_i_n_g_
f_o_r_ i_n_p_u_t_:_
B_a_c_k_s_p_a_c_e_ d_e_l_e_t_e_ l_a_s_t_ c_h_a_r_a_c_t_e_r_
D_e_l_ d_e_l_e_t_e_ l_a_s_t_ c_h_a_r_a_c_t_e_r_
t_a_b_ t_a_b_s_ o_v_e_r_ (_t_r_e_a_t_e_d_ a_s_ s_p_a_c_e_ b_y_ X_L_I_S_P_ r_e_a_d_e_r_)_
c_t_r_l_-_C_ g_o_t_o_ t_o_p_ l_e_v_e_l_
c_t_r_l_-_G_ c_l_e_a_n_u_p_ a_n_d_ r_e_t_u_r_n_ o_n_e_ l_e_v_e_l_
c_t_r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_d_i_t_o_r_
l_i_k_e_ E_P_S_I_L_O_N_._ I_n_ t_h_i_s_ c_a_s_e_,_ n_o_r_m_a_l_ c_o_m_m_a_n_d_ l_i_n_e_ e_d_i_t_i_n_g_ i_s_ a_v_a_i_l_a_b_l_e_,_
b_u_t_ t_h_e_ c_o_n_t_r_o_l_ k_e_y_s_ w_i_l_l_ n_o_t_ w_o_r_k_ (_i_n_ p_a_r_t_i_c_u_l_a_r_,_ c_t_r_l_-_C_ w_i_l_l_ c_a_u_s_e_
XLISP 2.0 XLISP COMMAND LOOP Page 4
t_h_e_ p_r_o_g_r_a_m_ t_o_ e_x_i_t_!_)_._ U_s_e_ t_h_e_ X_L_I_S_P_ f_u_n_c_t_i_o_n_s_ t_o_p_-_l_e_v_e_l_,_ c_l_e_a_n_-_u_p_,_
a_n_d_ c_o_n_t_i_n_u_e_ i_n_s_t_e_a_d_ o_f_ c_t_r_l_-_C_,_ c_t_r_l_-_G_,_ a_n_d_ c_t_r_l_-_P_._
XLISP 2.0 BREAK COMMAND LOOP Page 5
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 2.0 DATA TYPES Page 6
DATA TYPES
(_M_a_j_o_r_ m_o_d_i_f_i_c_a_t_i_o_n_s_)_
There are several different data types available to XLISP
programmers. Typical implementation limits are shown for 32 bit word
systems. Values in square brackets apply to 16 bit MS-DOS
implementations.
All data nodes are effectively cons cells consisting of two pointers
and and one or two bytes of identification flags (9 or 10 bytes per
cell). Node space is managed and garbage collected by XLISP. Array and
string storage is either allocated by the C runtime or managed and
garbaged collected by XLISP (compilation option). If C does the
allocation, memory fragmentation can occur. Fragmentation can be
eliminated by saving the image and restarting XLISP.
lists
NIL is a special pointer.
arrays
The CDR field of an array points to the dynamically allocated
data array, while the CAR contains the integer length of the
array. Elements in the data array are pointers to other cells
[Size limited to 16383]
character strings
Implemented like arrays, except string array is byte indexed and
contains the actual characters. Note that unlike the underlying
C, the null character (value 0) is valid. [Size limited to 32767]
symbols
Implemented as a 4 element array. The elements are value cell,
function cell, property list, and print name (a character string
node).
integers
Small integers (> -129 and <256) are statically allocated and are
thus always EQ integers of the same value. The CAR field is used
to hold the value, which is a 32 bit signed integer.
characters
All characters are statically allocated and are thus EQ
characters of the same value. The CAR field is used to hold the
value. In XLISP characters are "unsigned" and thus range in value
from 0 to 255.
floats
The CAR and CDR fields hold the value, which is typically a 64
bit IEEE floating point number.
objects
Implemented as an array of instance variable count plus one
elements. The first element is the object's class, while the
remaining arguments are the instance variables.
XLISP 2.0 DATA TYPES Page 7
streams (file)
The CAR and CDR fields are used in a system dependent way as a
file pointer. Files are not kept open across image saves, but the
standard files are opened automatically during image restores.
streams (string)
Implemented as a TCONC list of characters (see page 34).
subrs (built-in functions)
The CAR field points to the actual code to execute, while the CDR
field is an internal pointer to the name of the function.
fsubrs (special forms)
Same implementation as subrs.
closures (user defined functions)
Implemented as an array of 11 elements:
1. name symbol or NIL
2. 'lambda or 'macro
3. list of required arguments
4. optional arguments as list of (<arg> <init> <specified-p>)
triples.
5. &rest argument
6. &key arguments as list of (<key> <arg> <init> <specified-p>)
quadruples.
7. &aux arguments as list of (<arg> <init>) pairs.
8. function body
9. value environment (see page 65 for format)
10. function environment
11. argument list (unprocessed)
structures
Implemented as an array with first element being a pointer to the
structure name string, and the remaining elements being the
structure elements.
XLISP 2.0 THE EVALUATOR Page 8
THE EVALUATOR
The process of evaluation in XLISP:
Strings, integers, characters, floats, objects, arrays, s_t_r_u_c_t_u_r_e_s_,_
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 applied to these evaluated
expressions.
If it is an fsubr, the fsubr is called with the remaining list
elements as arguments (unevaluated).
If it is a macro, the macro is expanded with the remaining list
elements as arguments (unevaluated). The macro expansion is then
evaluated in place of the original macro call.
XLISP 2.0 HOOK FUNCTIONS Page 9
HOOK FUNCTIONS
(_N_e_w_ s_e_c_t_i_o_n_)_
The evalhook and applyhook facility are useful for implementing
debugging programs or just observing the operation of XLISP. It is
possible to control evaluation of forms in any context.
If the symbol '*evalhook*' is bound to a function closure, then every
call of eval will call this function. The function takes two
arguements, the form to be evaluated and execution environment. During
the execution of this function, *evalhook* (and *applyhook*) are
dynamically bound to NIL to prevent undesirable recursion. This "hook"
function returns the result of the evaluation.
If the symbol '*applyhook*' is bound to a function, then every
function application within an eval will call this function (note that
the function apply, and others which do not use eval, will not invoke
the apply hook function). The function takes two arguments, the
function closure and the argument list (which is already evaluated).
During execution of this hook function, *applyhook* (and *evalhook*)
are dynamically bound to NIL to prevent undesired recursion. This
function is to return the result of the function application.
Note that the hook functions cannot reset *evalhook* or *applyhook* to
NIL, because upon exit these values will be reset. An excape mechanism
is provided -- execution of 'top-level', or any error that causes
return to the top level, will unhook the functions. Applications
should bind these values either via 'progv', 'evalhook', or
'applyhook'.
The functions 'evalhook' and 'applyhook' allowed for controlled
application of the hook functions. The form supplied as an argument to
'evalhook', or the function application given to 'applyhook', are not
hooked themselves, but any subsidiary forms and applications are. In
addition, by supplying NIL values for the hook functions, 'evalhook'
can be used to execute a form within a specific environment passed as
an argument.
XLISP 2.0 LEXICAL CONVENTIONS Page 10
LEXICAL CONVENTIONS
(_M_a_j_o_r_ e_x_p_a_n_s_i_o_n_ o_f_ o_r_i_g_i_n_a_l_ d_o_c_u_m_e_n_t_)_
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.
Except when escape sequences are used, symbol names in XLISP can
consist of any sequence of non-blank printable characters except the
terminating macro characters:
( ) ' ` , " ;
and the escape characters:
\ |
In addition, the first character may not be '#' (non-terminating macro
character), nor may the symbol have identical syntax with an integer
or floating point literal. Uppercase and lowercase characters are not
distinguished within symbol names. All lowercase characters are mapped
to uppercase on input.
Any printing character, including whitespace, may be part of a symbol
name when escape characters are used. The backslash escapes the
following character, while multiple characters can be escaped by
placing them between vertical bars. At all times the backslash must be
used to escape either escape characters.
For semantic reasons, certain chararacter sequences should/can never
be used as symbols in XLISP. A single period is used to denote dotted
lists. The symbol NIL represents an empty list. Symbols starting with
a colon are keywords, and will always evaluate to themselves. Thus
they should not be used as regular symbols. The symbol T is also
reserved for use as the truth value.
Integer literals consist of a sequence of digits optionally beginning
with a sign ('+' 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 sign ('+' or '-') and including one or both of an
embedded decimal point or a trailing exponent. The optional exponent
is denoted by an 'E' followed by an optional sign and one or more
digits. The range of values a floating point number can represent is
XLISP 2.0 LEXICAL CONVENTIONS Page 11
limited by the size of a C 'float' ('double' on machines with 32 bit
addresses) on the machine on which XLISP is running.
Integer and floating point literals cannot have embedded escape
characters. If they do, they are treated as symbols. Thus '12\3' is a
symbol even though it would appear to be identical to '123'.
Character literals are handled via the #\ read-macro construct:
#\<char> == the ASCII code of the printing character
#\newline == ASCII linefeed character
#\space == ASCII space character
#\rubout == ASCII rubout (DEL)
#\C-<char> == ASCII control character
#\M-<char> == ASCII character with msb set (Meta character)
#\M-C-<char> == ASCII control character with msb set
Literal strings are sequences of characters surrounded by double
quotes (the " read-macro). 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 2.0 READTABLES Page 12
READTABLES
(_M_a_j_o_r_ m_o_d_i_f_i_c_a_t_i_o_n_s_)_
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 -- if it is changed then the section LEXICAL CONVENTIONS
may not apply. The readtable is an array with 256 entries, one for
each of the extended ASCII character codes. Each entry contains one of
the following values, with the initial entries assigned to the values
indicated:
:white-space A whitespace character - tab, cr, lf, ff,
space
(:tmacro . fun) terminating readmacro - ( ) " , ; ' `
(:nmacro . fun) non-terminating readmacro - #
:sescape Single escape character - \
:mescape Multiple escape character - |
:constituent Indicating a symbol constituent (all printing
characters not listed above)
nil Indicating an invalid character (everything
else)
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 takes 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. A :nmacro is
a symbol constituent except as the first character of a symbol.
As an example, the following read macro allows the square brackets to
be used as a more visibly appealing alternative to the SEND function:
XLISP 2.0 READTABLES Page 13
(setf (aref *readtable* (char-int #\[)) ; #\[ table entry
(cons :tmacro
(lambda (f c &aux ex) ; second arg is not used
(do ()
((eq (peek-char t f) #\]))
(setf ex (append ex (list (read f)))))
(read-char f) ; toss the trailing #\]
(cons (cons 'send ex) nil))))
(setf (aref *readtable* (char-int #\]))
(cons :tmacro
(lambda (f c)
(error "misplaced right bracket"))))
XLISP defines several useful read macros:
'<expr> == (quote <expr>)
`<expr> == (backquote <expr>)
,<expr> == (comma <expr>)
,@<expr> == (comma-at <expr>)
#'<expr> == (function <expr>)
#(<expr>...) == an array of the specified expressions
#S(<structtype> [<slotname> <value>]...)
== structure of specified type and initial
values
#.<expr> == result of evaluating <expr>
#x<hdigits> == a hexadecimal number (0-9,A-F)
#o<odigits> == an octal number (0-7)
#b<bdigits> == a binary number (0-1)
#| |# == a comment
#:<symbol> == an uninterned symbol
XLISP 2.0 LAMBDA LISTS Page 14
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'. T_h_e_ &_a_l_l_o_w_-_o_t_h_e_r_-_k_e_y_s_
m_a_r_k_e_r_ i_s_ i_g_n_o_r_e_d_._
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 2.0 LAMBDA LISTS Page 15
Here is the complete syntax for lambda lists:
(<rarg>...
[&optional [<oarg> | (<oarg> [<init> [<svar>]])]...]
[&rest <rarg>]
[&key
[<karg> | ([<karg> | (<key> <karg>)] [<init> [<svar>]])] ...
&allow-other-keys]
[&aux [<aux> | (<aux> [<init>])]...])
where:
<rarg> is a required argument symbol
<oarg> is an &optional argument symbol
<rarg> is the &rest argument symbol
<karg> is a &key argument symbol
<key> is a keyword symbol
<aux> is an auxiliary variable symbol
<init> is an initialization expression
<svar> is a supplied-p variable symbol
XLISP 2.0 OBJECTS Page 16
OBJECTS
Definitions:
selector - a symbol used to select an appropriate method
message - a selector and a list of actual arguments
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.
T_o_ p_e_r_f_o_r_m_ a_ m_e_t_h_o_d_ l_o_o_k_u_p_ s_t_a_r_t_i_n_g_ w_i_t_h_ t_h_e_ o_b_j_e_c_t_'_s_ s_u_p_e_r_c_l_a_s_s_
r_a_t_h_e_r_ t_h_a_n_ i_t_s_ c_l_a_s_s_,_ u_s_e_ t_h_e_ f_u_n_c_t_i_o_n_ '_s_e_n_d_-_s_u_p_e_r_'_._ 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.
T_w_o_ o_b_j_e_c_t_s_,_ b_o_t_h_ c_l_a_s_s_e_s_,_ a_r_e_ p_r_e_d_e_f_i_n_e_d_:_ O_b_j_e_c_t_ a_n_d_ C_l_a_s_s_._ B_o_t_h_
O_b_j_e_c_t_ a_n_d_ C_l_a_s_s_ a_r_e_ o_f_ c_l_a_s_s_ C_l_a_s_s_._ T_h_e_ s_u_p_e_r_c_l_a_s_s_ o_f_ C_l_a_s_s_ i_s_
O_b_j_e_c_t_,_ w_h_i_l_e_ O_b_j_e_c_t_ h_a_s_ n_o_ s_u_p_e_r_c_l_a_s_s_._ T_y_p_i_c_a_l_ u_s_e_ i_s_ t_o_ c_r_e_a_t_e_ n_e_w_
c_l_a_s_s_e_s_ (_b_y_ s_e_n_d_i_n_g_ :_n_e_w_ t_o_ C_l_a_s_s_)_ t_o_ r_e_p_r_e_s_e_n_t_ a_p_p_l_i_c_a_t_i_o_n_ o_b_j_e_c_t_s_._
O_b_j_e_c_t_s_ o_f_ t_h_e_s_e_ c_l_a_s_s_e_s_,_ c_r_e_a_t_e_d_ b_y_ s_e_n_d_i_n_g_ :_n_e_w_ t_o_ t_h_e_ a_p_p_r_o_p_r_i_a_t_e_
n_e_w_ c_l_a_s_s_,_ a_r_e_ s_u_b_c_l_a_s_s_e_s_ o_f_ O_b_j_e_c_t_._ T_h_e_ O_b_j_e_c_t_ m_e_t_h_o_d_ :_s_h_o_w_ c_a_n_ b_e_
u_s_e_d_ t_o_ v_i_e_w_ t_h_e_ c_o_n_t_e_n_t_s_ o_f_ a_n_y_ o_b_j_e_c_t_._
XLISP 2.0 OBJECTS Page 17
THE 'Object' CLASS
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
:_p_r_i_n_1_ [_<_s_t_r_e_a_m_>_]_ P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e_f_i_n_e_d_ i_n_ c_l_a_s_s_e_s_._l_s_p_)_
:_s_t_o_r_e_o_n_ R_E_A_D_ R_E_P_R_E_S_E_N_T_A_T_I_O_N_
r_e_t_u_r_n_s_ a_ l_i_s_t_,_ t_h_a_t_ w_h_e_n_ e_x_e_c_u_t_e_d_ w_i_l_l_ c_r_e_a_t_e_ a_ c_o_p_y_
o_f_ t_h_e_ o_b_j_e_c_t_._ O_n_l_y_ w_o_r_k_s_ f_o_r_ m_e_m_b_e_r_s_ o_f_
c_l_a_s_s_e_s_ c_r_e_a_t_e_d_ w_i_t_h_ d_e_f_c_l_a_s_s_._
(_d_e_f_i_n_e_d_ i_n_ c_l_a_s_s_e_s_._l_s_p_)_
XLISP 2.0 OBJECTS Page 18
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 <ivars> [<cvars> [<super>]] INITIALIZE A NEW CLASS
<ivars> the list of instance variable symbol
<cvars> the list of class variable symbols
<super> the superclass (default is Object)
returns the new class object
:answer <msg> <fargs> <code> ADD A MESSAGE TO A CLASS
<msg> the message symbol
<fargs> the formal argument list (lambda list)
<code> a list of executable expressions
returns the object
:_s_u_p_e_r_c_l_a_s_s_ G_E_T_ T_H_E_ S_U_P_E_R_C_L_A_S_S_ O_F_ T_H_E_ O_B_J_E_C_T_
r_e_t_u_r_n_s_ t_h_e_ s_u_p_e_r_c_l_a_s_s_ (_o_f_ t_h_e_ c_l_a_s_s_)_
(_d_e_f_i_n_e_d_ i_n_ c_l_a_s_s_e_s_._l_s_p_)_
:_m_e_s_s_a_g_e_s_ G_E_T_ T_H_E_ L_I_S_T_ O_F_ M_E_S_S_A_G_E_S_ O_F_ T_H_E_ C_L_A_S_S_
r_e_t_u_r_n_s_ a_s_s_o_c_i_a_t_i_o_n_ l_i_s_t_ o_f_ m_e_s_s_a_g_e_ s_e_l_e_c_t_o_r_s_ a_n_d_
c_l_o_s_u_r_e_s_ f_o_r_ m_e_s_s_a_g_e_s_._
(_d_e_f_i_n_e_d_ i_n_ c_l_a_s_s_e_s_._l_s_p_)_
:_s_t_o_r_e_o_n_ R_E_A_D_ R_E_P_R_E_S_E_N_T_A_T_I_O_N_
r_e_t_u_r_n_s_ a_ l_i_s_t_,_ t_h_a_t_ w_h_e_n_ e_x_e_c_u_t_e_d_ w_i_l_l_ r_e_-_c_r_e_a_t_e_ t_h_e_
c_l_a_s_s_ a_n_d_ i_t_s_ m_e_t_h_o_d_s_._
(_d_e_f_i_n_e_d_ i_n_ c_l_a_s_s_e_s_._l_s_p_)_
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. T_h_e_r_e_f_o_r_e_,_ w_h_e_n_ a_ n_e_w_ c_l_a_s_s_ i_s_ c_r_e_a_t_e_d_ b_y_ s_e_n_d_i_n_g_
'_:_n_e_w_'_ t_o_ c_l_a_s_s_ '_C_l_a_s_s_'_ t_h_e_ m_e_s_s_a_g_e_ '_:_i_s_n_e_w_'_ i_s_ s_e_n_t_ t_o_ C_l_a_s_s_
a_u_t_o_m_a_t_i_c_a_l_l_y_._ T_o_ c_r_e_a_t_e_ a_ n_e_w_ c_l_a_s_s_,_ a_ f_u_n_c_t_i_o_n_ o_f_ t_h_e_ f_o_l_l_o_w_i_n_g_
f_o_r_m_a_t_ i_s_ u_s_e_d_:_
(_s_e_t_q_ <_n_e_w_c_l_a_s_s_n_a_m_e_>_ (_s_e_n_d_ C_l_a_s_s_ :_n_e_w_ <_i_v_a_r_s_>_ [_<_c_v_a_r_s_>_ [_<_s_u_p_e_r_>_]_]_)_)_
When a new class is created, 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 2.0 OBJECTS Page 19
I_N_S_T_A_N_C_E_ V_A_R_I_A_B_L_E_S_ O_F_ C_L_A_S_S_ '_C_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_b_j_e_c_t_ -_ t_h_e_ c_l_a_s_s_ '_O_b_j_e_c_t_'_
_ c_l_a_s_s_ -_ t_h_e_ c_l_a_s_s_ '_C_l_a_s_s_'_
*obarray* - the object hash table
*standard-input* - the standard input stream,_ s_t_d_i_n_
*standard-output* - the standard output stream,_ s_t_d_o_u_t_
*error-output* - the error output stream,_ s_t_d_e_r_r_
*trace-output* - the trace output stream,_ d_e_f_a_u_l_t_s_ t_o_ s_t_d_e_r_r_
*debug-io* - the break loop i/o stream,_ d_e_f_a_u_l_t_s_ t_o_ s_t_d_e_r_r_
*breakenable* - flag controlling entering break loop on errors
*tracelist* - list of names of functions to trace
*tracenable* - enable trace back printout on errors
*tracelimit* - number of levels of trace back information
*evalhook* - user substitute for the evaluator function
*applyhook* - u_s_e_r_ s_u_b_s_t_i_t_u_t_e_ f_o_r_ f_u_n_c_t_i_o_n_ a_p_p_l_i_c_a_t_i_o_n_
*readtable* - the current readtable
*unbound* - indicator for unbound symbols
*gc-flag* - controls the printing of gc messages
*gc-hook* - function to call after garbage collection
*integer-format* - format for printing integers ("%d" or "%ld")
*float-format* - format for printing floats ("%g")
*print-case* - symbol output case (:upcase or :downcase)
_ *_p_r_i_n_t_-_l_e_v_e_l_*_ -_ l_i_s_t_ l_e_v_e_l_s_ b_e_y_o_n_d_ t_h_i_s_ s_e_t_t_i_n_g_ a_r_e_ p_r_i_n_t_e_d_ a_s_
'_#_'_
_ *_p_r_i_n_t_-_l_e_n_g_t_h_*_ -_ l_i_s_t_s_ l_o_n_g_e_r_ t_h_a_n_ t_h_i_s_ s_e_t_t_i_n_g_ a_r_e_ p_r_i_n_t_e_d_ a_s_
'_._._._'_
_ *_d_o_s_-_i_n_p_u_t_*_ -_ u_s_e_ d_o_s_ l_i_n_e_ i_n_p_u_t_ f_u_n_c_t_i_o_n_ f_o_r_ r_e_a_d_._
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.
I_n_t_e_n_d_e_d_ t_o_ b_e_ a_d_d_e_d_:_
_ *_p_r_i_n_t_-_b_a_s_e_*_ -_ r_a_d_i_x_ u_s_e_d_ i_n_ p_r_i_n_t_i_n_g_ i_n_t_e_g_e_r_s_._
XLISP 2.0 EVALUATION FUNCTIONS Page 21
EVALUATION FUNCTIONS
(eval <expr>) EVALUATE AN XLISP EXPRESSION
<expr> the expression to be evaluated
returns the result of evaluating the expression
(apply <fun> <args>) APPLY A FUNCTION TO A LIST OF ARGUMENTS
<fun> the function to apply (or function symbol). M_a_y_ n_o_t_ b_e_
m_a_c_r_o_ o_r_ f_s_u_b_r_._
<args> the argument list (_u_n_l_i_k_e_ C_o_m_m_o_n_ L_i_s_p_,_ o_n_l_y_ o_n_e_
a_l_l_o_w_e_d_)_
returns the result of applying the function to the arguments
(funcall <fun> <arg>...) CALL A FUNCTION WITH ARGUMENTS
<fun> the function to call (or function symbol). M_a_y_ n_o_t_ b_e_
m_a_c_r_o_ o_r_ f_s_u_b_r_._
<arg> arguments to pass to the function
returns the result of calling the function with the arguments
(quote <expr>) RETURN AN EXPRESSION UNEVALUATED
f_s_u_b_r_
<expr> the expression to be quoted (quoted)
returns <expr> unevaluated
(function <expr>) GET THE FUNCTIONAL INTERPRETATION
f_s_u_b_r_
<expr> the symbol or lambda expression (quoted)
returns the functional interpretation
(backquote <expr>) FILL IN A TEMPLATE
f_s_u_b_r_
<expr> the template (quoted)
returns a copy of the template with comma and comma-at
expressions expanded.
(_c_o_m_m_a_ <_e_x_p_r_>_)_ C_O_M_M_A_ E_X_P_R_E_S_S_I_O_N_
(_N_e_v_e_r_ e_x_e_c_u_t_e_d_)_ A_s_ t_h_e_ o_b_j_e_c_t_ o_f_ a_ b_a_c_k_q_u_o_t_e_ e_x_p_a_n_s_i_o_n_,_ t_h_e_
e_x_p_r_e_s_s_i_o_n_ i_s_ e_v_a_l_u_a_t_e_d_ a_n_d_ b_e_c_o_m_e_s_ a_n_ o_b_j_e_c_t_ i_n_ t_h_e_ e_n_c_l_o_s_i_n_g_
l_i_s_t_._
(_c_o_m_m_a_-_a_t_ <_e_x_p_r_>_)_ C_O_M_M_A_-_A_T_ E_X_P_R_E_S_S_I_O_N_
(_N_e_v_e_r_ e_x_e_c_u_t_e_d_)_ A_s_ t_h_e_ o_b_j_e_c_t_ o_f_ a_ b_a_c_k_q_u_o_t_e_ e_x_p_a_n_s_i_o_n_,_ t_h_e_
e_x_p_r_e_s_s_i_o_n_ i_s_ e_v_a_l_u_a_t_e_d_ (_a_n_d_ m_u_s_t_ e_v_a_l_u_a_t_e_ t_o_ a_ l_i_s_t_)_ a_n_d_ i_s_ t_h_e_n_
s_p_l_i_c_e_d_ i_n_t_o_ t_h_e_ e_n_c_l_o_s_i_n_g_ l_i_s_t_._
(lambda <args> <expr>...) MAKE A FUNCTION CLOSURE
f_s_u_b_r_
<args> formal argument list (lambda list) (quoted)
<expr> expressions of the function body (quoted)
returns the function closure
XLISP 2.0 EVALUATION FUNCTIONS Page 22
(get-lambda-expression <closure>) GET THE LAMBDA EXPRESSION
<closure> the closure
returns the original lambda expression
(macroexpand <form>) RECURSIVELY EXPAND MACRO CALLS
<form> the form to expand
returns the macro expansion
(macroexpand-1 <form>) EXPAND A MACRO CALL
<form> the macro call form
returns the macro expansion
XLISP 2.0 SYMBOL FUNCTIONS Page 23
SYMBOL FUNCTIONS
(set <sym> <expr>) SET THE G_L_O_B_A_L_ VALUE OF A SYMBOL
<sym> the symbol being set
<expr> the new value
returns the new value
(setq [<sym> <expr>]...) SET THE VALUE OF A SYMBOL
f_s_u_b_r_
<sym> the symbol being set (quoted)
<expr> the new value
returns the new value
(psetq [<sym> <expr>]...) PARALLEL VERSION OF SETQ
f_s_u_b_r_._ A_l_l_ e_x_p_r_e_s_s_i_o_n_s_ a_r_e_ e_v_a_l_u_a_t_e_d_ b_e_f_o_r_e_ a_n_y_ a_s_s_i_g_n_m_e_n_t_s_
a_r_e_ m_a_d_e_._
<sym> the symbol being set (quoted)
<expr> the new value
returns the new value
(setf [<place> <expr>]...) SET THE VALUE OF A FIELD
f_s_u_b_r_
<place> the field specifier (quoted):
<sym> set value of a symbol
(car <expr>) set car of a cons node
(cdr <expr>) set cdr of a cons node
(nth <n> <expr>) set nth car of a list
(aref <expr> <n>) set nth element of an array o_r_
s_t_r_i_n_g_
(_e_l_t_ <_e_x_p_r_>_ <_n_>_)_ s_e_t_ n_t_h_ e_l_e_m_e_n_t_ o_f_ a_ s_e_q_u_e_n_c_e_
(get <sym> <prop>) set value of a property
(symbol-value <sym>) set value of a symbol
(symbol-function <sym>) functional value of a
symbol
(symbol-plist <sym>) set property list of a
symbol
(_s_e_n_d_ <_o_b_j_>_ :_<_i_v_a_r_>_)_ (_W_h_e_n_ c_l_a_s_s_e_s_._l_s_p_ u_s_e_d_)_,_
s_e_t_ i_n_s_t_a_n_c_e_ v_a_r_i_a_b_l_e_ o_f_
o_b_j_e_c_t_._
(_<_s_y_m_>_-_<_e_l_e_m_e_n_t_>_ <_s_t_r_u_c_t_>_)_ (_W_h_e_n_ s_t_r_u_c_t_._l_s_p_ u_s_e_d_)_,_
s_e_t_ t_h_e_ e_l_e_m_e_n_t_ o_f_
s_t_r_u_c_t_u_r_e_ s_t_r_u_c_t_,_ t_y_p_e_
s_y_m_._
(_<_f_i_e_l_d_s_y_m_>_ <_a_r_g_s_>_)_ t_h_e_ f_u_n_c_t_i_o_n_ s_t_o_r_e_d_ i_n_ p_r_o_p_e_r_t_y_
*_s_e_t_f_*_ i_n_ s_y_m_b_o_l_ <_f_i_e_l_d_s_y_m_>_ i_s_
a_p_p_l_i_e_d_ t_o_ (_<_a_r_g_s_>_ <_e_x_p_r_>_)_
<value> the new value
returns the new value
XLISP 2.0 SYMBOL FUNCTIONS Page 24
(_p_u_s_h_ <_e_x_p_r_>_ <_p_l_a_c_e_>_)_ C_O_N_S_ T_O_ S_Y_M_B_O_L_ V_A_L_U_E_
<_p_l_a_c_e_>_ f_i_e_l_d_ s_p_e_c_i_f_i_e_r_ b_e_i_n_g_ m_o_d_i_f_i_e_d_ (_s_e_e_ s_e_t_f_)_
<_e_x_p_r_>_ v_a_l_u_e_ t_o_ c_o_n_s_ t_o_ c_u_r_r_e_n_t_ s_y_m_b_o_l_ v_a_l_u_e_
r_e_t_u_r_n_s_ t_h_e_ n_e_w_ v_a_l_u_e_ w_h_i_c_h_ i_s_ (_C_O_N_S_ <_e_x_p_r_>_ <_p_l_a_c_e_>_)_
N_o_t_e_:_ d_e_f_i_n_e_d_ a_s_ m_a_c_r_o_ i_n_ c_o_m_m_o_n_._l_s_p_
(_p_o_p_ <_p_l_a_c_e_>_)_ R_E_M_O_V_E_ F_I_R_S_T_ E_L_E_M_E_N_T_ O_F_ S_Y_M_B_O_L_ V_A_L_U_E_
<_p_l_a_c_e_>_ t_h_e_ f_i_e_l_d_ b_e_i_n_g_ m_o_d_i_f_i_e_d_ (_s_e_e_ s_e_t_f_)_
r_e_t_u_r_n_s_ (_C_A_R_ <_p_l_a_c_e_>_)_,_ f_i_e_l_d_ c_h_a_n_g_e_d_ t_o_ (_C_D_R_ <_p_l_a_c_e_>_)_
N_o_t_e_:_ d_e_f_i_n_e_d_ a_s_ m_a_c_r_o_ i_n_ c_o_m_m_o_n_._l_s_p_
(defun <sym> <fargs> <expr>...) DEFINE A FUNCTION
(defmacro <sym> <fargs> <expr>...) DEFINE A MACRO
f_s_u_b_r_
<sym> symbol being defined (quoted)
<fargs> formal argument list (lambda list) (quoted)
<expr> expressions constituting the body of the function
(quoted)
returns the function symbol
(gensym [<tag>]) GENERATE A SYMBOL
<tag> string or number
returns the new symbol
(intern <pname>) MAKE AN INTERNED SYMBOL
<pname> the symbol's print name string
returns the new symbol
(make-symbol <pname>) MAKE AN UNINTERNED SYMBOL
<pname> the symbol's print name string
returns the new symbol
(symbol-name <sym>) GET THE PRINT NAME OF A SYMBOL
<sym> the symbol
returns the symbol's print name
(symbol-value <sym>) GET THE VALUE OF A SYMBOL
<sym> the symbol
returns the symbol's value
(symbol-function <sym>) GET THE FUNCTIONAL VALUE OF A SYMBOL
<sym> the symbol
returns the symbol's functional value
(symbol-plist <sym>) GET THE PROPERTY LIST OF A SYMBOL
<sym> the symbol
returns the symbol's property list
(hash <sym> <n>) COMPUTE THE HASH INDEX FOR A SYMBOL
<sym> the symbol or string
<n> the table size (integer)
XLISP 2.0 SYMBOL FUNCTIONS Page 25
returns the hash index (integer)
(_m_a_k_u_n_b_o_u_n_d_ <_s_y_m_>_)_ M_A_K_E_ A_ S_Y_M_B_O_L_ V_A_L_U_E_ B_E_ U_N_B_O_U_N_D_
<_s_y_m_>_ t_h_e_ s_y_m_b_o_l_
r_e_t_u_r_n_s_ t_h_e_ s_y_m_b_o_l_
N_o_t_e_:_ d_e_f_i_n_e_d_ i_n_ i_n_i_t_._l_s_p_
(_f_m_a_k_u_n_b_o_u_n_d_ <_s_y_m_>_)_ M_A_K_E_ A_ S_Y_M_B_O_L_ F_U_N_C_T_I_O_N_ B_E_ U_N_B_O_U_N_D_
<_s_y_m_>_ t_h_e_ s_y_m_b_o_l_
r_e_t_u_r_n_s_ t_h_e_ s_y_m_b_o_l_
N_o_t_e_:_ d_e_f_i_n_e_d_ i_n_ i_n_i_t_._l_s_p_
XLISP 2.0 PROPERTY LIST FUNCTIONS Page 26
PROPERTY LIST FUNCTIONS
(get <sym> <prop>) GET THE VALUE OF A PROPERTY
<sym> the symbol
<prop> the property symbol
returns the property value or nil
(putprop <sym> <val> <prop>) PUT A PROPERTY ONTO A PROPERTY LIST
<sym> the symbol
<val> the property value
<prop> the property symbol
returns the property value
(remprop <sym> <prop>) REMOVE A PROPERTY
<sym> the symbol
<prop> the property symbol
returns nil
XLISP 2.0 ARRAY FUNCTIONS Page 27
ARRAY FUNCTIONS
(aref <array> <n>) GET THE NTH ELEMENT OF AN ARRAY
T_h_i_s_ f_u_n_c_t_i_o_n_ n_o_w_ a_l_s_o_ w_o_r_k_s_ o_n_ s_t_r_i_n_g_s_._
<array> the array
<n> the array index (integer)
returns the value of the array element
(make-array <size>) MAKE A NEW ARRAY
<size> the size of the new array (integer)
returns the new array
(vector <expr>...) MAKE AN INITIALIZED VECTOR
<expr> the vector elements
returns the new vector
XLISP 2.0 SEQUENCE FUNCTIONS Page 28
SEQUENCE FUNCTIONS
T_h_e_s_e_ f_u_n_c_t_i_o_n_s_ w_o_r_k_ o_n_ s_e_q_u_e_n_c_e_s_ -_-_ l_i_s_t_s_,_ a_r_r_a_y_s_,_ o_r_ s_t_r_i_n_g_s_,_ a_n_d_
f_o_r_ t_h_e_ m_o_s_t_ p_a_r_t_ r_e_p_r_e_s_e_n_t_ a_n_ e_x_t_e_n_s_i_o_n_ o_f_ t_h_e_ d_i_s_t_r_i_b_u_t_i_o_n_ X_L_I_S_P_
2_._0_._
(concatenate <type> <expr> ...) CONCATENATE SEQUENCES
<type> result type, one of cons, array, or string
<expr> zero or more sequences to concatenate
returns a sequence which is the concatenation of the arguement
sequences
NOTE: if result type is string, sequences must contain only
characters.
(elt <expr> <n>) GET THE NTH ELEMENT OF A SEQUENCE
<expr> the sequence
<n> the index of element to return
returns the element if the index is in bounds, otherwise error
(map <type> <fcn> <expr> ...) APPLY FUNCTION TO SUCCESSIVE ELEMENTS
<type> result type, one of cons, array, string, or nil
<fcn> the function or function name
<expr> a sequence for each argument of the function
returns a new sequence of type <type>.
(every <fcn> <expr> ...) APPLY FUNCTION TO ELEMENTS UNTIL FALSE
(notevery <fcn> <expr> ...)
<fcn> the function or function name
<expr> a sequence for each argument of the function
returns every returns last evaluated function result, or T
notevery returns T if there is a nil function result,
else NIL
(some <fcn> <expr> ...) APPLY FUNCTION TO ELEMENTS UNTIL TRUE
(notany <fcn> <expr> ...)
<fcn> the function or function name
<expr> a sequence for each argument of the function
returns some returns first non-nil function result, or NIL
notany returns NIL if there is a non-nil function
result, else T
(length <expr>) FIND THE LENGTH OF A SEQUENCE
U_n_c_h_a_n_g_e_d_ f_r_o_m_ t_h_e_ d_i_s_t_r_i_b_u_t_i_o_n_
<expr> the list, vector or string
returns the length of the list, vector or string
XLISP 2.0 SEQUENCE FUNCTIONS Page 29
(reverse <expr>) REVERSE A SEQUENCE
(_n_r_e_v_e_r_s_e_ <_e_x_p_r_>_)_ D_E_S_T_R_U_C_T_I_V_E_L_Y_ R_E_V_E_R_S_E_ A_ S_E_Q_U_E_N_C_E_
D_i_s_t_r_i_b_u_t_i_o_n_ o_n_l_y_ w_o_r_k_e_d_ o_n_ l_i_s_t_s_._
<expr> the sequence to reverse
returns a new sequence in the reverse order
(subseq <seq> <start> [<end>]) EXTRACT A SUBSEQUENCE
D_i_s_t_r_i_b_u_t_i_o_n_ o_n_l_y_ w_o_r_k_e_d_ o_n_ s_t_r_i_n_g_s_._
<seq> the sequence
<start> the starting position (zero origin)
<end> the ending position + 1 (defaults to end) o_r_ N_I_L_ f_o_r_
e_n_d_ o_f_ s_e_q_u_e_n_c_e_
returns the sequence between <start> and <end>
(search <seq1> <seq2> &key :test :test-not :start1 :end1 :start2
:end2)
SEARCH FOR SEQUENCE
Note: added function
<seq1> the sequence to search for
<seq2> the sequence to search in
:test the test function (defaults to eql)
:test-not the test function (sense inverted)
:start1 starting index in <seq1>
:end1 index of end+1 in <seq1> or NIL for end of sequence
:start2 starting index in <seq2>
:end2 index of end+1 in <seq2> or NIL for end of sequence
returns position of first match
(remove <expr> <seq> &key :test :test-not :start :end)
REMOVE ELEMENTS FROM A SEQUENCE
D_i_s_t_r_i_b_u_t_i_o_n_ o_n_l_y_ w_o_r_k_e_d_ o_n_ l_i_s_t_s_._
<expr> the element to remove
<seq> the sequence
:test the test function (defaults to eql)
:test-not the test function (sense inverted)
:_s_t_a_r_t_ s_t_a_r_t_i_n_g_ i_n_d_e_x_
:_e_n_d_ i_n_d_e_x_ o_f_ e_n_d_+_1_,_ o_r_ N_I_L_ f_o_r_ (_l_e_n_g_t_h_ <_s_e_q_>_)_
returns copy of sequence with matching expressions removed
(remove-if <test> <seq> &key :start :end)
REMOVE ELEMENTS THAT PASS TEST
D_i_s_t_r_i_b_u_t_i_o_n_ o_n_l_y_ w_o_r_k_e_d_ o_n_ l_i_s_t_s_._
<test> the test predicate
<seq> the sequence
:_s_t_a_r_t_ s_t_a_r_t_i_n_g_ i_n_d_e_x_
:_e_n_d_ i_n_d_e_x_ o_f_ e_n_d_+_1_,_ o_r_ N_I_L_ f_o_r_ (_l_e_n_g_t_h_ <_s_e_q_>_)_
returns copy of sequence with matching elements removed
XLISP 2.0 SEQUENCE FUNCTIONS Page 30
(remove-if-not <test> <seq> &key :start :end)
REMOVE ELEMENTS THAT FAIL TEST
D_i_s_t_r_i_b_u_t_i_o_n_ o_n_l_y_ w_o_r_k_e_d_ o_n_ l_i_s_t_s_._
<test> the test predicate
<seq> the sequence
:_s_t_a_r_t_ s_t_a_r_t_i_n_g_ i_n_d_e_x_
:_e_n_d_ i_n_d_e_x_ o_f_ e_n_d_+_1_,_ o_r_ N_I_L_ f_o_r_ (_l_e_n_g_t_h_ <_s_e_q_>_)_
returns copy of sequence with non-matching elements removed
(count-if <test> <seq> &key :start :end) COUNT ELEMENTS THAT PASS TEST
Note: added function
<test> the test predicate
<seq> the sequence
:start starting index
:end index of end+1, or NIL for (length <seq>)
returns count of matching elements
(find-if <test> <seq> &key :start :end)
FIND FIRST ELEMENT THAT PASSES TEST
Note: added function
<test> the test predicate
<seq> the list
:start starting index
:end index of end+1, or NIL for (length <seq>)
returns first element of sequence that passes test
(position-if <test> <seq> &key :start :end)
FIND POSITION OF FIRST ELEMENT THAT PASSES TEST
Note: added function
<test> the test predicate
<seq> the list
:start starting index
:end index of end+1, or NIL for (length <seq>)
returns position of first element of sequence that passes test,
or NIL.
(delete <expr> <seq> &key :test :test-not :start :end)
DELETE ELEMENTS FROM A SEQUENCE
D_i_s_t_r_i_b_u_t_i_o_n_ o_n_l_y_ w_o_r_k_e_d_ o_n_ l_i_s_t_s_._
<expr> the element to delete
<seq> the sequence
:test the test function (defaults to eql)
:test-not the test function (sense inverted)
:_s_t_a_r_t_ s_t_a_r_t_i_n_g_ i_n_d_e_x_
:_e_n_d_ i_n_d_e_x_ o_f_ e_n_d_+_1_,_ o_r_ N_I_L_ f_o_r_ (_l_e_n_g_t_h_ <_e_x_p_r_>_)_
returns the sequence with the matching expressions deleted
XLISP 2.0 SEQUENCE FUNCTIONS Page 31
(delete-if <test> <seq> &key :start :end)
DELETE ELEMENTS THAT PASS TEST
D_i_s_t_r_i_b_u_t_i_o_n_ o_n_l_y_ w_o_r_k_e_d_ o_n_ l_i_s_t_s_._
<test> the test predicate
<seq> the sequence
:_s_t_a_r_t_ s_t_a_r_t_i_n_g_ i_n_d_e_x_
:_e_n_d_ i_n_d_e_x_ o_f_ e_n_d_+_1_,_ o_r_ N_I_L_ f_o_r_ (_l_e_n_g_t_h_ <_e_x_p_r_>_)_
returns the sequence with matching elements deleted
(delete-if-not <test> <seq> &key :start :end)
DELETE ELEMENTS THAT FAIL TEST
D_i_s_t_r_i_b_u_t_i_o_n_ o_n_l_y_ w_o_r_k_e_d_ o_n_ l_i_s_t_s_._
<test> the test predicate
<seq> the sequence
:_s_t_a_r_t_ s_t_a_r_t_i_n_g_ i_n_d_e_x_
:_e_n_d_ i_n_d_e_x_ o_f_ e_n_d_+_1_,_ o_r_ N_I_L_ f_o_r_ (_l_e_n_g_t_h_ <_e_x_p_r_>_)_
returns the sequence with non-matching elements deleted
XLISP 2.0 LIST FUNCTIONS Page 32
LIST FUNCTIONS
(car <expr>) RETURN THE CAR OF A LIST NODE
<expr> the list node
returns the car of the list node
(cdr <expr>) RETURN THE CDR OF A LIST NODE
<expr> the list node
returns the cdr of the list node
(cxxr <expr>) ALL CxxR COMBINATIONS
(cxxxr <expr>) ALL CxxxR COMBINATIONS
(cxxxxr <expr>) ALL CxxxxR COMBINATIONS
(first <expr>) A SYNONYM FOR CAR
(second <expr>) A SYNONYM FOR CADR
(third <expr>) A SYNONYM FOR CADDR
(fourth <expr>) A SYNONYM FOR CADDDR
(rest <expr>) A SYNONYM FOR CDR
(cons <expr1> <expr2>) CONSTRUCT A NEW LIST NODE
<expr1> the car of the new list node
<expr2> the cdr of the new list node
returns the new list node
(list <expr>...) CREATE A LIST OF VALUES
(_l_i_s_t_*_ <_e_x_p_r_>_ ._._._ <_l_i_s_t_>_)_
l_i_s_t_*_ i_s_ d_e_f_i_n_e_d_ i_n_ c_o_m_m_o_n_._l_s_p_
<expr> expressions to be combined into a list
returns the new list
(append <expr>...) APPEND LISTS
<expr> lists whose elements are to be appended
returns the new list
(last <list>) RETURN THE LAST LIST NODE OF A LIST
<list> the list
returns the last list node in the list
(member <expr> <list> &key :test :test-not)
FIND AN EXPRESSION IN A LIST
<expr> the expression to find
<list> 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
XLISP 2.0 LIST FUNCTIONS Page 33
(assoc <expr> <alist> &key :test :test-not)
FIND AN EXPRESSION IN AN A-LIST
<expr> the expression to find
<alist> the association list
:test the test function (defaults to eql)
:test-not the test function (sense inverted)
returns the alist entry or nil
(nth <n> <list>) RETURN THE NTH ELEMENT OF A LIST
<n> the number of the element to return (zero origin)
<list> the list
returns the nth element or nil if the list isn't that long
(nthcdr <n> <list>) RETURN THE NTH CDR OF A LIST
<n> the number of the element to return (zero origin)
<list> the list
returns the nth cdr or nil if the list isn't that long
(mapc <fcn> <list1> <list>...) APPLY FUNCTION TO SUCCESSIVE CARS
<fcn> the function or function name
<listn> a list for each argument of the function
returns the first list of arguments
(mapcar <fcn> <list1> <list>...) APPLY FUNCTION TO SUCCESSIVE CARS
<fcn> the function or function name
<listn> a list for each argument of the function
returns a list of the values returned
(mapl <fcn> <list1> <list>...) APPLY FUNCTION TO SUCCESSIVE CDRS
<fcn> the function or function name
<listn> a list for each argument of the function
returns the first list of arguments
(maplist <fcn> <list1> <list>...) APPLY FUNCTION TO SUCCESSIVE CDRS
<fcn> the function or function name
<listn> a list for each argument of the function
returns a list of the values returned
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expression
<expr> 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 <alist> <expr> &key :test :test-not) SUBSTITUTE WITH AN A-LIST
M_o_d_i_f_i_e_d_ t_o_ d_o_ m_i_n_i_m_u_m_ c_o_p_y_i_n_g_ a_s_ i_n_ C_o_m_m_o_n_ L_i_s_p_
<alist> the association list
<expr> 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
(_p_a_i_r_l_i_s_ <_k_e_y_s_>_ <_v_a_l_u_e_s_>_ <_a_l_i_s_t_>_)_ B_U_I_L_D_ A_N_ A_-_L_I_S_T_ F_R_O_M_ T_W_O_ L_I_S_T_S_
I_n_ f_i_l_e_ c_o_m_m_o_n_._l_s_p_
<_k_e_y_s_>_ l_i_s_t_ o_f_ a_s_s_o_c_i_a_t_i_o_n_ k_e_y_s_
<_v_a_l_u_e_s_>_ l_i_s_t_ o_f_ a_s_s_o_c_i_a_t_i_o_n_ v_a_l_u_e_s_,_ s_a_m_e_ l_e_n_g_t_h_ a_s_ k_e_y_s_
<_a_l_i_s_t_>_ e_x_i_s_t_i_n_g_ a_s_s_o_c_i_a_t_i_o_n_ l_i_s_t_
r_e_t_u_r_n_s_ n_e_w_ a_s_s_o_c_i_a_t_i_o_n_ l_i_s_t_
(_c_o_p_y_-_l_i_s_t_ <_l_i_s_t_>_)_ C_O_P_Y_ T_H_E_ T_O_P_ L_E_V_E_L_ O_F_ A_ L_I_S_T_
I_n_ f_i_l_e_ c_o_m_m_o_n_._l_s_p_
<_l_i_s_t_>_ t_h_e_ l_i_s_t_
r_e_t_u_r_n_s_ a_ c_o_p_y_ o_f_ t_h_e_ l_i_s_t_ (_n_e_w_ c_o_n_s_ c_e_l_l_s_ i_n_ t_o_p_ l_e_v_e_l_)_
(_c_o_p_y_-_a_l_i_s_t_ <_a_l_i_s_t_>_)_ C_O_P_Y_ A_N_ A_S_S_O_C_I_A_T_I_O_N_ L_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_F_ T_C_O_N_C_ S_T_R_U_C_T_U_R_E_
(_l_c_o_n_c_ <_t_c_o_n_c_>_ <_l_i_s_t_>_)_
I_n_ f_i_l_e_ c_o_m_m_o_n_._l_s_p_
<_t_c_o_n_c_>_ a_ t_c_o_n_c_ s_t_r_u_c_t_u_r_e_
<_e_x_p_r_>_ e_l_e_m_e_n_t_ t_o_ a_d_d_ t_o_ t_a_i_l_
<_l_i_s_t_>_ l_i_s_t_ o_f_ e_l_e_m_e_n_t_s_ t_o_ a_d_d_ t_o_ t_a_i_l_
r_e_t_u_r_n_s_ m_o_d_i_f_i_e_d_ t_c_o_n_c_
(_r_e_m_o_v_e_-_h_e_a_d_ <_t_c_o_n_c_>_)_ R_E_M_O_V_E_ F_R_O_M_ H_E_A_D_ O_F_ T_C_O_N_C_ S_T_R_U_C_T_U_R_E_
I_n_ f_i_l_e_ c_o_m_m_o_n_._l_s_p_
<_t_c_o_n_c_>_ a_ t_c_o_n_c_ s_t_r_u_c_t_u_r_e_
r_e_t_u_r_n_s_ h_e_a_d_ o_f_ t_c_o_n_c_ (_t_c_o_n_c_ i_s_ m_o_d_i_f_i_e_d_)_
XLISP 2.0 DESTRUCTIVE LIST FUNCTIONS Page 36
DESTRUCTIVE LIST FUNCTIONS
S_e_e_ a_l_s_o_ n_r_e_v_e_r_s_e_,_ d_e_l_e_t_e_,_ d_e_l_e_t_e_-_i_f_,_ a_n_d_ d_e_l_e_t_e_-_i_f_-_n_o_t_,_ u_n_d_e_r_
S_E_Q_U_E_N_C_E_ F_U_N_C_T_I_O_N_S_._
(rplaca <list> <expr>) REPLACE THE CAR OF A LIST NODE
<list> the list node
<expr> the new value for the car of the list node
returns the list node after updating the car
(rplacd <list> <expr>) REPLACE THE CDR OF A LIST NODE
<list> the list node
<expr> the new value for the cdr of the list node
returns the list node after updating the cdr
(nconc <list>...) DESTRUCTIVELY CONCATENATE LISTS
<list> lists to concatenate
returns the result of concatenating the lists
(sort <list> <test>) SORT A LIST
<list> the list to sort
<test> the comparison function
returns the sorted list
XLISP 2.0 ARITHMETIC FUNCTIONS Page 37
ARITHMETIC FUNCTIONS
W_a_r_n_i_n_g_:_ i_n_t_e_g_e_r_ c_a_l_c_u_l_a_t_i_o_n_s_ t_h_a_t_ o_v_e_r_f_l_o_w_ g_i_v_e_ e_r_r_o_n_e_o_u_s_ r_e_s_u_l_t_s_._
A_S_I_N_,_ A_C_O_S_,_ a_n_d_ A_T_A_N_ a_r_e_ r_e_t_r_o_f_i_t_t_e_d_ f_r_o_m_ X_L_I_S_P_ 2_._1_._
(truncate <expr>) TRUNCATES A FLOATING POINT NUMBER TO AN INTEGER
<expr> the number
returns the result of truncating the number
(float <expr>) CONVERTS AN INTEGER TO A FLOATING POINT NUMBER
<expr> the number
returns the result of floating the integer
(+ <expr>...) ADD A LIST OF NUMBERS
<expr> the numbers
returns the result of the addition
(- <expr>...) SUBTRACT A LIST OF NUMBERS OR NEGATE A SINGLE NUMBER
<expr> the numbers
returns the result of the subtraction
(* <expr>...) MULTIPLY A LIST OF NUMBERS
<expr> the numbers
returns the result of the multiplication
(/ <expr>...) DIVIDE A LIST OF NUMBERS OR INVERT A SINGLE NUMBER
<expr> the numbers
returns the result of the division
(1+ <expr>) ADD ONE TO A NUMBER
<expr> the number
returns the number plus one
(1- <expr>) SUBTRACT ONE FROM A NUMBER
<expr> the number
returns the number minus one
(rem <expr>...) REMAINDER OF A LIST OF NUMBERS
<expr> the numbers
returns the result of the remainder operation
(min <expr>...) THE SMALLEST OF A LIST OF NUMBERS
<expr> the expressions to be checked
returns the smallest number in the list
(max <expr>...) THE LARGEST OF A LIST OF NUMBERS
<expr> the expressions to be checked
returns the largest number in the list
XLISP 2.0 ARITHMETIC FUNCTIONS Page 38
(abs <expr>) THE ABSOLUTE VALUE OF A NUMBER
<expr> the number
returns the absolute value of the number
(gcd <n1> <n2>...) COMPUTE THE GREATEST COMMON DIVISOR
<n1> the first number (integer)
<n2> the second number(s) (integer)
returns the greatest common divisor
(random <n>) COMPUTE A RANDOM NUMBER BETWEEN 1 and N-1
<n> the upper bound (integer)
returns a random number
(sin <expr>) COMPUTE THE SINE OF A NUMBER
<expr> the floating point number
returns the sine of the number
(cos <expr>) COMPUTE THE COSINE OF A NUMBER
<expr> the floating point number
returns the cosine of the number
(tan <expr>) COMPUTE THE TANGENT OF A NUMBER
<expr> the floating point number
returns the tangent of the number
(asin <expr>) COMPUTE THE ARC SINE OF A NUMBER
<expr> the floating point number
returns the arc sine of the number
(acos <expr>) COMPUTE THE ARC COSINE OF A NUMBER
<expr> the floating point number
returns the arc cosine of the number
(atan <expr>) COMPUTE THE ARC TANGENT OF A NUMBER
<expr> the floating point number
returns the arc tangent of the number
(expt <x-expr> <y-expr>) COMPUTE X TO THE Y POWER
<x-expr> the floating point number
<y-expr> the floating point exponent
returns x to the y power
(exp <x-expr>) COMPUTE E TO THE X POWER
<x-expr> the floating point number
returns e to the x power
(sqrt <expr>) COMPUTE THE SQUARE ROOT OF A NUMBER
<expr> the floating point number
returns the square root of the number
XLISP 2.0 ARITHMETIC FUNCTIONS Page 39
(< <n1> <n2>...) TEST FOR LESS THAN
(<= <n1> <n2>...) TEST FOR LESS THAN OR EQUAL TO
(= <n1> <n2>...) TEST FOR EQUAL TO
(/= <n1> <n2>...) TEST FOR NOT EQUAL TO
(>= <n1> <n2>...) TEST FOR GREATER THAN OR EQUAL TO
(> <n1> <n2>...) TEST FOR GREATER THAN
<n1> the first number to compare
<n2> the second number to compare
returns the result of comparing <n1> with <n2>...
XLISP 2.0 BITWISE LOGICAL FUNCTIONS Page 40
BITWISE LOGICAL FUNCTIONS
(logand <expr>...) THE BITWISE AND OF A LIST OF NUMBERS
<expr> the numbers
returns the result of the and operation
(logior <expr>...) THE BITWISE INCLUSIVE OR OF A LIST OF NUMBERS
<expr> the numbers
returns the result of the inclusive or operation
(logxor <expr>...) THE BITWISE EXCLUSIVE OR OF A LIST OF NUMBERS
<expr> the numbers
returns the result of the exclusive or operation
(lognot <expr>) THE BITWISE NOT OF A NUMBER
<expr> the number
returns the bitwise inversion of number
XLISP 2.0 STRING FUNCTIONS Page 41
STRING FUNCTIONS
E_x_t_e_n_s_i_o_n_ b_e_y_o_n_d_ d_i_s_t_r_i_b_u_t_i_o_n_:_ f_u_n_c_t_i_o_n_s_ w_i_t_h_ n_a_m_e_s_ s_t_a_r_t_i_n_g_ "_s_t_r_i_n_g_"_
w_i_l_l_ a_l_s_o_ a_c_c_e_p_t_ a_ s_y_m_b_o_l_,_ i_n_ w_h_i_c_h_ c_a_s_e_ t_h_e_ s_y_m_b_o_l_'_s_ p_r_i_n_t_ n_a_m_e_ i_s_
u_s_e_d_._
(string <expr>) MAKE A STRING FROM AN INTEGER ASCII VALUE
<expr> a_n_ i_n_t_e_g_e_r_ (_w_h_i_c_h_ i_s_ f_i_r_s_t_ c_o_n_v_e_r_t_e_d_ i_n_t_o_ i_t_s_ A_S_C_I_I_
c_h_a_r_a_c_t_e_r_ v_a_l_u_e_)_,_ s_t_r_i_n_g_,_ c_h_a_r_a_c_t_e_r_,_ o_r_ s_y_m_b_o_l_
returns t_h_e_ s_t_r_i_n_g_ r_e_p_r_e_s_e_n_t_a_t_i_o_n_ o_f_ t_h_e_ a_r_g_u_m_e_n_t_
(string-trim <bag> <str>) TRIM BOTH ENDS OF A STRING
<bag> a string containing characters to trim
<str> the string to trim
returns a trimed copy of the string
(string-left-trim <bag> <str>) TRIM THE LEFT END OF A STRING
<bag> a string containing characters to trim
<str> the string to trim
returns a trimed copy of the string
(string-right-trim <bag> <str>) TRIM THE RIGHT END OF A STRING
<bag> a string containing characters to trim
<str> the string to trim
returns a trimed copy of the string
(string-upcase <str> &key :start :end) CONVERT TO UPPERCASE
<str> the string
:start the starting offset
:end the ending offset + 1 o_r_ N_I_L_ f_o_r_ e_n_d_ o_f_ s_t_r_i_n_g_
returns a converted copy of the string
(string-downcase <str> &key :start :end) CONVERT TO LOWERCASE
<str> the string
:start the starting offset
:end the ending offset + 1 o_r_ N_I_L_ f_o_r_ e_n_d_ o_f_ s_t_r_i_n_g_
returns a converted copy of the string
(nstring-upcase <str> &key :start :end) CONVERT TO UPPERCASE
<str> the string
:start the starting offset
:end the ending offset + 1 o_r_ N_I_L_ f_o_r_ e_n_d_ o_f_ s_t_r_i_n_g_
returns the converted string (not a copy)
(nstring-downcase <str> &key :start :end) CONVERT TO LOWERCASE
<str> the string
:start the starting offset
:end the ending offset + 1 o_r_ N_I_L_ f_o_r_ e_n_d_ o_f_ s_t_r_i_n_g_
returns the converted string (not a copy)
XLISP 2.0 STRING FUNCTIONS Page 42
(strcat <expr>...) CONCATENATE STRINGS
M_a_c_r_o_ i_n_ i_n_i_t_._l_s_p_,_ t_o_ m_a_i_n_t_a_i_n_ c_o_m_p_a_t_i_b_i_l_i_t_y_ w_i_t_h_ d_i_s_t_r_i_b_u_t_i_o_n_._
S_e_e_ "_c_o_n_c_a_t_e_n_a_t_e_"_._
<expr> the strings to concatenate
returns the result of concatenating the strings
(string< <str1> <str2> &key :start1 :end1 :start2 :end2)
(string<= <str1> <str2> &key :start1 :end1 :start2 :end2)
(string= <str1> <str2> &key :start1 :end1 :start2 :end2)
(string/= <str1> <str2> &key :start1 :end1 :start2 :end2)
(string>= <str1> <str2> &key :start1 :end1 :start2 :end2)
(string> <str1> <str2> &key :start1 :end1 :start2 :end2)
<str1> the first string to compare
<str2> the second string to compare
:start1 first substring starting offset
:end1 first substring ending offset + 1 o_r_ N_I_L_ f_o_r_ e_n_d_ o_f_
s_t_r_i_n_g_
:start2 second substring starting offset
:end2 second substring ending offset + 1 o_r_ N_I_L_ f_o_r_ e_n_d_ o_f_
s_t_r_i_n_g_
returns t if predicate is true, nil otherwise
Note: case is significant with these comparison functions.
(string-lessp <str1> <str2> &key :start1 :end1 :start2 :end2)
(string-not-greaterp <str1> <str2> &key :start1 :end1 :start2 :end2)
(string-equalp <str1> <str2> &key :start1 :end1 :start2 :end2)
(string-not-equalp <str1> <str2> &key :start1 :end1 :start2 :end2)
(string-not-lessp <str1> <str2> &key :start1 :end1 :start2 :end2)
(string-greaterp <str1> <str2> &key :start1 :end1 :start2 :end2)
<str1> the first string to compare
<str2> the second string to compare
:start1 first substring starting offset
:end1 first substring ending offset + 1 o_r_ N_I_L_ f_o_r_ e_n_d_ o_f_
s_t_r_i_n_g_
:start2 second substring starting offset
:end2 second substring ending offset + 1 o_r_ N_I_L_ f_o_r_ e_n_d_ o_f_
s_t_r_i_n_g_
returns t if predicate is true, nil otherwise
Note: case is not significant with these comparison functions.
XLISP 2.0 CHARACTER FUNCTIONS Page 43
CHARACTER FUNCTIONS
(char <string> <index>) EXTRACT A CHARACTER FROM A STRING
<string> the string
<index> the string index (zero relative)
returns the ascii code of the character
(upper-case-p <chr>) IS THIS AN UPPER CASE CHARACTER?
<chr> the character
returns true if the character is upper case, nil otherwise
(lower-case-p <chr>) IS THIS A LOWER CASE CHARACTER?
<chr> the character
returns true if the character is lower case, nil otherwise
(both-case-p <chr>) IS THIS AN ALPHABETIC (EITHER CASE) CHARACTER?
<chr> the character
returns true if the character is alphabetic, nil otherwise
(digit-char-p <chr>) IS THIS A DIGIT CHARACTER?
<chr> the character
returns the digit weight if character is a digit, nil otherwise
(char-code <chr>) GET THE ASCII CODE OF A CHARACTER
<chr> the character
returns the ASCII character code (integer,_ p_a_r_i_t_y_ b_i_t_ s_t_r_i_p_p_e_d_)
(code-char <code>) GET THE CHARACTER WITH A SPECFIED ASCII CODE
<code> the ASCII code (integer,_ r_a_n_g_e_ 0_-_1_2_7_)
returns the character with that code or nil
(char-upcase <chr>) CONVERT A CHARACTER TO UPPER CASE
<chr> the character
returns the upper case character
(char-downcase <chr>) CONVERT A CHARACTER TO LOWER CASE
<chr> the character
returns the lower case character
(digit-char <n>) CONVERT A DIGIT WEIGHT TO A DIGIT
<n> the digit weight (integer)
returns the digit character or nil
(char-int <chr>) CONVERT A CHARACTER TO AN INTEGER
<chr> the character
returns the ASCII character code (_r_a_n_g_e_ 0_-_2_5_5_)_
(int-char <int>) CONVERT AN INTEGER TO A CHARACTER
<int> the ASCII character code (_t_r_e_a_t_e_d_ m_o_d_u_l_o_ 2_5_6_)_
returns the character with that code
XLISP 2.0 CHARACTER FUNCTIONS Page 44
(char< <chr1> <chr2>...)
(char<= <chr1> <chr2>...)
(char= <chr1> <chr2>...)
(char/= <chr1> <chr2>...)
(char>= <chr1> <chr2>...)
(char> <chr1> <chr2>...)
<chr1> the first character to compare
<chr2> the second character(s) to compare
returns t if predicate is true, nil otherwise
Note: case is significant with these comparison functions.
(char-lessp <chr1> <chr2>...)
(char-not-greaterp <chr1> <chr2>...)
(char-equalp <chr1> <chr2>...)
(char-not-equalp <chr1> <chr2>...)
(char-not-lessp <chr1> <chr2>...)
(char-greaterp <chr1> <chr2>...)
<chr1> the first string to compare
<chr2> the second string(s) to compare
returns t if predicate is true, nil otherwise
Note: case is not significant with these comparison functions.
XLISP 2.0 STRUCTURE FUNCTIONS Page 45
STRUCTURE FUNCTIONS
(_A_d_d_e_d_ f_e_a_t_u_r_e_ f_r_o_m_ X_L_I_S_P_ 2_._1_)_
XLISP provides a subset of the Common Lisp structure definition
facility. No slot options are allowed, but slots can have default
initialization expressions.
(defstruct name <slot-desc>...)
or
(defstruct (name <option>...) <slot-desc>...)
fsubr
<name> the structure name symbol (quoted)
<option> option description (quoted)
<slot-desc> slot descriptions (quoted)
returns the structure name
The recognized options are:
(:conc-name name)
(:include name [<slot-desc>...])
Note that if :CONC-NAME appears, it should be before :INCLUDE.
Each slot description takes the form:
<name>
or
(<name> <defexpr>)
If the default initialization expression is not specified, the slot
will be initialized to NIL if no keyword argument is passed to the
creation function.
DEFSTRUCT causes access functions to be created for each of the slots
and also arranges that SETF will work with those access functions. The
access function names are constructed by taking the structure name,
appending a '-' and then appending the slot name. This can be
overridden by using the :CONC-NAME option.
DEFSTRUCT also makes a creation function called MAKE-<structname>, a
copy function called COPY-<structname> and a predicate function called
<structname>-P. The creation function takes keyword arguments for each
of the slots. Structures can be created using the #S( read macro, as
well.
The property *struct-slots* is added to the symbol that names the
structure. This property consists of an association list of slot names
and closures that evaluate to the initial values (NIL if no initial
value expression).
XLISP 2.0 STRUCTURE FUNCTIONS Page 46
For instance:
(defstruct foo bar (gag 2))
creates the following functions:
(foo-bar <expr>)
(setf (foo-bar <expr>) <value>)
(foo-gag <expr>)
(setf (foo-gag <expr>) <value>)
(make-foo &key :bar :gag)
(copy-foo <expr>)
(foo-p <expr>)
XLISP 2.0 OBJECT FUNCTIONS Page 47
OBJECT FUNCTIONS
T_h_i_s_ s_e_c_t_i_o_n_ i_s_ c_o_m_p_l_e_t_e_l_y_ n_e_w_._ N_o_t_e_ t_h_a_t_ t_h_e_ f_u_n_c_t_i_o_n_s_ p_r_o_v_i_d_e_d_ i_n_
c_l_a_s_s_e_s_._l_s_p_ a_r_e_ u_s_e_f_u_l_ b_u_t_ n_o_t_ n_e_c_e_s_s_a_r_y_._
Messages defined for Object and Class are listed starting on page 17.
(send <object> <message> [<args>...]) SEND A MESSAGE
<object> the object to receive the message
<message> message sent to object
<args> arguments to method (if any)
returns the result of the method
(send-super <message> [<args>]) SEND A MESSAGE TO SUPERCLASS
valid only in method context
<message> message sent to objects superclass
<args> arguments to method (if any)
returns the result of the method
(defclass <sym> <ivars> [<cvars> [<super>]]) DEFINE A NEW CLASS
defined in class.lsp as a macro
<sym> symbol whose value is to be bound to the class object
(quoted)
<ivars> list of instance variables (quoted). Instance variables
specified either as <ivar> or (<ivar> <init>) to
specify non-nil default initial value.
<cvars> list of class variables (quoted)
<super> superclass, or Object if absent.
This function sends :SET-PNAME (defined in classes.lsp) to the
new class to set the class' print name instance variable.
Methods defined for classes defined with defclass:
(send <object> :<ivar>)
Returns the specified instance variable
(send <object> :SET-IVAR <ivar> <value>)
Used to set an instance variable, typically with setf.
(send <sym> :NEW {:<ivar> <init>})
Actually definition for :ISNEW. Creates new object
initializing instance variables as specified in keyword
arguments, or to their default if keyword argument is
missing. Returns the object.
(defmethod <class> <sym> <fargs> <expr> ...) DEFINE A NEW METHOD
defined in class.lsp as a macro
<class> Class which will respond to message
<sym> Message name (quoted)
<fargs> Formal argument list. Leading "self" is implied
(quoted)
<expr> Expressions constituting body of method (quoted)
returns the class object.
XLISP 2.0 OBJECT FUNCTIONS Page 48
(definst <class> <sym> [<args>...]) DEFINE A NEW GLOBAL INSTANCE
defined in class.lsp as a macro
<class> Class of new object
<sym> Symbol whose value will be set to new object
<args> Arguments passed to :NEW (typically initial values for
instance variables)
XLISP 2.0 PREDICATE FUNCTIONS Page 49
PREDICATE FUNCTIONS
(atom <expr>) IS THIS AN ATOM?
<expr> the expression to check
returns t if the value is an atom, nil otherwise
(symbolp <expr>) IS THIS A SYMBOL?
<expr> the expression to check
returns t if the expression is a symbol, nil otherwise
(numberp <expr>) IS THIS A NUMBER?
<expr> the expression to check
returns t if the expression is a number, nil otherwise
(null <expr>) IS THIS AN EMPTY LIST?
<expr> the list to check
returns t if the list is empty, nil otherwise
(not <expr>) IS THIS FALSE?
<expr> the expression to check
return t if the value is nil, nil otherwise
(listp <expr>) IS THIS A LIST?
<expr> the expression to check
returns t if the value is a cons or nil, nil otherwise
(endp <list>) IS THIS THE END OF A LIST?
<list> the list
returns t if the value is nil, nil otherwise
(consp <expr>) IS THIS A NON-EMPTY LIST?
<expr> the expression to check
returns t if the value is a cons, nil otherwise
(integerp <expr>) IS THIS AN INTEGER?
<expr> the expression to check
returns t if the value is an integer, nil otherwise
(floatp <expr>) IS THIS A FLOAT?
<expr> the expression to check
returns t if the value is a float, nil otherwise
(stringp <expr>) IS THIS A STRING?
<expr> the expression to check
returns t if the value is a string, nil otherwise
(characterp <expr>) IS THIS A CHARACTER?
<expr> the expression to check
returns t if the value is a character, nil otherwise
XLISP 2.0 PREDICATE FUNCTIONS Page 50
(arrayp <expr>) IS THIS AN ARRAY?
<expr> the expression to check
returns t if the value is an array, nil otherwise
(streamp <expr>) IS THIS A STREAM?
<expr> the expression to check
returns t if the value is a stream, nil otherwise
(objectp <expr>) IS THIS AN OBJECT?
<expr> the expression to check
returns t if the value is an object, nil otherwise
(classp <expr>) IS THIS A CLASS OBJECT?
<expr> the expression to check
returns t if the value is a class object, nil otherwise
(boundp <sym>) IS A VALUE BOUND TO THIS SYMBOL?
<sym> the symbol
returns t if a value is bound to the symbol, nil otherwise
(fboundp <sym>) IS A FUNCTIONAL VALUE BOUND TO THIS SYMBOL?
<sym> the symbol
returns t if a functional value is bound to the symbol, nil
otherwise
(minusp <expr>) IS THIS NUMBER NEGATIVE?
<expr> the number to test
returns t if the number is negative, nil otherwise
(zerop <expr>) IS THIS NUMBER ZERO?
<expr> the number to test
returns t if the number is zero, nil otherwise
(plusp <expr>) IS THIS NUMBER POSITIVE?
<expr> the number to test
returns t if the number is positive, nil otherwise
(evenp <expr>) IS THIS INTEGER EVEN?
<expr> the integer to test
returns t if the integer is even, nil otherwise
(oddp <expr>) IS THIS INTEGER ODD?
<expr> the integer to test
returns t if the integer is odd, nil otherwise
(eq <expr1> <expr2>) ARE THE EXPRESSIONS IDENTICAL?
<expr1> the first expression
<expr2> the second expression
returns t if they are equal, nil otherwise
XLISP 2.0 PREDICATE FUNCTIONS Page 51
(eql <expr1> <expr2>) ARE THE EXPRESSIONS IDENTICAL?
Note: works with all numbers
<expr1> the first expression
<expr2> the second expression
returns t if they are equal, nil otherwise
(equal <expr1> <expr2>) ARE THE EXPRESSIONS EQUAL?
<expr1> the first expression
<expr2> the second expression
returns t if they are equal, nil otherwise
XLISP 2.0 CONTROL CONSTRUCTS Page 52
CONTROL CONSTRUCTS
(cond <pair>...) EVALUATE CONDITIONALLY
f_s_u_b_r_
<pair> pair consisting of:
(<pred> <expr>...)
where
<pred> is a predicate expression
<expr> evaluated if the predicate is not nil
returns the value of the first expression whose predicate is
not nil
(and <expr>...) THE LOGICAL AND OF A LIST OF EXPRESSIONS
f_s_u_b_r_
<expr> 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 <expr>...) THE LOGICAL OR OF A LIST OF EXPRESSIONS
f_s_u_b_r_
<expr> 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 <texpr> <expr1> [<expr2>]) EVALUATE EXPRESSIONS CONDITIONALLY
f_s_u_b_r_
<texpr> the test expression
<expr1> the expression to be evaluated if texpr is non-nil
<expr2> the expression to be evaluated if texpr is nil
returns the value of the selected expression
(when <texpr> <expr>...) EVALUATE ONLY WHEN A CONDITION IS TRUE
f_s_u_b_r_
<texpr> the test expression
<expr> the expression(s) to be evaluted if texpr is non-nil
returns the value of the last expression or nil
(unless <texpr> <expr>...) EVALUATE ONLY WHEN A CONDITION IS FALSE
f_s_u_b_r_
<texpr> the test expression
<expr> the expression(s) to be evaluated if texpr is nil
returns the value of the last expression or nil
XLISP 2.0 CONTROL CONSTRUCTS Page 53
(case <expr> <case>...[(t <expr>)]) SELECT BY CASE
f_s_u_b_r_
<expr> the selection expression
<case> pair consisting of:
(<value> <expr>...)
where:
<value> is a single expression or a list of
expressions (unevaluated)
<expr> are expressions to execute if the case
matches
(t <expr>) default case (no previous matching)
returns the value of the last expression of the matching case
(let (<binding>...) <expr>...) CREATE LOCAL BINDINGS
(let* (<binding>...) <expr>...) LET WITH SEQUENTIAL BINDING
f_s_u_b_r_
<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
<expr> the expressions to be evaluated
returns the value of the last expression
(flet (<binding>...) <expr>...) CREATE LOCAL FUNCTIONS
(labels (<binding>...) <expr>...) FLET WITH RECURSIVE FUNCTIONS
(macrolet (<binding>...) <expr>...) CREATE LOCAL MACROS
f_s_u_b_r_
<binding> the function bindings each of which is:
(<sym> <fargs> <expr>...)
where:
<sym> the function/macro name
<fargs> formal argument list (lambda list)
<expr> expressions constituting the body of the
function/macro
<expr> the expressions to be evaluated
returns the value of the last expression
(catch <sym> <expr>...) EVALUATE EXPRESSIONS AND CATCH THROWS
f_s_u_b_r_
<sym> the catch tag
<expr> expressions to evaluate
returns the value of the last expression the throw expression
(throw <sym> [<expr>]) THROW TO A CATCH
f_s_u_b_r_
<sym> the catch tag
<expr> the value for the catch to return (defaults to nil)
returns never returns
XLISP 2.0 CONTROL CONSTRUCTS Page 54
(unwind-protect <expr> <cexpr>...) PROTECT EVALUATION OF AN EXPRESSION
f_s_u_b_r_
<expr> the expression to protect
<cexpr> 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 2.0 LOOPING CONSTRUCTS Page 55
LOOPING CONSTRUCTS
(loop <expr>...) BASIC LOOPING FORM
f_s_u_b_r_
<expr> the body of the loop
returns never returns (must use non-local exit)
(do (<binding>...) (<texpr> <rexpr>...) <expr>...)GENERAL LOOPING FORM
(do* (<binding>...) (<texpr> <rexpr>...) <expr>...)
f_s_u_b_r_._ d_o_ b_i_n_d_s_ s_i_m_u_l_t_a_n_e_o_u_s_l_y_,_ d_o_*_ b_i_n_d_s_ s_e_q_u_e_n_t_i_a_l_l_y_
<binding> the variable bindings each of which is either:
1) a symbol (which is initialized to nil)
2) a list of the form: (<sym> <init> [<step>])
where:
<sym> is the symbol to bind
<init> the initial value of the symbol
<step> a step expression
<texpr> the termination test expression
<rexpr> result expressions (the default is nil)
<expr> the body of the loop (treated like an implicit prog)
returns the value of the last result expression
(dolist (<sym> <expr> [<rexpr>]) <expr>...) LOOP THROUGH A LIST
f_s_u_b_r_
<sym> the symbol to bind to each list element
<expr> the list expression
<rexpr> the result expression (the default is nil)
<expr> the body of the loop (treated like an implicit prog)
(dotimes (<sym> <expr> [<rexpr>]) <expr>...) LOOP FROM ZERO TO N-1
f_s_u_b_r_
<sym> the symbol to bind to each value from 0 to n-1
<expr> the number of times to loop
<rexpr> the result expression (the default is nil)
<expr> the body of the loop (treated like an implicit prog)
XLISP 2.0 THE PROGRAM FEATURE Page 56
THE PROGRAM FEATURE
(prog (<binding>...) <expr>...) THE PROGRAM FEATURE
(prog* (<binding>...) <expr>...) PROG WITH SEQUENTIAL BINDING
f_s_u_b_r_
<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
<expr> expressions to evaluate or tags (symbols)
returns nil or the argument passed to the return function
(block <name> <expr>...) NAMED BLOCK
f_s_u_b_r_
<name> the block name (quoted symbol)
<expr> the block body
returns the value of the last expression
(return [<expr>]) CAUSE A PROG CONSTRUCT TO RETURN A VALUE
f_s_u_b_r_
<expr> the value (defaults to nil)
returns never returns
(return-from <name> [<value>]) RETURN FROM A NAMED BLOCK O_R_ F_U_N_C_T_I_O_N_
f_s_u_b_r_
<name> the block o_r_ f_u_n_c_t_i_o_n_ name (quoted symbol)
<value> the value to return (defaults to nil)
returns never returns
(tagbody <expr>...) BLOCK WITH LABELS
f_s_u_b_r_
<expr> expression(s) to evaluate or tags (symbols)
returns nil
(go <sym>) GO TO A TAG WITHIN A TAGBODY OR PROG
f_s_u_b_r_
<sym> the tag (quoted)
returns never returns
(progv <slist> <vlist> <expr>...) DYNAMICALLY BIND SYMBOLS
f_s_u_b_r_
<slist> list of symbols (evaluated)
<vlist> list of values to bind to the symbols (evaluated)
<expr> expression(s) to evaluate
returns the value of the last expression
XLISP 2.0 THE PROGRAM FEATURE Page 57
(prog1 <expr1> <expr>...) EXECUTE EXPRESSIONS SEQUENTIALLY
f_s_u_b_r_
<expr1> the first expression to evaluate
<expr> the remaining expressions to evaluate
returns the value of the first expression
(prog2 <expr1> <expr2> <expr>...) EXECUTE EXPRESSIONS SEQUENTIALLY
f_s_u_b_r_
<expr1> the first expression to evaluate
<expr2> the second expression to evaluate
<expr> the remaining expressions to evaluate
returns the value of the second expression
(progn <expr>...) EXECUTE EXPRESSIONS SEQUENTIALLY
f_s_u_b_r_
<expr> the expressions to evaluate
returns the value of the last expression (or nil)
XLISP 2.0 INPUT/OUTPUT FUNCTIONS Page 58
INPUT/OUTPUT FUNCTIONS
N_o_t_e_ t_h_a_t_ w_h_e_n_ p_r_i_n_t_i_n_g_ o_b_j_e_c_t_s_,_ p_r_i_n_t_i_n_g_ i_s_ a_c_c_o_m_p_l_i_s_h_e_d_ b_y_ s_e_n_d_i_n_g_
t_h_e_ m_e_s_s_a_g_e_ :_p_r_i_n_1_ t_o_ t_h_e_ o_b_j_e_c_t_ (_t_h_i_s_ i_s_ a_ m_o_d_i_f_i_c_a_t_i_o_n_ o_f_ t_h_e_
d_i_s_t_r_i_b_u_t_i_o_n_)_._
(read [<stream> [<eof> [<rflag>]]]) READ AN EXPRESSION
<stream> the input stream (default is *standard-input*)
<eof> the value to return on end of file (default is nil)
<rflag> recursive read flag (default is nil, u_n_u_s_e_d_ i_n_ t_h_i_s_
i_m_p_l_e_m_e_n_t_a_t_i_o_n_)
returns the expression read
(_s_e_t_-_m_a_c_r_o_-_c_h_a_r_a_c_t_e_r_ <_c_h_>_ <_f_c_n_>_ [_ T_ ]_)_ M_O_D_I_F_Y_ R_E_A_D_ T_A_B_L_E_
d_e_f_i_n_e_d_ i_n_ i_n_i_t_._l_s_p_
<_c_h_>_ c_h_a_r_a_c_t_e_r_ t_o_ d_e_f_i_n_e_
<_f_c_n_>_ f_u_n_c_t_i_o_n_ t_o_ b_i_n_d_ t_o_ c_h_a_r_a_c_t_e_r_ (_s_e_e_ p_a_g_e_ 1_2_)_
T_ i_f_ T_M_A_C_R_O_ r_a_t_h_e_r_ t_h_a_n_ N_M_A_C_R_O_
(_g_e_t_-_m_a_c_r_o_-_c_h_a_r_a_c_t_e_r_ <_c_h_>_)_ E_X_A_M_I_N_E_ R_E_A_D_ T_A_B_L_E_
d_e_f_i_n_e_d_ i_n_ i_n_i_t_._l_s_p_
<_c_h_>_ c_h_a_r_a_c_t_e_r_
r_e_t_u_r_n_s_ f_u_n_c_t_i_o_n_ b_o_u_n_d_ t_o_ c_h_a_r_a_c_t_e_r_
(print <expr> [<stream>]) PRINT AN EXPRESSION ON A NEW LINE
<expr> the expression to be printed
<stream> the output stream (default is *standard-output*)
returns the expression
(prin1 <expr> [<stream>]) PRINT AN EXPRESSION
s_y_m_b_o_l_s_,_ c_o_n_s_ c_e_l_l_s_ (_w_i_t_h_o_u_t_ c_i_r_c_u_l_a_r_i_t_i_e_s_)_,_ a_r_r_a_y_s_,_ s_t_r_i_n_g_s_,_ a_n_d_
c_h_a_r_a_c_t_e_r_s_ a_r_e_ p_r_i_n_t_e_d_ i_n_ a_ f_o_r_m_a_t_ a_c_c_e_p_t_a_b_l_e_ t_o_ t_h_e_ r_e_a_d_
f_u_n_c_t_i_o_n_._
<expr> the expression to be printed
<stream> the output stream (default is *standard-output*)
returns the expression
(princ <expr> [<stream>]) PRINT AN EXPRESSION WITHOUT QUOTING
<expr> the expressions to be printed
<stream> the output stream (default is *standard-output*)
returns the expression
(pprint <expr> [<stream>]) PRETTY PRINT AN EXPRESSION
<expr> the expressions to be printed
<stream> the output stream (default is *standard-output*)
returns the expression
(terpri [<stream>]) TERMINATE THE CURRENT PRINT LINE
<stream> the output stream (default is *standard-output*)
returns nil
XLISP 2.0 INPUT/OUTPUT FUNCTIONS Page 59
(flatsize <expr>) LENGTH OF PRINTED REPRESENTATION USING PRIN1
<expr> the expression
returns the length
(flatc <expr>) LENGTH OF PRINTED REPRESENTATION USING PRINC
<expr> the expression
returns the length
XLISP 2.0 THE FORMAT FUNCTION Page 60
THE FORMAT FUNCTION
(format <stream> <fmt> <arg>...) DO FORMATTED OUTPUT
<stream> the output stream
<fmt> the format string
<arg> the format arguments
returns output string if <stream> is nil, nil otherwise
I_f_ <_s_t_r_e_a_m_>_ i_s_ T_,_ t_h_e_n_ *_S_T_A_N_D_A_R_D_-_O_U_T_P_U_T_*_ i_s_ a_s_s_u_m_e_d_._
The format string can contain characters that should be copied
directly to the output and formatting directives. The formatting
directives are:
~A o_r_ ~_a_ print next argument using princ
~S o_r_ ~_s_ print next argument using prin1
~% start a new line
~~ print a tilde character
~_\_n_ i_g_n_o_r_e_ r_e_t_u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_ i_/_o_ t_h_r_o_u_g_h_ s_t_a_n_d_a_r_d_ i_n_p_u_t_/_o_u_t_p_u_t_/_e_r_r_o_r_._
(open <fname> &key :direction :_e_l_e_m_e_n_t_-_t_y_p_e_) OPEN A FILE STREAM
<fname> the file name string or symbol
:direction :input, :output, or :_i_o_ (default is :input).
A file opened for input must already exist. A
file opened for output will delete any
existing file by the same name. A file opened
for input or io is positioned at its start.
:_e_l_e_m_e_n_t_-_t_y_p_e_ F_I_X_N_U_M_ o_r_ C_H_A_R_A_C_T_E_R_ (_d_e_f_a_u_l_t_ i_s_ C_H_A_R_A_C_T_E_R_)_,_
a_s_ r_e_t_u_r_n_e_d_ b_y_ t_y_p_e_-_o_f_ f_u_n_c_t_i_o_n_._ F_i_l_e_s_ o_p_e_n_e_d_
w_i_t_h_ t_y_p_e_ F_I_X_N_U_M_ a_r_e_ b_i_n_a_r_y_ f_i_l_e_s_ i_n_s_t_e_a_d_ o_f_
a_s_c_i_i_,_ w_h_i_c_h_ m_e_a_n_s_ n_o_ c_r_l_f_ t_o_/_f_r_o_m_ l_f_
c_o_n_v_e_r_s_i_o_n_ t_a_k_e_s_ p_l_a_c_e_,_ a_n_d_ c_o_n_t_r_o_l_-_Z_ w_i_l_l_
n_o_t_ t_e_r_m_i_n_a_t_e_ a_n_ i_n_p_u_t_ f_i_l_e_._ I_t_ i_s_ t_h_e_ i_n_t_e_n_t_
o_f_ C_o_m_m_o_n_ L_i_s_p_ t_h_a_t_ b_i_n_a_r_y_ f_i_l_e_s_ o_n_l_y_ b_e_
a_c_c_e_s_s_e_d_ w_i_t_h_ r_e_a_d_-_b_y_t_e_ a_n_d_ w_r_i_t_e_-_b_y_t_e_ w_h_i_l_e_
a_s_c_i_i_ f_i_l_e_s_ b_e_ a_c_c_e_s_s_e_d_ w_i_t_h_ a_n_y_ f_u_n_c_t_i_o_n_ b_u_t_
r_e_a_d_-_b_y_t_e_ a_n_d_ w_r_i_t_e_-_b_y_t_e_._ X_L_I_S_P_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_n_g_ f_i_l_e_-_p_o_s_i_t_i_o_n_ t_o_ p_o_s_i_t_i_o_n_ a_ f_i_l_e_
a_t_ a_ l_o_c_a_t_i_o_n_ e_a_r_l_i_e_r_ r_e_p_o_r_t_e_d_ b_y_ f_i_l_e_-_p_o_s_i_t_i_o_n_._
<_s_t_r_e_a_m_>_ t_h_e_ f_i_l_e_ s_t_r_e_a_m_ (_s_h_o_u_l_d_ b_e_ a_ d_i_s_k_ f_i_l_e_)_
<_e_x_p_r_>_ d_e_s_i_r_e_d_ f_i_l_e_ p_o_s_i_t_i_o_n_,_ i_f_ s_e_t_t_i_n_g_ p_o_s_i_t_i_o_n_
r_e_t_u_r_n_s_ i_f_ s_e_t_t_i_n_g_ p_o_s_i_t_i_o_n_,_ a_n_d_ s_u_c_c_e_s_s_f_u_l_,_ t_h_e_n_ T_;_ i_f_ g_e_t_t_i_n_g_
p_o_s_i_t_i_o_n_ a_n_d_ s_u_c_c_e_s_s_f_u_l_ t_h_e_n_ t_h_e_ p_o_s_i_t_i_o_n_;_ o_t_h_e_r_w_i_s_e_
N_I_L_
(read-char [<stream>]) READ A CHARACTER FROM A STREAM
<stream> the input stream (default is *standard-input*)
returns the character
(peek-char [<flag> [<stream>]]) PEEK AT THE NEXT CHARACTER
<flag> flag for skipping white space (default is nil)
<stream> the input stream (default is *standard-input*)
returns the character (integer)
(write-char <ch> [<stream>]) WRITE A CHARACTER TO A STREAM
<ch> the character to write
<stream> the output stream (default is *standard-output*)
returns the character
(read-line [<stream>]) READ A LINE FROM A STREAM
<stream> the input stream (default is *standard-input*)
returns the string
(read-byte [<stream>]) READ A BYTE FROM A STREAM
<stream> the input stream (default is *standard-input*)
returns the byte (integer)
(write-byte <byte> [<stream>]) WRITE A BYTE TO A STREAM
<byte> the byte to write (integer)
<stream> the output stream (default is *standard-output*)
returns the byte (integer)
XLISP 2.0 STRING STREAM FUNCTIONS Page 63
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 list
return a sting or list of the 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.
N_o_t_e_ t_h_a_t_ t_h_e_r_e_ i_s_ n_o_ d_i_f_f_e_r_e_n_c_e_ b_e_t_w_e_e_n_ u_n_n_a_m_e_d_ i_n_p_u_t_ a_n_d_ o_u_t_p_u_t_
s_t_r_e_a_m_s_._ U_n_n_a_m_e_d_ i_n_p_u_t_ s_t_r_e_a_m_s_ m_a_y_ b_e_ w_r_i_t_t_e_n_ t_o_ b_y_ o_u_t_p_u_t_ f_u_n_c_t_i_o_n_s_,_
i_n_ w_h_i_c_h_ c_a_s_e_ t_h_e_ c_h_a_r_a_c_t_e_r_s_ a_r_e_ a_p_p_e_n_d_e_d_ t_o_ t_h_e_ t_a_i_l_ e_n_d_ o_f_ t_h_e_
s_t_r_e_a_m_._ U_n_n_a_m_e_d_ o_u_t_p_u_t_ s_t_r_e_a_m_s_ m_a_y_ a_l_s_o_ b_e_ (_d_e_s_t_r_u_c_t_i_v_e_l_y_)_ r_e_a_d_ b_y_ a_n_y_
i_n_p_u_t_ f_u_n_c_t_i_o_n_ a_s_ w_e_l_l_ a_s_ t_h_e_ g_e_t_-_o_u_t_p_u_t_-_s_t_r_e_a_m_ f_u_n_c_t_i_o_n_s_._
(make-string-input-stream <str> [<start> [<end>]])
<str> the string
<start> the starting offset
<end> the ending offset + 1 o_r_ N_I_L_ f_o_r_ e_n_d_ o_f_ s_t_r_i_n_g_
returns an unnamed stream that reads from the string
(make-string-output-stream)
returns an unnamed output stream
(get-output-stream-string <stream>)
<stream> the output stream
returns the output so far as a string
Note: the output stream is emptied by this function
(get-output-stream-list <stream>)
<stream> the output stream
returns the output so far as a list
Note: the output stream is emptied by this function
XLISP 2.0 DEBUGGING AND ERROR HANDLING Page 64
DEBUGGING AND ERROR HANDLING FUNCTIONS
(trace [<sym>...]) ADD A FUNCTION TO THE TRACE LIST
f_s_u_b_r_
<sym> the function(s) to add (quoted)
returns the trace list
(untrace [<sym>...]) REMOVE A FUNCTION FROM THE TRACE LIST
f_s_u_b_r_._ I_f_ n_o_ f_u_n_c_t_i_o_n_s_ g_i_v_e_n_,_ a_l_l_ f_u_n_c_t_i_o_n_s_ a_r_e_ r_e_m_o_v_e_d_ f_r_o_m_ t_h_e_
t_r_a_c_e_ l_i_s_t_._
<sym> the function(s) to remove (quoted)
returns the trace list
(error <emsg> [<arg>]) SIGNAL A NON-CORRECTABLE ERROR
<emsg> the error message string
<arg> the argument expression (printed after the message)
returns never returns
(cerror <cmsg> <emsg> [<arg>]) SIGNAL A CORRECTABLE ERROR
<cmsg> the continue message string
<emsg> the error message string
<arg> the argument expression (printed after the message)
returns nil when continued from the break loop
(break [<bmsg> [<arg>]]) ENTER A BREAK LOOP
<bmsg> the break message string (defaults to "**BREAK**")
<arg> 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 <expr> [<pflag>]) TRAP ERRORS
f_s_u_b_r_
<expr> the expression to execute
<pflag> flag to control printing of the error message
returns the value of the last expression consed with nil or nil
on error
(baktrace [<n>]) PRINT N LEVELS OF TRACE BACK INFORMATION
<n> the number of levels (defaults to all levels)
returns nil
XLISP 2.0 DEBUGGING AND ERROR HANDLING Page 65
(evalhook <expr> <ehook> <ahook> [<env>]) EVALUATE WITH HOOKS
<expr> the expression to evaluate. <_e_h_o_o_k_>_ i_s_ n_o_t_ u_s_e_d_ a_t_ t_h_e_
t_o_p_ l_e_v_e_l_._
<ehook> the value for *evalhook*
<ahook> the value for *applyhook*
<env> the environment (default is nil). T_h_e_ f_o_r_m_a_t_ i_s_ a_
d_o_t_t_e_d_ p_a_i_r_ o_f_ v_a_l_u_e_ (_c_a_r_)_ a_n_d_ f_u_n_c_t_i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LISP 2.0 SYSTEM FUNCTIONS Page 66
SYSTEM FUNCTIONS
(load <fname> &key :verbose :print) LOAD A SOURCE FILE
<fname> the filename string or symbol
:verbose the verbose flag (default is t)
:print the print flag (default is nil)
returns the filename
(restore <fname>) RESTORE WORKSPACE FROM A FILE
<fname> the filename string or symbol
returns nil on failure, otherwise never returns
(save <fname>) SAVE WORKSPACE TO A FILE
<fname> the filename string or symbol
returns t if workspace was written, nil otherwise
(_s_a_v_e_f_u_n_ <_f_c_n_>_)_ S_A_V_E_ F_U_N_C_T_I_O_N_ T_O_ A_ F_I_L_E_
d_e_f_i_n_e_d_ i_n_ i_n_i_t_._l_s_p_
<_f_c_n_>_ f_u_n_c_t_i_o_n_ n_a_m_e_ (_s_a_v_e_s_ i_t_ t_o_ f_i_l_e_ o_f_ s_a_m_e_ n_a_m_e_,_ w_i_t_h_
e_x_t_e_n_s_i_o_n_ "_._l_s_p_"_)_
r_e_t_u_r_n_s_ t_ i_f_ s_u_c_c_e_s_s_f_u_l_
(dribble [<fname>]) CREATE A FILE WITH A TRANSCRIPT OF A SESSION
<fname> 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 [<num>]) EXPAND MEMORY BY ADDING SEGMENTS
<num> the number of segments to add, default 1
returns the number of segments added
(alloc <num>) CHANGE NUMBER OF NODES TO ALLOCATE IN EACH SEGMENT
<num> the number of nodes to allocate
returns the old number of nodes to allocate
(room) SHOW MEMORY ALLOCATION STATISTICS
returns nil
(_t_i_m_e_ <_e_x_p_r_>_)_ M_E_A_S_U_R_E_ E_X_E_C_U_T_I_O_N_ T_I_M_E_
f_s_u_b_r_._ N_o_t_e_:_ a_d_d_e_d_ f_u_n_c_t_i_o_n_
<_e_x_p_r_>_ t_h_e_ e_x_p_r_e_s_s_i_o_n_ t_o_ e_v_a_l_u_a_t_e_
r_e_t_u_r_n_s_ t_h_e_ e_x_e_c_u_t_i_o_n_ t_i_m_e_,_ i_n_ s_e_c_o_n_d_s_ (_f_l_o_a_t_i_n_g_ p_o_i_n_t_)_
XLISP 2.0 SYSTEM FUNCTIONS Page 67
(_c_o_e_r_c_e_ <_e_x_p_r_>_ <_t_y_p_e_>_)_ F_O_R_C_E_ E_X_P_R_E_S_S_I_O_N_ T_O_ D_E_S_I_G_N_A_T_E_D_ T_Y_P_E_
N_o_t_e_:_ a_d_d_e_d_ f_u_n_c_t_i_o_n_
<_e_x_p_r_>_ t_h_e_ e_x_p_r_e_s_s_i_o_n_ t_o_ c_o_e_r_c_e_
<_t_y_p_e_>_ d_e_s_i_r_e_d_ t_y_p_e_,_ a_s_ r_e_t_u_r_n_e_d_ b_y_ t_y_p_e_-_o_f_
r_e_t_u_r_n_s_ <_e_x_p_r_>_ i_f_ t_y_p_e_ i_s_ c_o_r_r_e_c_t_,_ o_r_ c_o_n_v_e_r_t_e_d_ o_b_j_e_c_t_._
S_e_q_u_e_n_c_e_s_ c_a_n_ b_e_ c_o_e_r_c_e_d_ i_n_t_o_ o_t_h_e_r_ s_e_q_u_e_n_c_e_s_,_ s_i_n_g_l_e_ c_h_a_r_a_c_t_e_r_
s_t_r_i_n_g_s_ o_r_ s_y_m_b_o_l_s_ w_i_t_h_ s_i_n_g_l_e_ c_h_a_r_a_c_t_e_r_ p_r_i_n_t_n_a_m_e_s_ c_a_n_ b_e_
c_o_e_r_c_e_d_ i_n_t_o_ c_h_a_r_a_c_t_e_r_s_,_ i_n_t_e_g_e_r_s_ c_a_n_ b_e_ c_o_e_r_c_e_d_ i_n_t_o_ c_h_a_r_a_c_t_e_r_s_
o_r_ f_l_o_n_u_m_s_._
(type-of <expr>) RETURNS THE TYPE OF THE EXPRESSION
<expr> 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
s_y_m_ f_o_r_ s_t_r_u_c_t_u_r_e_s_ o_f_ t_y_p_e_ "_s_y_m_"_
(_g_e_n_e_r_i_c_ <_e_x_p_r_>_)_ C_R_E_A_T_E_ A_ G_E_N_E_R_I_C_ T_Y_P_E_D_ C_O_P_Y_ O_F_ T_H_E_ E_X_P_R_E_S_S_I_O_N_
N_o_t_e_:_ a_d_d_e_d_ f_u_n_c_t_i_o_n_,_ T_o_m_ A_l_m_y_'_s_ i_n_v_e_n_t_i_o_n_._
<_e_x_p_r_>_ t_h_e_ e_x_p_r_e_s_s_i_o_n_ t_o_ c_o_p_y_
r_e_t_u_r_n_s_ n_i_l_ i_f_ v_a_l_u_e_ i_s_ n_i_l_,_ o_t_h_e_r_w_i_s_e_ i_f_ t_y_p_e_ i_s_:_
S_Y_M_B_O_L_ c_o_p_y_ a_s_ a_n_ A_R_R_A_Y_
O_B_J_E_C_T_ c_o_p_y_ a_s_ a_n_ A_R_R_A_Y_
C_O_N_S_ (_C_O_N_S_ (_C_A_R_ <_e_x_p_r_>_)_(_C_D_R_ <_e_x_p_r_>_)_)_
C_L_O_S_U_R_E_ c_o_p_y_ a_s_ a_n_ A_R_R_A_Y_
S_T_R_I_N_G_ c_o_p_y_ o_f_ t_h_e_ s_t_r_i_n_g_
F_I_X_N_U_M_ v_a_l_u_e_
F_L_O_N_U_M_ v_a_l_u_e_
C_H_A_R_A_C_T_E_R_ v_a_l_u_e_
U_N_N_A_M_E_D_-_S_T_R_E_A_M_ c_o_p_y_ a_s_ a_ C_O_N_S_
A_R_R_A_Y_ c_o_p_y_ o_f_ t_h_e_ a_r_r_a_y_
(peek <addrs>) PEEK AT A LOCATION IN MEMORY
<addrs> the address to peek at (integer)
returns the value at the specified address (integer)
(poke <addrs> <value>) POKE A VALUE INTO MEMORY
<addrs> the address to poke (integer)
<value> the value to poke into the address (integer)
returns the value
XLISP 2.0 SYSTEM FUNCTIONS Page 68
(address-of <expr>) GET THE ADDRESS OF AN XLISP NODE
<expr> the node
returns the address of the node (integer)
(_g_e_t_k_e_y_)_ R_E_A_D_ A_ K_E_Y_S_T_R_O_K_E_ F_R_O_M_ C_O_N_S_O_L_E_
r_e_t_u_r_n_s_ i_n_t_e_g_e_r_ v_a_l_u_e_ o_f_ k_e_y_ (_n_o_ e_c_h_o_)_
(_s_y_s_t_e_m_ <_c_o_m_m_a_n_d_>_)_ E_X_E_C_U_T_E_ A_ S_Y_S_T_E_M_ C_O_M_M_A_N_D_
<_c_o_m_m_a_n_d_>_ C_o_m_m_a_n_d_ s_t_r_i_n_g_,_ i_f_ 0_ l_e_n_g_t_h_ t_h_e_n_ s_p_a_w_n_ O_S_ s_h_e_l_l_
r_e_t_u_r_n_s_ T_ i_f_ s_u_c_c_e_s_s_f_u_l_ (_n_o_t_e_ t_h_a_t_ M_S_/_D_O_S_ c_o_m_m_a_n_d_._c_o_m_ a_l_w_a_y_s_
r_e_t_u_r_n_s_ s_u_c_c_e_s_s_)_
(_e_x_i_t_)_ E_X_I_T_ X_L_I_S_P_
r_e_t_u_r_n_s_ n_e_v_e_r_ r_e_t_u_r_n_s_
The following graphic functions represent an extension by Tom Almy:
(mode <ax> [<bx> <width> <height>) SET DISPLAY MODE
<ax> Graphic mode (value passed in register AX)
<bx> BX value for some extended graphic modes
<width> width for extended graphic modes
<height> height for extended graphic modes
returns T
(color <value>) SET DRAWING COLOR
<value> Drawing color (not checked for validity)
returns <value>
(move <x1> <y1> [<x2> <y2> ...]) ABSOLUTE MOVE
(moverel <x1> <y2> [<x2> <y2> ...]) RELATIVE MOVE
For moverel, all coordinates are relative to the preceeding
point.
<x1> <y1> Moves to point x1,y1 in anticipation of draw.
<x2> <y2> Draws to points specified in additional arguments.
returns T if succeeds, else NIL
(draw [<x1> <y1> ...]) ABSOLUTE DRAW
(drawrel [<x1> <y1> ...]) RELATIVE DRAW
For drawrel, all coordinates are relative to the preceeding
point.
<x1> <y1> Point(s) drawn to, in order.
returns T if succeeds, else NIL
XLISP 2.0 ADDITIONAL FUNCTIONS Page 69
ADDITIONAL FUNCTIONS AND UTILITIES
T_h_i_s_ s_e_c_t_i_o_n_ i_s_ c_o_m_p_l_e_t_e_l_y_ n_e_w_ (_a_d_d_e_d_ b_y_ T_o_m_ A_l_m_y_)_._
STEP.LSP
This file contains a simple Lisp single-step debugger. It started as
an implementation of the "hook" example in chapter 20 of Steele's
"Common Lisp". This version was brought up on Xlisp 1.7 for the Amiga,
and then on VAXLISP.
To invoke: (step (whatever-form with args))
For each list (interpreted function call), the stepper prints the
environment and the list, then enters a read-eval-print loop. At this
point the available commands are:
(a list)<CR> evaluate the list in the current environment, print the
result, and repeat.
<CR> step into the called function
anything_else<CR> step over the called function.
If the stepper comes to a form that is not a list it prints the form
and the value, and continues on without stopping.
Note that stepper commands are executed in the current environment.
Since this is the case, the stepper commands can change the current
environment. For example, a SETF will change an environment variable
and thus can alter the course of execution.
Global variables - newline, *hooklevel*
Functions/macros - while step eval-hool-function step-spaces step-
flush
Note an even more powerful stepper package is in stepper.lsp
(documented in stepper.doc).
XLISP 2.0 ADDITIONAL FUNCTIONS Page 70
PP.LSP
In addition to the pretty-printer itself, this file contains a few
functions that illustrate some simple but useful applications.
(pp <object> [<stream>]) PRETTY PRINT EXPRESSION
(pp-def <funct> [<stream>]) PRETTY PRINT FUNCTION/MACRO
(pp-file <file> [<stream>]) PRETTY PRINT FILE
<object> The expression to print
<funct> Function to print (as DEFUN or DEFMACRO)
<file> File to print (specify either as string or quoted
symbol)
<stream> Output stream (default is *standard-output*)
returns T
Global variables: tabsize maxsize miser-size min-miser-car max-normal-
car
Functions/Macros: sym-function pp-file pp-def make-def pp pp1 moveto
spaces pp-rest-across pp-rest printmacrop pp-binding-form pp-do-form
pp-defining-form pp-pair-form
See the source file for more information.
XLISP 2.0 ADDITIONAL FUNCTIONS Page 71
REPAIR.LSP
This file contains a structure editor.
Execute (repair 'symbol) to edit a symbol.
or (repairf symbol) to edit the function binding of a symbol
(allows changing the argument list or function type,
lambda or macro).
The editor alters the current selection by copying so that aborting
all changes is generally posible; the exception is when editing a
closure, if the closure is BACKed out of, the change is permanent.
For all commands taking a numeric argument, the first element of the
selection is the 0th (as in NTH function).
Any array elements become lists when they are selected, and return to
arrays upon RETURN or BACK commands.
Do not create new closures, because the environment will be incorrect.
Closures become LAMBDA or MACRO expressions as the selection. Only the
closure body may be changed; the argument list cannot be successfully
modified, nor can the environment.
For class objects, only the methods and message names can be modified.
For instance objects, instance variables can be examined (if the
object under-stands the message :<ivar> for the particular ivar), and
changed (if :SET-IVAR is defined for that class, as it is if
CLASSES.LSP is used).
(command list on next page)
XLISP 2.0 ADDITIONAL FUNCTIONS Page 72
COMMANDS (general):
? list available commands for the selection.
RETURN exit, saving all changes.
ABORT exit, without changes.
BACK go back one level (as before CAR CDR or N commands).
B n go back n levels.
L display selection using pprint; if selection is symbol,
give short description.
MAP pprints each element of selection, or if selection is
symbol then gives complete description of properties.
PLEV x set *print-level* to x. (Initial default is *rep-print-
level*)
PLEN x set *print-length to x. (Initial default is *rep-print-
length*)
EVAL x evaluates x and prints result. The symbol @ is bound to
the selection.
REPLACE x replaces the current selection with evaluated x. The
symbol @ is bound to the selection.
COMMANDS (if selection is symbol):
VALUE edit the value binding.
FUNCTION edit the function binding (must be a closure).
PROP x edit property x.
COMMANDS (if selection is list):
CAR select the CAR of the current selection.
CDR select the CDR of the current selection.
n where n is small non-negative integer, changes current
selection to (NTH n list).
SUBST x y all occurances of (quoted) y are replaced with (quoted)
x. EQUAL is used for the comparison.
RAISE n removes parenthesis surrounding nth element of
selection.
LOWER n m inserts parenthesis starting with the nth element, for
m elements.
ARRAY n m as in LOWER, but makes elements into an array.
I n x inserts (quoted) x before nth element in selection.
R n x replaces nth element in selection with (quoted) x.
D n deletes nth element in selection.
All function names and global variables start with the string "rep-"
or "*rep-*".
XLISP 2.0 EXAMPLES Page 73
EXAMPLES: 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 2.0 EXAMPLES Page 74
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.
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))
XLISP 2.0 INDEX Page 75
INDEX
:answer 18
:class 17
:constituent 12
:iskindof 17
:ismemberof 17
:isnew 17, 18
:mescape 12
:messages 18
:new 18
:nmacro 12
:prin1 17
:respondsto 17
:sescape 12
:show 17
:storeon 17, 18
:superclass 17, 18
:tmacro 12
:white-space 12
+ 20, 37
++ 20
+++ 20
- 20, 37
* 20, 37
** 20
*** 20
*applyhook* 9, 20
*breakenable* 5, 20
*debug-io* 20
*dos-input* 3, 20
*error-output* 20
*evalhook* 9, 20
*float-format* 20
*gc-flag* 20
*gc-hook* 20
*integer-format* 20
*obarray* 20
*print-case* 20
*print-length* 20
*print-level* 20
*readtable* 12, 20
*standard-input* 20
*standard-output* 20
*trace-output* 20
*tracelimit* 5, 20
*tracelist* 20
*tracenable* 5, 20
*unbound* 20
/ 37
/= 39 < 39
<= 39
= 39
> 39
>= 39
&aux 14
&key 14
&optional 14
&rest 14
1+ 37
1- 37
abs 38
acos 38
address-of 68
alloc 66
and 52
append 32
apply 21
applyhook 9, 65
aref 23, 27
arrayp 50
asin 38
assoc 33
atan 38
atom 49
backquote 21
baktrace 64
block 56
both-case-p 43
boundp 50
break 64
car 23, 32
case 53
catch 53
cdr 23, 32
cerror 64
char 43
char-code 43
char-downcase 43
char-equalp 44
char-greaterp 44
char-int 43
char-lessp 44
char-not-equalp 44
char-not-greaterp 44
char-not-lessp 44
char-upcase 43
char/= 44
char< 44
XLISP 2.0 INDEX Page 76
char<= 44
char= 44
char> 44
char>= 44
characterp 49
class 20
classp 50
clean-up 4, 64
clean-up, 5
close 61
code-char 43
coerce 67
color 68
comma 21
comma-at 21
concatenate 28
cond 52
cons 32
consp 49
continue 4, 5, 64
copy-alist 34
copy-list 34
copy-tree 34
cos 38
count-if 30
cxxr 32
cxxxr 32
cxxxxr 32
debug 65
defclass 47
definst 48
defmacro 24
defmethod 47
defstruct 45
defun 24
delete 30
delete-if 31
delete-if-not 31
digit-char 43
digit-char-p 43
do 55
do* 55
dolist 55
dotimes 55
draw 68
drawrel 68
dribble 66
elt 23, 28
endp 49
eq 50
eql 51 equal 51
error 64
errset 5, 64
eval 21
evalhook 9, 65
evenp 50
every 28
exit 68
exp 38
expand 66
expt 38
fboundp 50
file-length 61
file-position 62
find-if 30
first 32
flatc 59
flatsize 59
flet 53
float 37
floatp 49
fmakunbound 25
format 60
fourth 32
funcall 21
function 21
gc 66
gcd 38
generic 67
gensym 24
get 23, 26
get-lambda-expression 22
get-macro-character 58
get-output-stream-list 63
get-output-stream-string
63
getkey 68
go 56
hash 24
if 52
int-char 43
integerp 49
intern 24
labels 53
lambda 21
last 32
lconc 35
length 28
let 53
let* 53
list 32
XLISP 2.0 INDEX Page 77
listp 49
load 66
logand 40
logior 40
lognot 40
logxor 40
loop 55
lower-case-p 43
macroexpand 22
macroexpand-1 22
macrolet 53
make-array 27
make-string-input-stream
63
make-string-output-stream
63
make-symbol 24
make_tconc 34
makunbound 25
map 28
mapc 33
mapcan 33
mapcar 33
mapcon 33
mapl 33
maplist 33
max 37
member 32
min 37
minusp 50
mode 68
move 68
moverel 68
nconc 36
nil 20
nodebug 65
not 49
notany 28
notevery 28
nreverse 29
nstring-downcase 41
nstring-upcase 41
nth 23, 33
nthcdr 33
null 49
numberp 49
object 20
objectp 50
oddp 50
open 61
or 52 pairlis 34
peek 67
peek-char 62
plusp 50
poke 67
pop 24
position-if 30
pp 70
pprint 58
prin1 58
princ 58
print 58
prog 56
prog* 56
prog1 57
prog2 57
progn 57
progv 56
psetq 23
push 24
putprop 26
quote 21
random 38
read 58
read-byte 62
read-char 62
read-line 62
rem 37
remove 29
remove-head 35
remove-if 29
remove-if-not 30
remprop 26
repair 71
rest 32
restore 66
return 56
return-from 56
reverse 29
room 66
rplaca 36
rplacd 36
save 66
search 29
second 32
self 16, 20
send 16, 23, 47
send-super 16, 47
set 23
set-macro-character 58
setf 23
XLISP 2.0 INDEX Page 78
setq 23
sin 38
some 28
sort 36
sqrt 38
step 69
strcat 42
streamp 50
string 41
string-downcase 41
string-equalp 42
string-greaterp 42
string-left-trim 41
string-lessp 42
string-not-equalp 42
string-not-greaterp 42
string-not-lessp 42
string-right-trim 41
string-trim 41
string-upcase 41
string/= 42
string< 42
string<= 42
string= 42
string> 42
string>= 42
stringp 49
sublis 34
subseq 29
subst 34
symbol-function 23, 24
symbol-name 24
symbol-plist 23, 24
symbol-value 23, 24
symbolp 49
system 68
t 20
tagbody 56
tan 38
tconc 35
terpri 58
third 32
throw 53
time 66
top-level 4, 64
trace 64
truncate 37
type-of 67
unless 52
untrace 64
unwind-protect 54 upper-case-p 43
vector 27
when 52
write-byte 62
write-char 62
zerop 50