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_l_-_Z_ e_n_d_ o_f_ f_i_l_e_ (_r_e_t_u_r_n_s_ o_n_e_ l_e_v_e_l_ o_r_ e_x_i_t_s_ p_r_o_g_r_a_m_)_ c_t_r_l_-_P_ p_r_o_c_e_e_d_ (_c_o_n_t_i_n_u_e_)_ c_t_r_l_-_T_ p_r_i_n_t_ i_n_f_o_r_m_a_t_i_o_n_ (_a_d_d_e_d_ f_u_n_c_t_i_o_n_ b_y_ T_A_A_)_ 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_ t_y_p_e_d_ w_h_i_l_e_ X_L_I_S_P_ i_s_ e_x_e_c_u_t_i_n_g_:_ c_t_r_l_-_B_ B_R_E_A_K_ -_-_ e_n_t_e_r_ b_r_e_a_k_ l_o_o_p_ c_t_r_l_-_S_ P_a_u_s_e_ u_n_t_i_l_ a_n_o_t_h_e_r_ k_e_y_ i_s_ s_t_r_u_c_k_ c_t_r_l_-_C_ g_o_ t_o_ t_o_p_ l_e_v_e_l_ (_i_f_ l_u_c_k_y_:_ c_t_r_l_-_B_,_c_t_r_l_-_C_ i_s_ s_a_f_e_r_)_ c_t_r_l_-_T_ p_r_i_n_t_ i_n_f_o_r_m_a_t_i_o_n_ I_f_ t_h_e_ g_l_o_b_a_l_ v_a_r_i_a_b_l_e_ *_d_o_s_-_i_n_p_u_t_*_ i_s_ s_e_t_ n_o_n_-_n_i_l_,_ D_O_S_ i_s_ u_s_e_d_ t_o_ r_e_a_d_ e_n_t_i_r_e_ i_n_p_u_t_ l_i_n_e_s_._ O_p_e_r_a_t_i_o_n_ t_h_i_s_ w_a_y_ i_s_ c_o_n_v_e_n_i_e_n_t_ i_f_ c_e_r_t_a_i_n_ D_O_S_ u_t_i_l_i_t_i_e_s_,_ s_u_c_h_ a_s_ C_E_D_,_ a_r_e_ u_s_e_d_,_ o_r_ i_f_ X_L_I_S_P_ i_s_ r_u_n_ u_n_d_e_r_ a_n_ e_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 ( ) triples. 5. &rest argument 6. &key arguments as list of ( ) quadruples. 7. &aux arguments as list of ( ) 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: #\ == the ASCII code of the printing character #\newline == ASCII linefeed character #\space == ASCII space character #\rubout == ASCII rubout (DEL) #\C- == ASCII control character #\M- == ASCII character with msb set (Meta character) #\M-C- == 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: ' == (quote ) ` == (backquote ) , == (comma ) ,@ == (comma-at ) #' == (function ) #(...) == an array of the specified expressions #S( [ ]...) == structure of specified type and initial values #. == result of evaluating #x == a hexadecimal number (0-9,A-F) #o == an octal number (0-7) #b == a binary number (0-1) #| |# == a comment #: == 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: (... [&optional [ | ( [ []])]...] [&rest ] [&key [ | ([ | ( )] [ []])] ... &allow-other-keys] [&aux [ | ( [])]...]) where: is a required argument symbol is an &optional argument symbol is the &rest argument symbol is a &key argument symbol is a keyword symbol is an auxiliary variable symbol is an initialization expression is a supplied-p variable symbol XLISP 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_R_I_N_T_ T_H_E_ O_B_J_E_C_T_ r_e_t_u_r_n_s_ t_h_e_ o_b_j_e_c_t_ :isnew THE DEFAULT OBJECT INITIALIZATION ROUTINE 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_ N_I_L_ (_D_e_f_i_n_e_d_ i_n_ c_l_a_s_s_e_s_._l_s_p_,_ s_e_e_ :_s_u_p_e_r_c_l_a_s_s_ b_e_l_o_w_)_ :_i_s_m_e_m_b_e_r_o_f_ <_c_l_a_s_s_>_ C_L_A_S_S_ M_E_M_B_E_R_S_H_I_P_ <_c_l_a_s_s_>_ c_l_a_s_s_ n_a_m_e_ r_e_t_u_r_n_s_ T_ i_f_ o_b_j_e_c_t_ m_e_m_b_e_r_ o_f_ c_l_a_s_s_,_ e_l_s_e_ N_I_L_ (_d_e_f_i_n_e_d_ i_n_ c_l_a_s_s_e_s_._l_s_p_)_ :_i_s_k_i_n_d_o_f_ <_c_l_a_s_s_>_ C_L_A_S_S_ M_E_M_B_E_R_S_H_I_P_ <_c_l_a_s_s_>_ c_l_a_s_s_ n_a_m_e_ r_e_t_u_r_n_s_ T_ i_f_ o_b_j_e_c_t_ m_e_m_b_e_r_ o_f_ c_l_a_s_s_ o_f_ s_u_b_c_l_a_s_s_ o_f_ c_l_a_s_s_,_ e_l_s_e_ N_I_L_ (_d_e_f_i_n_e_d_ i_n_ c_l_a_s_s_e_s_._l_s_p_)_ :_r_e_s_p_o_n_d_s_t_o_ <_s_e_l_>_ S_E_L_E_C_T_O_R_ K_N_O_W_L_E_D_G_E_ <_s_e_l_>_ m_e_s_s_a_g_e_ s_e_l_e_c_t_o_r_ r_e_t_u_r_n_s_ T_ i_f_ o_b_j_e_c_t_ r_e_s_p_o_n_d_s_ t_o_ m_e_s_s_a_g_e_ s_e_l_e_c_t_o_r_,_ e_l_s_e_ N_I_L_._ (_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_ 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 [ []] INITIALIZE A NEW CLASS the list of instance variable symbol the list of class variable symbols the superclass (default is Object) returns the new class object :answer ADD A MESSAGE TO A CLASS the message symbol the formal argument list (lambda list) a list of executable expressions returns the object :_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_L_A_S_S_'_:_ M_E_S_S_A_G_E_S_ -_ A_n_ a_s_s_o_c_i_a_t_i_o_n_ l_i_s_t_ o_f_ m_e_s_s_a_g_e_ n_a_m_e_s_ a_n_d_ c_l_o_s_u_r_e_s_ i_m_p_l_e_m_e_n_t_i_n_g_ t_h_e_ m_e_s_s_a_g_e_s_._ I_V_A_R_S_ -_ L_i_s_t_ o_f_ n_a_m_e_s_ o_f_ i_n_s_t_a_n_c_e_ v_a_r_i_a_b_l_e_s_._ C_V_A_R_S_ -_ L_i_s_t_ o_f_ n_a_m_e_s_ o_f_ c_l_a_s_s_ v_a_r_i_a_b_l_e_s_._ C_V_A_L_ -_ L_i_s_t_ o_f_ c_l_a_s_s_ v_a_r_i_a_b_l_e_ v_a_l_u_e_s_._ S_U_P_E_R_C_L_A_S_S_ -_ T_h_e_ s_u_p_e_r_c_l_a_s_s_ o_f_ t_h_i_s_ c_l_a_s_s_ o_r_ N_I_L_ i_f_ n_o_ s_u_p_e_r_c_l_a_s_s_ (_o_n_l_y_ f_o_r_ c_l_a_s_s_ O_B_J_E_C_T_)_._ I_V_A_R_C_N_T_ -_ i_n_s_t_a_n_c_e_ v_a_r_i_a_b_l_e_s_ i_n_ t_h_i_s_ c_l_a_s_s_ (_l_e_n_g_t_h_ o_f_ I_V_A_R_S_)_ I_V_A_R_T_O_T_A_L_ -_ t_o_t_a_l_ i_n_s_t_a_n_c_e_ v_a_r_i_a_b_l_e_s_ f_o_r_ t_h_i_s_ c_l_a_s_s_ a_n_d_ a_l_l_ s_u_p_e_r_c_l_a_s_s_e_s_ o_f_ t_h_i_s_ c_l_a_s_s_._ P_N_A_M_E_ -_ p_r_i_n_t_n_a_m_e_ s_t_r_i_n_g_ f_o_r_ t_h_i_s_ c_l_a_s_s_._ XLISP 2.0 SYMBOLS Page 20 SYMBOLS _ n_i_l_ -_ t_h_e_ e_m_p_t_y_ l_i_s_t_ _ t_ -_ t_r_u_t_h_ v_a_l_u_e_ self - the current object (within a method context) _ o_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 ) EVALUATE AN XLISP EXPRESSION the expression to be evaluated returns the result of evaluating the expression (apply ) APPLY A FUNCTION TO A LIST OF ARGUMENTS the function to apply (or function symbol). M_a_y_ n_o_t_ b_e_ m_a_c_r_o_ o_r_ f_s_u_b_r_._ 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 ...) CALL A FUNCTION WITH ARGUMENTS 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_._ arguments to pass to the function returns the result of calling the function with the arguments (quote ) RETURN AN EXPRESSION UNEVALUATED f_s_u_b_r_ the expression to be quoted (quoted) returns unevaluated (function ) GET THE FUNCTIONAL INTERPRETATION f_s_u_b_r_ the symbol or lambda expression (quoted) returns the functional interpretation (backquote ) FILL IN A TEMPLATE f_s_u_b_r_ 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 ...) MAKE A FUNCTION CLOSURE f_s_u_b_r_ formal argument list (lambda list) (quoted) expressions of the function body (quoted) returns the function closure XLISP 2.0 EVALUATION FUNCTIONS Page 22 (get-lambda-expression ) GET THE LAMBDA EXPRESSION the closure returns the original lambda expression (macroexpand
) RECURSIVELY EXPAND MACRO CALLS the form to expand returns the macro expansion (macroexpand-1 ) EXPAND A MACRO CALL the macro call form returns the macro expansion XLISP 2.0 SYMBOL FUNCTIONS Page 23 SYMBOL FUNCTIONS (set ) SET THE G_L_O_B_A_L_ VALUE OF A SYMBOL the symbol being set the new value returns the new value (setq [ ]...) SET THE VALUE OF A SYMBOL f_s_u_b_r_ the symbol being set (quoted) the new value returns the new value (psetq [ ]...) 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_._ the symbol being set (quoted) the new value returns the new value (setf [ ]...) SET THE VALUE OF A FIELD f_s_u_b_r_ the field specifier (quoted): set value of a symbol (car ) set car of a cons node (cdr ) set cdr of a cons node (nth ) set nth car of a list (aref ) set nth element of an array 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 ) set value of a property (symbol-value ) set value of a symbol (symbol-function ) functional value of a symbol (symbol-plist ) 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_>_)_ 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 ...) DEFINE A FUNCTION (defmacro ...) DEFINE A MACRO f_s_u_b_r_ symbol being defined (quoted) formal argument list (lambda list) (quoted) expressions constituting the body of the function (quoted) returns the function symbol (gensym []) GENERATE A SYMBOL string or number returns the new symbol (intern ) MAKE AN INTERNED SYMBOL the symbol's print name string returns the new symbol (make-symbol ) MAKE AN UNINTERNED SYMBOL the symbol's print name string returns the new symbol (symbol-name ) GET THE PRINT NAME OF A SYMBOL the symbol returns the symbol's print name (symbol-value ) GET THE VALUE OF A SYMBOL the symbol returns the symbol's value (symbol-function ) GET THE FUNCTIONAL VALUE OF A SYMBOL the symbol returns the symbol's functional value (symbol-plist ) GET THE PROPERTY LIST OF A SYMBOL the symbol returns the symbol's property list (hash ) COMPUTE THE HASH INDEX FOR A SYMBOL the symbol or string the table size (integer) 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 ) GET THE VALUE OF A PROPERTY the symbol the property symbol returns the property value or nil (putprop ) PUT A PROPERTY ONTO A PROPERTY LIST the symbol the property value the property symbol returns the property value (remprop ) REMOVE A PROPERTY the symbol the property symbol returns nil XLISP 2.0 ARRAY FUNCTIONS Page 27 ARRAY FUNCTIONS (aref ) 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_._ the array the array index (integer) returns the value of the array element (make-array ) MAKE A NEW ARRAY the size of the new array (integer) returns the new array (vector ...) MAKE AN INITIALIZED VECTOR the vector elements returns the new vector XLISP 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 ...) CONCATENATE SEQUENCES result type, one of cons, array, or string 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 ) GET THE NTH ELEMENT OF A SEQUENCE the sequence the index of element to return returns the element if the index is in bounds, otherwise error (map ...) APPLY FUNCTION TO SUCCESSIVE ELEMENTS result type, one of cons, array, string, or nil the function or function name a sequence for each argument of the function returns a new sequence of type . (every ...) APPLY FUNCTION TO ELEMENTS UNTIL FALSE (notevery ...) the function or function name 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 ...) APPLY FUNCTION TO ELEMENTS UNTIL TRUE (notany ...) the function or function name 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 ) 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_ the list, vector or string returns the length of the list, vector or string XLISP 2.0 SEQUENCE FUNCTIONS Page 29 (reverse ) 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_._ the sequence to reverse returns a new sequence in the reverse order (subseq []) 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_._ the sequence the starting position (zero origin) 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 and (search &key :test :test-not :start1 :end1 :start2 :end2) SEARCH FOR SEQUENCE Note: added function the sequence to search for the sequence to search in :test the test function (defaults to eql) :test-not the test function (sense inverted) :start1 starting index in :end1 index of end+1 in or NIL for end of sequence :start2 starting index in :end2 index of end+1 in or NIL for end of sequence returns position of first match (remove &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_._ the element to remove 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 &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_._ the test predicate 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 &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_._ the test predicate 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 &key :start :end) COUNT ELEMENTS THAT PASS TEST Note: added function the test predicate the sequence :start starting index :end index of end+1, or NIL for (length ) returns count of matching elements (find-if &key :start :end) FIND FIRST ELEMENT THAT PASSES TEST Note: added function the test predicate the list :start starting index :end index of end+1, or NIL for (length ) returns first element of sequence that passes test (position-if &key :start :end) FIND POSITION OF FIRST ELEMENT THAT PASSES TEST Note: added function the test predicate the list :start starting index :end index of end+1, or NIL for (length ) returns position of first element of sequence that passes test, or NIL. (delete &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_._ the element to delete 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 &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_._ the test predicate 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 &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_._ the test predicate 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 ) RETURN THE CAR OF A LIST NODE the list node returns the car of the list node (cdr ) RETURN THE CDR OF A LIST NODE the list node returns the cdr of the list node (cxxr ) ALL CxxR COMBINATIONS (cxxxr ) ALL CxxxR COMBINATIONS (cxxxxr ) ALL CxxxxR COMBINATIONS (first ) A SYNONYM FOR CAR (second ) A SYNONYM FOR CADR (third ) A SYNONYM FOR CADDR (fourth ) A SYNONYM FOR CADDDR (rest ) A SYNONYM FOR CDR (cons ) CONSTRUCT A NEW LIST NODE the car of the new list node the cdr of the new list node returns the new list node (list ...) CREATE A LIST OF VALUES (_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_ expressions to be combined into a list returns the new list (append ...) APPEND LISTS lists whose elements are to be appended returns the new list (last ) RETURN THE LAST LIST NODE OF A LIST the list returns the last list node in the list (member &key :test :test-not) FIND AN EXPRESSION IN A LIST the expression to find the list to search :test the test function (defaults to eql) :test-not the test function (sense inverted) returns the remainder of the list starting with the expression XLISP 2.0 LIST FUNCTIONS Page 33 (assoc &key :test :test-not) FIND AN EXPRESSION IN AN A-LIST the expression to find the association list :test the test function (defaults to eql) :test-not the test function (sense inverted) returns the alist entry or nil (nth ) RETURN THE NTH ELEMENT OF A LIST the number of the element to return (zero origin) the list returns the nth element or nil if the list isn't that long (nthcdr ) RETURN THE NTH CDR OF A LIST the number of the element to return (zero origin) the list returns the nth cdr or nil if the list isn't that long (mapc ...) APPLY FUNCTION TO SUCCESSIVE CARS the function or function name a list for each argument of the function returns the first list of arguments (mapcar ...) APPLY FUNCTION TO SUCCESSIVE CARS the function or function name a list for each argument of the function returns a list of the values returned (mapl ...) APPLY FUNCTION TO SUCCESSIVE CDRS the function or function name a list for each argument of the function returns the first list of arguments (maplist ...) APPLY FUNCTION TO SUCCESSIVE CDRS the function or function name a list for each argument of the function returns a list of the values returned (_m_a_p_c_a_n_ <_f_c_n_>_ <_l_i_s_t_1_>_ <_l_i_s_t_>_._._._)_ A_P_P_L_Y_ F_U_N_C_T_I_O_N_ T_O_ S_U_C_C_E_S_S_I_V_E_ C_A_R_S_ <_f_c_n_>_ t_h_e_ f_u_n_c_t_i_o_n_ o_r_ f_u_n_c_t_i_o_n_ n_a_m_e_ <_l_i_s_t_n_>_ a_ l_i_s_t_ f_o_r_ e_a_c_h_ a_r_g_u_m_e_n_t_ o_f_ t_h_e_ f_u_n_c_t_i_o_n_ r_e_t_u_r_n_s_ l_i_s_t_ o_f_ r_e_t_u_r_n_ v_a_l_u_e_s_ n_c_o_n_c_'_d_ t_o_g_e_t_h_e_r_ N_o_t_e_:_ t_h_i_s_ f_u_n_c_t_i_o_n_ i_s_ i_n_ i_n_i_t_._l_s_p_ (_m_a_p_c_o_n_ <_f_c_n_>_ <_l_i_s_t_1_>_ <_l_i_s_t_>_._._._)_ A_P_P_L_Y_ F_U_N_C_T_I_O_N_ T_O_ S_U_C_C_E_S_S_I_V_E_ C_D_R_S_ <_f_c_n_>_ t_h_e_ f_u_n_c_t_i_o_n_ o_r_ f_u_n_c_t_i_o_n_ n_a_m_e_ <_l_i_s_t_n_>_ a_ l_i_s_t_ f_o_r_ e_a_c_h_ a_r_g_u_m_e_n_t_ o_f_ t_h_e_ f_u_n_c_t_i_o_n_ r_e_t_u_r_n_s_ l_i_s_t_ o_f_ r_e_t_u_r_n_ v_a_l_u_e_s_ n_c_o_n_c_'_d_ t_o_g_e_t_h_e_r_ N_o_t_e_:_ t_h_i_s_ f_u_n_c_t_i_o_n_ i_s_ i_n_ i_n_i_t_._l_s_p_ XLISP 2.0 LIST FUNCTIONS Page 34 (subst &key :test :test-not) SUBSTITUTE EXPRESSIONS 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_ the new expression the old expression the expression in which to do the substitutions :test the test function (defaults to eql) :test-not the test function (sense inverted) returns the expression with substitutions (sublis &key :test :test-not) SUBSTITUTE WITH AN A-LIST 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_ the association list the expression in which to do the substitutions :test the test function (defaults to eql) :test-not the test function (sense inverted) returns the expression with substitutions (_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_I_S_T_ I_n_ f_i_l_e_ c_o_m_m_o_n_._l_s_p_ <_a_l_i_s_t_>_ t_h_e_ a_s_s_o_c_i_a_t_i_o_n_ l_i_s_t_ r_e_t_u_r_n_s_ a_ c_o_p_y_ o_f_ t_h_e_ a_s_s_o_c_i_a_t_i_o_n_ l_i_s_t_ (_k_e_y_s_ a_n_d_ v_a_l_u_e_s_ n_o_t_ c_o_p_i_e_s_)_ (_c_o_p_y_-_t_r_e_e_ <_t_r_e_e_>_)_ C_O_P_Y_ A_ T_R_E_E_ I_n_ f_i_l_e_ c_o_m_m_o_n_._l_s_p_ <_t_r_e_e_>_ a_ t_r_e_e_ s_t_r_u_c_t_u_r_e_ o_f_ c_o_n_s_ c_e_l_l_s_ r_e_t_u_r_n_s_ a_ c_o_p_y_ o_f_ t_h_e_ t_r_e_e_ s_t_r_u_c_t_u_r_e_ (_m_a_k_e___t_c_o_n_c_)_ M_A_K_E_ A_ 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_._ (_n_o_t_e_ t_h_a_t_ s_t_r_i_n_g_ s_t_r_e_a_m_s_ a_r_e_ i_n_t_e_r_n_a_l_l_y_ i_m_p_l_e_m_e_n_t_e_d_ a_s_ T_C_O_N_C_s_._ O_l_d_e_r_ v_e_r_s_i_o_n_s_ o_f_ x_l_i_s_p_ a_l_l_o_w_e_d_ a_n_y_ T_C_O_N_C_ t_o_ b_e_ u_s_e_d_ a_s_ a_ s_t_e_a_m_,_ b_u_t_ 2_._0_ i_m_p_l_e_m_e_n_t_s_ a_ s_p_e_c_i_a_l_ s_t_r_i_n_g_ s_t_r_e_a_m_ t_y_p_e_._)_ r_e_t_u_r_n_s_ a_n_ e_m_p_t_y_ t_c_o_n_c_ s_t_r_u_c_t_u_r_e_ XLISP 2.0 LIST FUNCTIONS Page 35 (_t_c_o_n_c_ <_t_c_o_n_c_>_ <_e_x_p_r_>_)_ A_D_D_ T_O_ T_A_I_L_ O_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 ) REPLACE THE CAR OF A LIST NODE the list node the new value for the car of the list node returns the list node after updating the car (rplacd ) REPLACE THE CDR OF A LIST NODE the list node the new value for the cdr of the list node returns the list node after updating the cdr (nconc ...) DESTRUCTIVELY CONCATENATE LISTS lists to concatenate returns the result of concatenating the lists (sort ) SORT A LIST the list to sort 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 ) TRUNCATES A FLOATING POINT NUMBER TO AN INTEGER the number returns the result of truncating the number (float ) CONVERTS AN INTEGER TO A FLOATING POINT NUMBER the number returns the result of floating the integer (+ ...) ADD A LIST OF NUMBERS the numbers returns the result of the addition (- ...) SUBTRACT A LIST OF NUMBERS OR NEGATE A SINGLE NUMBER the numbers returns the result of the subtraction (* ...) MULTIPLY A LIST OF NUMBERS the numbers returns the result of the multiplication (/ ...) DIVIDE A LIST OF NUMBERS OR INVERT A SINGLE NUMBER the numbers returns the result of the division (1+ ) ADD ONE TO A NUMBER the number returns the number plus one (1- ) SUBTRACT ONE FROM A NUMBER the number returns the number minus one (rem ...) REMAINDER OF A LIST OF NUMBERS the numbers returns the result of the remainder operation (min ...) THE SMALLEST OF A LIST OF NUMBERS the expressions to be checked returns the smallest number in the list (max ...) THE LARGEST OF A LIST OF NUMBERS the expressions to be checked returns the largest number in the list XLISP 2.0 ARITHMETIC FUNCTIONS Page 38 (abs ) THE ABSOLUTE VALUE OF A NUMBER the number returns the absolute value of the number (gcd ...) COMPUTE THE GREATEST COMMON DIVISOR the first number (integer) the second number(s) (integer) returns the greatest common divisor (random ) COMPUTE A RANDOM NUMBER BETWEEN 1 and N-1 the upper bound (integer) returns a random number (sin ) COMPUTE THE SINE OF A NUMBER the floating point number returns the sine of the number (cos ) COMPUTE THE COSINE OF A NUMBER the floating point number returns the cosine of the number (tan ) COMPUTE THE TANGENT OF A NUMBER the floating point number returns the tangent of the number (asin ) COMPUTE THE ARC SINE OF A NUMBER the floating point number returns the arc sine of the number (acos ) COMPUTE THE ARC COSINE OF A NUMBER the floating point number returns the arc cosine of the number (atan ) COMPUTE THE ARC TANGENT OF A NUMBER the floating point number returns the arc tangent of the number (expt ) COMPUTE X TO THE Y POWER the floating point number the floating point exponent returns x to the y power (exp ) COMPUTE E TO THE X POWER the floating point number returns e to the x power (sqrt ) COMPUTE THE SQUARE ROOT OF A NUMBER the floating point number returns the square root of the number XLISP 2.0 ARITHMETIC FUNCTIONS Page 39 (< ...) TEST FOR LESS THAN (<= ...) TEST FOR LESS THAN OR EQUAL TO (= ...) TEST FOR EQUAL TO (/= ...) TEST FOR NOT EQUAL TO (>= ...) TEST FOR GREATER THAN OR EQUAL TO (> ...) TEST FOR GREATER THAN the first number to compare the second number to compare returns the result of comparing with ... XLISP 2.0 BITWISE LOGICAL FUNCTIONS Page 40 BITWISE LOGICAL FUNCTIONS (logand ...) THE BITWISE AND OF A LIST OF NUMBERS the numbers returns the result of the and operation (logior ...) THE BITWISE INCLUSIVE OR OF A LIST OF NUMBERS the numbers returns the result of the inclusive or operation (logxor ...) THE BITWISE EXCLUSIVE OR OF A LIST OF NUMBERS the numbers returns the result of the exclusive or operation (lognot ) THE BITWISE NOT OF A NUMBER the number returns the bitwise inversion of number XLISP 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 ) MAKE A STRING FROM AN INTEGER ASCII VALUE 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 ) TRIM BOTH ENDS OF A STRING a string containing characters to trim the string to trim returns a trimed copy of the string (string-left-trim ) TRIM THE LEFT END OF A STRING a string containing characters to trim the string to trim returns a trimed copy of the string (string-right-trim ) TRIM THE RIGHT END OF A STRING a string containing characters to trim the string to trim returns a trimed copy of the string (string-upcase &key :start :end) CONVERT TO UPPERCASE the string :start the starting offset :end the ending offset + 1 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 &key :start :end) CONVERT TO LOWERCASE 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 &key :start :end) CONVERT TO UPPERCASE 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 &key :start :end) CONVERT TO LOWERCASE 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 ...) 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_"_._ the strings to concatenate returns the result of concatenating the strings (string< &key :start1 :end1 :start2 :end2) (string<= &key :start1 :end1 :start2 :end2) (string= &key :start1 :end1 :start2 :end2) (string/= &key :start1 :end1 :start2 :end2) (string>= &key :start1 :end1 :start2 :end2) (string> &key :start1 :end1 :start2 :end2) the first string to compare the second string to compare :start1 first substring starting offset :end1 first substring ending offset + 1 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 &key :start1 :end1 :start2 :end2) (string-not-greaterp &key :start1 :end1 :start2 :end2) (string-equalp &key :start1 :end1 :start2 :end2) (string-not-equalp &key :start1 :end1 :start2 :end2) (string-not-lessp &key :start1 :end1 :start2 :end2) (string-greaterp &key :start1 :end1 :start2 :end2) the first string to compare the second string to compare :start1 first substring starting offset :end1 first substring ending offset + 1 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 ) EXTRACT A CHARACTER FROM A STRING the string the string index (zero relative) returns the ascii code of the character (upper-case-p ) IS THIS AN UPPER CASE CHARACTER? the character returns true if the character is upper case, nil otherwise (lower-case-p ) IS THIS A LOWER CASE CHARACTER? the character returns true if the character is lower case, nil otherwise (both-case-p ) IS THIS AN ALPHABETIC (EITHER CASE) CHARACTER? the character returns true if the character is alphabetic, nil otherwise (digit-char-p ) IS THIS A DIGIT CHARACTER? the character returns the digit weight if character is a digit, nil otherwise (char-code ) GET THE ASCII CODE OF A CHARACTER the character returns the ASCII character code (integer,_ p_a_r_i_t_y_ b_i_t_ s_t_r_i_p_p_e_d_) (code-char ) GET THE CHARACTER WITH A SPECFIED ASCII CODE the ASCII code (integer,_ r_a_n_g_e_ 0_-_1_2_7_) returns the character with that code or nil (char-upcase ) CONVERT A CHARACTER TO UPPER CASE the character returns the upper case character (char-downcase ) CONVERT A CHARACTER TO LOWER CASE the character returns the lower case character (digit-char ) CONVERT A DIGIT WEIGHT TO A DIGIT the digit weight (integer) returns the digit character or nil (char-int ) CONVERT A CHARACTER TO AN INTEGER the character returns the ASCII character code (_r_a_n_g_e_ 0_-_2_5_5_)_ (int-char ) CONVERT AN INTEGER TO A CHARACTER 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< ...) (char<= ...) (char= ...) (char/= ...) (char>= ...) (char> ...) the first character to compare the second character(s) to compare returns t if predicate is true, nil otherwise Note: case is significant with these comparison functions. (char-lessp ...) (char-not-greaterp ...) (char-equalp ...) (char-not-equalp ...) (char-not-lessp ...) (char-greaterp ...) the first string to compare the second string(s) to compare returns t if predicate is true, nil otherwise Note: case is not significant with these comparison functions. XLISP 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 ...) or (defstruct (name