home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / OS2XLSP2.ZIP / XLISP.DOC < prev   
Text File  |  1988-02-10  |  84KB  |  3,235 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.                          XLISP: An Object-oriented Lisp
  8.  
  9.                                   Version 2.0
  10.  
  11.                                 February 6, 1988
  12.  
  13.  
  14.                                        by
  15.                                David Michael Betz
  16.                                 127 Taylor Road
  17.                              Peterborough, NH 03458
  18.  
  19.                              (603) 924-6936 (home)
  20.  
  21.                    Copyright (c) 1988, by David Michael Betz
  22.                               All Rights Reserved
  23.            Permission is granted for unrestricted non-commercial use
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.         XLISP                  TABLE OF CONTENTS                  Page 2
  71.  
  72.  
  73.                                Table of Contents
  74.  
  75.  
  76.                 TABLE OF CONTENTS                        2
  77.  
  78.                 INTRODUCTION                             4
  79.  
  80.                 A NOTE FROM THE AUTHOR                   5
  81.  
  82.                 XLISP COMMAND LOOP                       6
  83.  
  84.                 BREAK COMMAND LOOP                       7
  85.  
  86.                 DATA TYPES                               8
  87.  
  88.                 THE EVALUATOR                            9
  89.  
  90.                 LEXICAL CONVENTIONS                     10
  91.  
  92.                 READTABLES                              11
  93.  
  94.                 LAMBDA LISTS                            12
  95.  
  96.                 OBJECTS                                 14
  97.  
  98.                 SYMBOLS                                 17
  99.  
  100.                 EVALUATION FUNCTIONS                    18
  101.  
  102.                 SYMBOL FUNCTIONS                        19
  103.  
  104.                 PROPERTY LIST FUNCTIONS                 21
  105.  
  106.                 ARRAY FUNCTIONS                         22
  107.  
  108.                 LIST FUNCTIONS                          23
  109.  
  110.                 DESTRUCTIVE LIST FUNCTIONS              26
  111.  
  112.                 PREDICATE FUNCTIONS                     27
  113.  
  114.                 CONTROL CONSTRUCTS                      29
  115.  
  116.                 LOOPING CONSTRUCTS                      31
  117.  
  118.                 THE PROGRAM FEATURE                     32
  119.  
  120.                 DEBUGGING AND ERROR HANDLING            33
  121.  
  122.                 ARITHMETIC FUNCTIONS                    34
  123.  
  124.                 BITWISE LOGICAL FUNCTIONS               36
  125.  
  126.                 STRING FUNCTIONS                        37
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.         XLISP                  TABLE OF CONTENTS                  Page 3
  137.  
  138.  
  139.                 CHARACTER FUNCTIONS                     39
  140.  
  141.                 INPUT/OUTPUT FUNCTIONS                  41
  142.  
  143.                 THE FORMAT FUNCTION                     42
  144.  
  145.                 FILE I/O FUNCTIONS                      43
  146.  
  147.                 STRING STREAM FUNCTIONS                 44
  148.  
  149.                 SYSTEM FUNCTIONS                        45
  150.  
  151.                 EXAMPLES                                47
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.         XLISP                     INTRODUCTION                    Page 4
  203.  
  204.  
  205.         INTRODUCTION
  206.  
  207.         XLISP is an experimental programming language combining some of
  208.         the features of Common Lisp with an object-oriented extension
  209.         capability.  It was implemented to allow experimentation with
  210.         object-oriented programming on small computers.
  211.  
  212.         There are currently implementations of XLISP running on the IBM-
  213.         PC and clones under MS-DOS, on the Macintosh, the Atari-ST and
  214.         the Amiga.  It is completely written in the programming language
  215.         'C' and is easily extended with user written built-in functions
  216.         and classes.  It is available in source form to non-commercial
  217.         users.
  218.  
  219.         Many Common Lisp functions are built into XLISP.  In addition,
  220.         XLISP defines the objects 'Object' and 'Class' as primitives.
  221.         'Object' is the only class that has no superclass and hence is
  222.         the root of the class heirarchy tree.  'Class' is the class of
  223.         which all classes are instances (it is the only object that is
  224.         an instance of itself).
  225.  
  226.         This document is a brief description of XLISP.  It assumes some
  227.         knowledge of LISP and some understanding of the concepts of
  228.         object-oriented programming.
  229.  
  230.         I recommend the book "LISP" by Winston and Horn and published by
  231.         Addison Wesley for learning Lisp.  The first edition of this
  232.         book is based on MacLisp and the second edition is based on
  233.         Common Lisp.  XLISP will continue to migrate towards
  234.         compatibility with Common Lisp.
  235.  
  236.         You will probably also need a copy of "Common Lisp: The
  237.         Language" by Guy L. Steele, Jr., published by Digital Press to
  238.         use as a reference for some of the Common Lisp functions that
  239.         are described only briefly in this document.
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.         XLISP                A NOTE FROM THE AUTHOR               Page 5
  269.  
  270.  
  271.         A NOTE FROM THE AUTHOR
  272.  
  273.         If you have any problems with XLISP, feel free to contact me for
  274.         help or advice.  Please remember that since XLISP is available
  275.         in source form in a high level language, many users have been
  276.         making versions available on a variety of machines.  If you call
  277.         to report a problem with a specific version, I may not be able
  278.         to help you if that version runs on a machine to which I don't
  279.         have access.  Please have the version number of the version that
  280.         you are running readily accessible before calling me.
  281.  
  282.         If you find a bug in XLISP, first try to fix the bug yourself
  283.         using the source code provided.  If you are successful in fixing
  284.         the bug, send the bug report along with the fix to me.  If you
  285.         don't have access to a C compiler or are unable to fix a bug,
  286.         please send the bug report to me and I'll try to fix it.
  287.  
  288.         Any suggestions for improvements will be welcomed.  Feel free to
  289.         extend the language in whatever way suits your needs.  However,
  290.         PLEASE DO NOT RELEASE ENHANCED VERSIONS WITHOUT CHECKING WITH ME
  291.         FIRST!!  I would like to be the clearing house for new features
  292.         added to XLISP.  If you want to add features for your own
  293.         personal use, go ahead.  But, if you want to distribute your
  294.         enhanced version, contact me first.  Please remember that the
  295.         goal of XLISP is to provide a language to learn and experiment
  296.         with LISP and object-oriented programming on small computers.  I
  297.         don't want it to get so big that it requires megabytes of memory
  298.         to run.
  299.  
  300.  
  301.  
  302.  
  303.  
  304.  
  305.  
  306.  
  307.  
  308.  
  309.  
  310.  
  311.  
  312.  
  313.  
  314.  
  315.  
  316.  
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.         XLISP                 XLISP COMMAND LOOP                  Page 6
  335.  
  336.  
  337.         XLISP COMMAND LOOP
  338.  
  339.         When XLISP is started, it first tries to load the workspace
  340.         "xlisp.wks" from the current directory.  If that file doesn't
  341.         exist, XLISP builds an initial workspace, empty except for the
  342.         built-in functions and symbols.
  343.  
  344.         Then XLISP attempts to load "init.lsp" from the current
  345.         directory.  It then loads any files named as parameters on the
  346.         command line (after appending ".lsp" to their names).
  347.  
  348.         XLISP then issues the following prompt:
  349.  
  350.         >
  351.  
  352.         This indicates that XLISP is waiting for an expression to be
  353.         typed.
  354.  
  355.         When a complete expression has been entered, XLISP attempts to
  356.         evaluate that expression.  If the expression evaluates
  357.         successfully, XLISP prints the result and then returns to the
  358.         initial prompt waiting for another expression to be typed.
  359.  
  360.  
  361.  
  362.  
  363.  
  364.  
  365.  
  366.  
  367.  
  368.  
  369.  
  370.  
  371.  
  372.  
  373.  
  374.  
  375.  
  376.  
  377.  
  378.  
  379.  
  380.  
  381.  
  382.  
  383.  
  384.  
  385.  
  386.  
  387.  
  388.  
  389.  
  390.  
  391.  
  392.  
  393.  
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400.         XLISP                 BREAK COMMAND LOOP                  Page 7
  401.  
  402.  
  403.         BREAK COMMAND LOOP
  404.  
  405.         When XLISP encounters an error while evaluating an expression,
  406.         it attempts to handle the error in the following way:
  407.  
  408.         If the symbol '*breakenable*' is true, the message corresponding
  409.         to the error is printed.  If the error is correctable, the
  410.         correction message is printed.
  411.  
  412.         If the symbol '*tracenable*' is true, a trace back is printed.
  413.         The number of entries printed depends on the value of the symbol
  414.         '*tracelimit*'.  If this symbol is set to something other than a
  415.         number, the entire trace back stack is printed.
  416.  
  417.         XLISP then enters a read/eval/print loop to allow the user to
  418.         examine the state of the interpreter in the context of the
  419.         error.  This loop differs from the normal top-level
  420.         read/eval/print loop in that if the user invokes the function
  421.         'continue', XLISP will continue from a correctable error.  If
  422.         the user invokes the function 'clean-up', XLISP will abort the
  423.         break loop and return to the top level or the next lower
  424.         numbered break loop.  When in a break loop, XLISP prefixes the
  425.         break level to the normal prompt.
  426.  
  427.         If the symbol '*breakenable*' is nil, XLISP looks for a
  428.         surrounding errset function.  If one is found, XLISP examines
  429.         the value of the print flag.  If this flag is true, the error
  430.         message is printed.  In any case, XLISP causes the errset
  431.         function call to return nil.
  432.  
  433.         If there is no surrounding errset function, XLISP prints the
  434.         error message and returns to the top level.
  435.  
  436.  
  437.  
  438.  
  439.  
  440.  
  441.  
  442.  
  443.  
  444.  
  445.  
  446.  
  447.  
  448.  
  449.  
  450.  
  451.  
  452.  
  453.  
  454.  
  455.  
  456.  
  457.  
  458.  
  459.  
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466.         XLISP                      DATA TYPES                     Page 8
  467.  
  468.  
  469.         DATA TYPES
  470.  
  471.         There are several different data types available to XLISP
  472.         programmers.
  473.  
  474.             o lists
  475.             o symbols
  476.             o strings
  477.             o integers
  478.             o characters
  479.             o floats
  480.             o objects
  481.             o arrays
  482.             o streams
  483.             o subrs (built-in functions)
  484.             o fsubrs (special forms)
  485.             o closures (user defined functions)
  486.  
  487.  
  488.  
  489.  
  490.  
  491.  
  492.  
  493.  
  494.  
  495.  
  496.  
  497.  
  498.  
  499.  
  500.  
  501.  
  502.  
  503.  
  504.  
  505.  
  506.  
  507.  
  508.  
  509.  
  510.  
  511.  
  512.  
  513.  
  514.  
  515.  
  516.  
  517.  
  518.  
  519.  
  520.  
  521.  
  522.  
  523.  
  524.  
  525.  
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532.         XLISP                    THE EVALUATOR                    Page 9
  533.  
  534.  
  535.         THE EVALUATOR
  536.  
  537.         The process of evaluation in XLISP:
  538.  
  539.         Strings, integers, characters, floats, objects, arrays, streams,
  540.         subrs, fsubrs and closures evaluate to themselves.
  541.  
  542.         Symbols act as variables and are evaluated by retrieving the
  543.         value associated with their current binding.
  544.  
  545.         Lists are evaluated by examining the first element of the list
  546.         and then taking one of the following actions:
  547.  
  548.             If it is a symbol, the functional binding of the symbol is
  549.             retrieved.
  550.  
  551.             If it is a lambda expression, a closure is constructed for
  552.             the function described by the lambda expression.
  553.  
  554.             If it is a subr, fsubr or closure, it stands for itself.
  555.  
  556.             Any other value is an error.
  557.  
  558.         Then, the value produced by the previous step is examined:
  559.  
  560.             If it is a subr or closure, the remaining list elements are
  561.             evaluated and the subr or closure is called with these
  562.             evaluated expressions as arguments.
  563.  
  564.             If it is an fsubr, the fsubr is called using the remaining
  565.             list elements as arguments (unevaluated).
  566.  
  567.             If it is a macro, the macro is expanded using the remaining
  568.             list elements as arguments (unevaluated).  The macro
  569.             expansion is then evaluated in place of the original macro
  570.             call.
  571.  
  572.  
  573.  
  574.  
  575.  
  576.  
  577.  
  578.  
  579.  
  580.  
  581.  
  582.  
  583.  
  584.  
  585.  
  586.  
  587.  
  588.  
  589.  
  590.  
  591.  
  592.  
  593.  
  594.  
  595.  
  596.  
  597.  
  598.         XLISP                 LEXICAL CONVENTIONS                Page 10
  599.  
  600.  
  601.         LEXICAL CONVENTIONS
  602.  
  603.         The following conventions must be followed when entering XLISP
  604.         programs:
  605.  
  606.         Comments in XLISP code begin with a semi-colon character and
  607.         continue to the end of the line.
  608.  
  609.         Symbol names in XLISP can consist of any sequence of non-blank
  610.         printable characters except the following:
  611.  
  612.                 ( ) ' ` , " ;
  613.  
  614.         Uppercase and lowercase characters are not distinguished within
  615.         symbol names.  All lowercase characters are mapped to uppercase
  616.         on input.
  617.  
  618.         Integer literals consist of a sequence of digits optionally
  619.         beginning with a '+' or '-'.  The range of values an integer can
  620.         represent is limited by the size of a C 'long' on the machine on
  621.         which XLISP is running.
  622.  
  623.         Floating point literals consist of a sequence of digits
  624.         optionally beginning with a '+' or '-' and including an embedded
  625.         decimal point.  The range of values a floating point number can
  626.         represent is limited by the size of a C 'float' ('double' on
  627.         machines with 32 bit addresses) on the machine on which XLISP is
  628.         running.
  629.  
  630.         Literal strings are sequences of characters surrounded by double
  631.         quotes.  Within quoted strings the '\' character is used to
  632.         allow non-printable characters to be included.  The codes
  633.         recognized are:
  634.  
  635.                 \\        means the character '\'
  636.                 \n       means newline
  637.                 \t       means tab
  638.                 \r       means return
  639.                 \f       means form feed
  640.                 \nnn     means the character whose octal code is nnn
  641.  
  642.  
  643.  
  644.  
  645.  
  646.  
  647.  
  648.  
  649.  
  650.  
  651.  
  652.  
  653.  
  654.  
  655.  
  656.  
  657.  
  658.  
  659.  
  660.  
  661.  
  662.  
  663.  
  664.         XLISP                      READTABLES                    Page 11
  665.  
  666.  
  667.         READTABLES
  668.  
  669.         The behaviour of the reader is controlled by a data structure
  670.         called a "readtable".  The reader uses the symbol *READTABLE* to
  671.         locate the current readtable.  This table controls the
  672.         interpretation of input characters.  It is an array with 128
  673.         entries, one for each of the ASCII character codes.  Each entry
  674.         contains one of the following things:
  675.  
  676.                 NIL             Indicating an invalid character
  677.                 :CONSTITUENT    Indicating a symbol constituent
  678.                 :WHITE-SPACE    Indicating a whitespace character
  679.                 (:TMACRO . fun) Terminating readmacro
  680.                 (:NMACRO . fun) Non-terminating readmacro
  681.                 :SESCAPE        Single escape character ('\')
  682.                 :MESCAPE        Multiple escape character ('|')
  683.  
  684.         In the case of :TMACRO and :NMACRO, the "fun" component is a
  685.         function.  This can either be a built-in readmacro function or a
  686.         lambda expression.  The function should take two parameters.
  687.         The first is the input stream and the second is the character
  688.         that caused the invocation of the readmacro.  The readmacro
  689.         function should return NIL to indicate that the character should
  690.         be treated as white space or a value consed with NIL to indicate
  691.         that the readmacro should be treated as an occurance of the
  692.         specified value.  Of course, the readmacro code is free to read
  693.         additional characters from the input stream.
  694.  
  695.         XLISP defines several useful read macros:
  696.  
  697.                 '<expr>         == (quote <expr>)
  698.                 #'<expr>        == (function <expr>)
  699.                 #(<expr>...)    == an array of the specified expressions
  700.                 #x<hdigits>     == a hexadecimal number (0-9,A-F)
  701.                 #o<odigits>     == an octal number (0-7)
  702.                 #b<bdigits>     == a binary number (0-1)
  703.                 #\<char> == the ASCII code of the character
  704.                 #| ... |#       == a comment
  705.                 #:<symbol>      == an uninterned symbol
  706.                 `<expr>         == (backquote <expr>)
  707.                 ,<expr>         == (comma <expr>)
  708.                 ,@<expr>        == (comma-at <expr>)
  709.  
  710.  
  711.  
  712.  
  713.  
  714.  
  715.  
  716.  
  717.  
  718.  
  719.  
  720.  
  721.  
  722.  
  723.  
  724.  
  725.  
  726.  
  727.  
  728.  
  729.  
  730.         XLISP                     LAMBDA LISTS                   Page 12
  731.  
  732.  
  733.         LAMBDA LISTS
  734.  
  735.         There are several forms in XLISP that require that a "lambda
  736.         list" be specified.  A lambda list is a definition of the
  737.         arguments accepted by a function.  There are four different
  738.         types of arguments.
  739.  
  740.         The lambda list starts with required arguments.  Required
  741.         arguments must be specified in every call to the function.
  742.  
  743.         The required arguments are followed by the &optional arguments.
  744.         Optional arguments may be provided or omitted in a call.  An
  745.         initialization expression may be specified to provide a default
  746.         value for an &optional argument if it is omitted from a call.
  747.         If no initialization expression is specified, an omitted
  748.         argument is initialized to NIL.  It is also possible to provide
  749.         the name of a 'supplied-p' variable that can be used to
  750.         determine if a call provided a value for the argument or if the
  751.         initialization expression was used.  If specified, the supplied-
  752.         p variable will be bound to T if a value was specified in the
  753.         call and NIL if the default value was used.
  754.  
  755.         The &optional arguments are followed by the &rest argument.  The
  756.         &rest argument gets bound to the remainder of the argument list
  757.         after the required and &optional arguments have been removed.
  758.  
  759.         The &rest argument is followed by the &key arguments.  When a
  760.         keyword argument is passed to a function, a pair of values
  761.         appears in the argument list.  The first expression in the pair
  762.         should evaluate to a keyword symbol (a symbol that begins with a
  763.         ':').  The value of the second expression is the value of the
  764.         keyword argument.  Like &optional arguments, &key arguments can
  765.         have initialization expressions and supplied-p variables.  In
  766.         addition, it is possible to specify the keyword to be used in a
  767.         function call.  If no keyword is specified, the keyword obtained
  768.         by adding a ':' to the beginning of the keyword argument symbol
  769.         is used.  In other words, if the keyword argument symbol is
  770.         'foo', the keyword will be ':foo'.
  771.  
  772.         The &key arguments are followed by the &aux variables.  These
  773.         are local variables that are bound during the evaluation of the
  774.         function body.  It is possible to have initialization
  775.         expressions for the &aux variables.
  776.  
  777.  
  778.  
  779.  
  780.  
  781.  
  782.  
  783.  
  784.  
  785.  
  786.  
  787.  
  788.  
  789.  
  790.  
  791.  
  792.  
  793.  
  794.  
  795.  
  796.         XLISP                     LAMBDA LISTS                   Page 13
  797.  
  798.  
  799.         Here is the complete syntax for lambda lists:
  800.  
  801.                 (<rarg>...
  802.                  [&optional [<oarg> | (<oarg> [<init> [<svar>]])]...]
  803.                  [&rest <rarg>]
  804.                  [&key
  805.                    [<karg> | ([<karg> | (<key> <karg>)] [<init> [<svar>]])]...
  806.                    &allow-other-keys]
  807.                  [&aux
  808.                    [<aux> | (<aux> [<init>])]...])
  809.  
  810.             where:
  811.  
  812.                 <rarg>  is a required argument symbol
  813.                 <oarg>  is an &optional argument symbol
  814.                 <rarg>  is the &rest argument symbol
  815.                 <karg>  is a &key argument symbol
  816.                 <key>   is a keyword symbol
  817.                 <aux>   is an auxiliary variable symbol
  818.                 <init>  is an initialization expression
  819.                 <svar>  is a supplied-p variable symbol
  820.  
  821.  
  822.  
  823.  
  824.  
  825.  
  826.  
  827.  
  828.  
  829.  
  830.  
  831.  
  832.  
  833.  
  834.  
  835.  
  836.  
  837.  
  838.  
  839.  
  840.  
  841.  
  842.  
  843.  
  844.  
  845.  
  846.  
  847.  
  848.  
  849.  
  850.  
  851.  
  852.  
  853.  
  854.  
  855.  
  856.  
  857.  
  858.  
  859.  
  860.  
  861.  
  862.         XLISP                       OBJECTS                      Page 14
  863.  
  864.  
  865.         OBJECTS
  866.  
  867.         Definitions:
  868.  
  869.             o selector - a symbol used to select an appropriate method
  870.             o message - a selector and a list of actual arguments
  871.             o method - the code that implements a message
  872.  
  873.         Since XLISP was created to provide a simple basis for
  874.         experimenting with object-oriented programming, one of the
  875.         primitive data types included is 'object'.  In XLISP, an object
  876.         consists of a data structure containing a pointer to the
  877.         object's class as well as an array containing the values of the
  878.         object's instance variables.
  879.  
  880.         Officially, there is no way to see inside an object (look at the
  881.         values of its instance variables).  The only way to communicate
  882.         with an object is by sending it a message.
  883.  
  884.         You can send a message to an object using the 'send' function.
  885.         This function takes the object as its first argument, the
  886.         message selector as its second argument (which must be a symbol)
  887.         and the message arguments as its remaining arguments.
  888.  
  889.         The 'send' function determines the class of the receiving object
  890.         and attempts to find a method corresponding to the message
  891.         selector in the set of messages defined for that class.  If the
  892.         message is not found in the object's class and the class has a
  893.         super-class, the search continues by looking at the messages
  894.         defined for the super-class.  This process continues from one
  895.         super-class to the next until a method for the message is found.
  896.         If no method is found, an error occurs.
  897.  
  898.         A message can also be sent from the body of a method by using
  899.         the current object, but the method lookup starts with the
  900.         object's superclass rather than its class.  This allows a
  901.         subclass to invoke a standard method in its parent class even
  902.         though it overrides that method with its own specialized
  903.         version.
  904.  
  905.         When a method is found, the evaluator binds the receiving object
  906.         to the symbol 'self' and evaluates the method using the
  907.         remaining elements of the original list as arguments to the
  908.         method.  These arguments are always evaluated prior to being
  909.         bound to their corresponding formal arguments.  The result of
  910.         evaluating the method becomes the result of the expression.
  911.  
  912.  
  913.  
  914.  
  915.  
  916.  
  917.  
  918.  
  919.  
  920.  
  921.  
  922.  
  923.  
  924.  
  925.  
  926.  
  927.  
  928.         XLISP                       OBJECTS                      Page 15
  929.  
  930.  
  931.         THE 'Object' CLASS
  932.  
  933.         Classes:
  934.  
  935.         Object  THE TOP OF THE CLASS HEIRARCHY
  936.  
  937.             Messages:
  938.  
  939.                 :show  SHOW AN OBJECT'S INSTANCE VARIABLES
  940.                     returns     the object
  941.  
  942.                 :class  RETURN THE CLASS OF AN OBJECT
  943.                     returns     the class of the object
  944.  
  945.                 :isnew  THE DEFAULT OBJECT INITIALIZATION ROUTINE
  946.                     returns     the object
  947.  
  948.                 :sendsuper <sel> <args>...  SEND SUPERCLASS A MESSAGE
  949.                     <sel>       the message selector
  950.                     <args>      the message arguments
  951.                     returns     the result of sending the message
  952.  
  953.  
  954.  
  955.  
  956.  
  957.  
  958.  
  959.  
  960.  
  961.  
  962.  
  963.  
  964.  
  965.  
  966.  
  967.  
  968.  
  969.  
  970.  
  971.  
  972.  
  973.  
  974.  
  975.  
  976.  
  977.  
  978.  
  979.  
  980.  
  981.  
  982.  
  983.  
  984.  
  985.  
  986.  
  987.  
  988.  
  989.  
  990.  
  991.  
  992.  
  993.  
  994.         XLISP                       OBJECTS                      Page 16
  995.  
  996.  
  997.         THE 'Class' CLASS
  998.  
  999.         Class   THE CLASS OF ALL OBJECT CLASSES (including itself)
  1000.  
  1001.             Messages:
  1002.  
  1003.                 :new  CREATE A NEW INSTANCE OF A CLASS
  1004.                     returns     the new class object
  1005.  
  1006.                 :isnew <ivars> [<cvars> [<super>]]  INITIALIZE A NEW CLASS
  1007.                     <ivars>     the list of instance variable symbols
  1008.                     <cvars>     the list of class variable symbols
  1009.                     <super>     the superclass (default is Object)
  1010.                     returns     the new class object
  1011.  
  1012.                 :answer <msg> <fargs> <code>  ADD A MESSAGE TO A CLASS
  1013.                     <msg>       the message symbol
  1014.                     <fargs>     the formal argument list (lambda list)
  1015.                     <code>      a list of executable expressions
  1016.                     returns     the object
  1017.  
  1018.  
  1019.         When a new instance of a class is created by sending the message
  1020.         ':new' to an existing class, the message ':isnew' followed by
  1021.         whatever parameters were passed to the ':new' message is sent to
  1022.         the newly created object.
  1023.  
  1024.         When a new class is created by sending the ':new' message to the
  1025.         object 'Class', an optional parameter may be specified
  1026.         indicating the superclass of the new class.  If this parameter
  1027.         is omitted, the new class will be a subclass of 'Object'.  A
  1028.         class inherits all instance variables, class variables, and
  1029.         methods from its super-class.
  1030.  
  1031.  
  1032.  
  1033.  
  1034.  
  1035.  
  1036.  
  1037.  
  1038.  
  1039.  
  1040.  
  1041.  
  1042.  
  1043.  
  1044.  
  1045.  
  1046.  
  1047.  
  1048.  
  1049.  
  1050.  
  1051.  
  1052.  
  1053.  
  1054.  
  1055.  
  1056.  
  1057.  
  1058.  
  1059.  
  1060.         XLISP                       SYMBOLS                      Page 17
  1061.  
  1062.  
  1063.         SYMBOLS
  1064.  
  1065.             o self - the current object (within a method context)
  1066.             o *obarray* - the object hash table
  1067.             o *standard-input* - the standard input stream
  1068.             o *standard-output* - the standard output stream
  1069.             o *error-output* - the error output stream
  1070.             o *trace-output* - the trace output stream
  1071.             o *debug-io* - the debug i/o stream
  1072.             o *breakenable* - flag controlling entering break loop on errors
  1073.             o *tracelist* - list of names of functions to trace
  1074.             o *tracenable* - enable trace back printout on errors
  1075.             o *tracelimit* - number of levels of trace back information
  1076.             o *evalhook* - user substitute for the evaluator function
  1077.             o *applyhook* - (not yet implemented)
  1078.             o *readtable* - the current readtable
  1079.             o *unbound* - indicator for unbound symbols
  1080.             o *gc-flag* - controls the printing of gc messages
  1081.             o *gc-hook* - function to call after garbage collection
  1082.             o *integer-format* - format for printing integers ("%d" or "%ld")
  1083.             o *float-format* - format for printing floats ("%g")
  1084.             o *print-case* - symbol output case (:upcase or :downcase)
  1085.  
  1086.         There are several symbols maintained by the read/eval/print
  1087.         loop.  The symbols '+', '++', and '+++' are bound to the most
  1088.         recent three input expressions.  The symbols '*', '**' and '***'
  1089.         are bound to the most recent three results.  The symbol '-' is
  1090.         bound to the expression currently being evaluated.  It becomes
  1091.         the value of '+' at the end of the evaluation.
  1092.  
  1093.  
  1094.  
  1095.  
  1096.  
  1097.  
  1098.  
  1099.  
  1100.  
  1101.  
  1102.  
  1103.  
  1104.  
  1105.  
  1106.  
  1107.  
  1108.  
  1109.  
  1110.  
  1111.  
  1112.  
  1113.  
  1114.  
  1115.  
  1116.  
  1117.  
  1118.  
  1119.  
  1120.  
  1121.  
  1122.  
  1123.  
  1124.  
  1125.  
  1126.         XLISP                 EVALUATION FUNCTIONS               Page 18
  1127.  
  1128.  
  1129.         EVALUATION FUNCTIONS
  1130.  
  1131.         (eval <expr>)  EVALUATE AN XLISP EXPRESSION
  1132.             <expr>      the expression to be evaluated
  1133.             returns     the result of evaluating the expression
  1134.  
  1135.         (apply <fun> <args>)  APPLY A FUNCTION TO A LIST OF ARGUMENTS
  1136.             <fun>       the function to apply (or function symbol)
  1137.             <args>      the argument list
  1138.             returns     the result of applying the function to the arguments
  1139.  
  1140.         (funcall <fun> <arg>...)  CALL A FUNCTION WITH ARGUMENTS
  1141.             <fun>       the function to call (or function symbol)
  1142.             <arg>       arguments to pass to the function
  1143.             returns     the result of calling the function with the arguments
  1144.  
  1145.         (quote <expr>)  RETURN AN EXPRESSION UNEVALUATED
  1146.             <expr>      the expression to be quoted (quoted)
  1147.             returns     <expr> unevaluated
  1148.  
  1149.         (function <expr>)  GET THE FUNCTIONAL INTERPRETATION
  1150.             <expr>      the symbol or lambda expression (quoted)
  1151.             returns     the functional interpretation
  1152.  
  1153.         (backquote <expr>)  FILL IN A TEMPLATE
  1154.             <expr>      the template
  1155.             returns     a copy of the template with comma and comma-at
  1156.                         expressions expanded
  1157.  
  1158.         (lambda <args> <expr>...)  MAKE A FUNCTION CLOSURE
  1159.             <args>      formal argument list (lambda list) (quoted)
  1160.             <expr>      expressions of the function body
  1161.             returns     the function closure
  1162.  
  1163.         (get-lambda-expression <closure>)  GET THE LAMBDA EXPRESSION
  1164.             <closure>   the closure
  1165.             returns     the original lambda expression
  1166.  
  1167.         (macroexpand <form>)  RECURSIVELY EXPAND MACRO CALLS
  1168.             <form>      the form to expand
  1169.             returns     the macro expansion
  1170.  
  1171.         (macroexpand-1 <form>)  EXPAND A MACRO CALL
  1172.             <form>      the macro call form
  1173.             returns     the macro expansion
  1174.  
  1175.  
  1176.  
  1177.  
  1178.  
  1179.  
  1180.  
  1181.  
  1182.  
  1183.  
  1184.  
  1185.  
  1186.  
  1187.  
  1188.  
  1189.  
  1190.  
  1191.  
  1192.         XLISP                   SYMBOL FUNCTIONS                 Page 19
  1193.  
  1194.  
  1195.         SYMBOL FUNCTIONS
  1196.  
  1197.         (set <sym> <expr>)  SET THE VALUE OF A SYMBOL
  1198.             <sym>       the symbol being set
  1199.             <expr>      the new value
  1200.             returns     the new value
  1201.  
  1202.         (setq [<sym> <expr>]...)  SET THE VALUE OF A SYMBOL
  1203.             <sym>       the symbol being set (quoted)
  1204.             <expr>      the new value
  1205.             returns     the new value
  1206.  
  1207.         (psetq [<sym> <expr>]...)  PARALLEL VERSION OF SETQ
  1208.             <sym>       the symbol being set (quoted)
  1209.             <expr>      the new value
  1210.             returns     the new value
  1211.  
  1212.         (setf [<place> <expr>]...)  SET THE VALUE OF A FIELD
  1213.             <place>     the field specifier (quoted):
  1214.                           <sym>                   set value of a symbol
  1215.                           (car <expr>)            set car of a cons node
  1216.                           (cdr <expr>)            set cdr of a cons node
  1217.                           (nth <n> <expr>)        set nth car of a list
  1218.                           (aref <expr> <n>)       set nth element of an array
  1219.                           (get <sym> <prop>)      set value of a property
  1220.                           (symbol-value <sym>)    set value of a symbol
  1221.                           (symbol-function <sym>) set functional value of a symbol
  1222.                           (symbol-plist <sym>)    set property list of a symbol
  1223.             <value>     the new value
  1224.             returns     the new value
  1225.  
  1226.         (defun <sym> <fargs> <expr>...)  DEFINE A FUNCTION
  1227.         (defmacro <sym> <fargs> <expr>...)  DEFINE A MACRO
  1228.             <sym>       symbol being defined (quoted)
  1229.             <fargs>     formal argument list (lambda list) (quoted)
  1230.             <expr>      expressions constituting the body of the
  1231.                         function (quoted)
  1232.             returns     the function symbol
  1233.  
  1234.         (gensym [<tag>])  GENERATE A SYMBOL
  1235.             <tag>       string or number
  1236.             returns     the new symbol
  1237.  
  1238.         (intern <pname>)  MAKE AN INTERNED SYMBOL
  1239.             <pname>     the symbol's print name string
  1240.             returns     the new symbol
  1241.  
  1242.         (make-symbol <pname>)  MAKE AN UNINTERNED SYMBOL
  1243.             <pname>     the symbol's print name string
  1244.             returns     the new symbol
  1245.  
  1246.         (symbol-name <sym>)  GET THE PRINT NAME OF A SYMBOL
  1247.             <sym>       the symbol
  1248.             returns     the symbol's print name
  1249.  
  1250.  
  1251.  
  1252.  
  1253.  
  1254.  
  1255.  
  1256.  
  1257.  
  1258.         XLISP                   SYMBOL FUNCTIONS                 Page 20
  1259.  
  1260.  
  1261.         (symbol-value <sym>)  GET THE VALUE OF A SYMBOL
  1262.             <sym>       the symbol
  1263.             returns     the symbol's value
  1264.  
  1265.         (symbol-function <sym>)  GET THE FUNCTIONAL VALUE OF A SYMBOL
  1266.             <sym>       the symbol
  1267.             returns     the symbol's functional value
  1268.  
  1269.         (symbol-plist <sym>)  GET THE PROPERTY LIST OF A SYMBOL
  1270.             <sym>       the symbol
  1271.             returns     the symbol's property list
  1272.  
  1273.         (hash <sym> <n>)  COMPUTE THE HASH INDEX FOR A SYMBOL
  1274.             <sym>       the symbol or string
  1275.             <n>         the table size (integer)
  1276.             returns     the hash index (integer)
  1277.  
  1278.  
  1279.  
  1280.  
  1281.  
  1282.  
  1283.  
  1284.  
  1285.  
  1286.  
  1287.  
  1288.  
  1289.  
  1290.  
  1291.  
  1292.  
  1293.  
  1294.  
  1295.  
  1296.  
  1297.  
  1298.  
  1299.  
  1300.  
  1301.  
  1302.  
  1303.  
  1304.  
  1305.  
  1306.  
  1307.  
  1308.  
  1309.  
  1310.  
  1311.  
  1312.  
  1313.  
  1314.  
  1315.  
  1316.  
  1317.  
  1318.  
  1319.  
  1320.  
  1321.  
  1322.  
  1323.  
  1324.         XLISP               PROPERTY LIST FUNCTIONS              Page 21
  1325.  
  1326.  
  1327.         PROPERTY LIST FUNCTIONS
  1328.  
  1329.         (get <sym> <prop>)  GET THE VALUE OF A PROPERTY
  1330.             <sym>       the symbol
  1331.             <prop>      the property symbol
  1332.             returns     the property value or nil
  1333.  
  1334.         (putprop <sym> <val> <prop>)  PUT A PROPERTY ONTO A PROPERTY LIST
  1335.             <sym>       the symbol
  1336.             <val>       the property value
  1337.             <prop>      the property symbol
  1338.             returns     the property value
  1339.  
  1340.         (remprop <sym> <prop>)  REMOVE A PROPERTY
  1341.             <sym>       the symbol
  1342.             <prop>      the property symbol
  1343.             returns     nil
  1344.  
  1345.  
  1346.  
  1347.  
  1348.  
  1349.  
  1350.  
  1351.  
  1352.  
  1353.  
  1354.  
  1355.  
  1356.  
  1357.  
  1358.  
  1359.  
  1360.  
  1361.  
  1362.  
  1363.  
  1364.  
  1365.  
  1366.  
  1367.  
  1368.  
  1369.  
  1370.  
  1371.  
  1372.  
  1373.  
  1374.  
  1375.  
  1376.  
  1377.  
  1378.  
  1379.  
  1380.  
  1381.  
  1382.  
  1383.  
  1384.  
  1385.  
  1386.  
  1387.  
  1388.  
  1389.  
  1390.         XLISP                   ARRAY FUNCTIONS                  Page 22
  1391.  
  1392.  
  1393.         ARRAY FUNCTIONS
  1394.  
  1395.         (aref <array> <n>)  GET THE NTH ELEMENT OF AN ARRAY
  1396.             <array>     the array
  1397.             <n>         the array index (integer)
  1398.             returns     the value of the array element
  1399.  
  1400.         (make-array <size>)  MAKE A NEW ARRAY
  1401.             <size>      the size of the new array (integer)
  1402.             returns     the new array
  1403.  
  1404.         (vector <expr>...)  MAKE AN INITIALIZED VECTOR
  1405.             <expr>      the vector elements
  1406.             returns     the new vector
  1407.  
  1408.  
  1409.  
  1410.  
  1411.  
  1412.  
  1413.  
  1414.  
  1415.  
  1416.  
  1417.  
  1418.  
  1419.  
  1420.  
  1421.  
  1422.  
  1423.  
  1424.  
  1425.  
  1426.  
  1427.  
  1428.  
  1429.  
  1430.  
  1431.  
  1432.  
  1433.  
  1434.  
  1435.  
  1436.  
  1437.  
  1438.  
  1439.  
  1440.  
  1441.  
  1442.  
  1443.  
  1444.  
  1445.  
  1446.  
  1447.  
  1448.  
  1449.  
  1450.  
  1451.  
  1452.  
  1453.  
  1454.  
  1455.  
  1456.         XLISP                    LIST FUNCTIONS                  Page 23
  1457.  
  1458.  
  1459.         LIST FUNCTIONS
  1460.  
  1461.         (car <expr>)  RETURN THE CAR OF A LIST NODE
  1462.             <expr>      the list node
  1463.             returns     the car of the list node
  1464.  
  1465.         (cdr <expr>)  RETURN THE CDR OF A LIST NODE
  1466.             <expr>      the list node
  1467.             returns     the cdr of the list node
  1468.  
  1469.         (cxxr <expr>)  ALL CxxR COMBINATIONS
  1470.         (cxxxr <expr>)  ALL CxxxR COMBINATIONS
  1471.         (cxxxxr <expr>)  ALL CxxxxR COMBINATIONS
  1472.  
  1473.         (first <expr>)   A SYNONYM FOR CAR
  1474.         (second <expr>)  A SYNONYM FOR CADR
  1475.         (third <expr>)   A SYNONYM FOR CADDR
  1476.         (fourth <expr>)  A SYNONYM FOR CADDDR
  1477.         (rest <expr>)    A SYNONYM FOR CDR
  1478.  
  1479.         (cons <expr1> <expr2>)  CONSTRUCT A NEW LIST NODE
  1480.             <expr1>     the car of the new list node
  1481.             <expr2>     the cdr of the new list node
  1482.             returns     the new list node
  1483.  
  1484.         (list <expr>...)  CREATE A LIST OF VALUES
  1485.             <expr>      expressions to be combined into a list
  1486.             returns     the new list
  1487.  
  1488.         (append <expr>...)  APPEND LISTS
  1489.             <expr>      lists whose elements are to be appended
  1490.             returns     the new list
  1491.  
  1492.         (reverse <expr>)  REVERSE A LIST
  1493.             <expr>      the list to reverse
  1494.             returns     a new list in the reverse order
  1495.  
  1496.         (last <list>)  RETURN THE LAST LIST NODE OF A LIST
  1497.             <list>      the list
  1498.             returns     the last list node in the list
  1499.  
  1500.         (member <expr> <list> &key :test :test-not)  FIND AN EXPRESSION IN A LIST
  1501.             <expr>      the expression to find
  1502.             <list>      the list to search
  1503.             :test       the test function (defaults to eql)
  1504.             :test-not   the test function (sense inverted)      
  1505.             returns     the remainder of the list starting with the expression
  1506.  
  1507.         (assoc <expr> <alist> &key :test :test-not)  FIND AN EXPRESSION IN AN A-LIST
  1508.             <expr>      the expression to find
  1509.             <alist>     the association list
  1510.             :test       the test function (defaults to eql)
  1511.             :test-not   the test function (sense inverted)      
  1512.             returns     the alist entry or nil
  1513.  
  1514.  
  1515.  
  1516.  
  1517.  
  1518.  
  1519.  
  1520.  
  1521.  
  1522.         XLISP                    LIST FUNCTIONS                  Page 24
  1523.  
  1524.  
  1525.         (remove <expr> <list> &key :test :test-not)  REMOVE ELEMENTS FROM A LIST
  1526.             <expr>      the element to remove
  1527.             <list>      the list
  1528.             :test       the test function (defaults to eql)
  1529.             :test-not   the test function (sense inverted)      
  1530.             returns     copy of list with matching expressions removed
  1531.  
  1532.         (remove-if <test> <list>)  REMOVE ELEMENTS THAT PASS TEST
  1533.             <test>      the test predicate
  1534.             <list>      the list
  1535.             returns     copy of list with matching elements removed
  1536.  
  1537.         (remove-if-not <test> <list>)  REMOVE ELEMENTS THAT FAIL TEST
  1538.             <test>      the test predicate
  1539.             <list>      the list
  1540.             returns     copy of list with non-matching elements removed
  1541.  
  1542.         (length <expr>)  FIND THE LENGTH OF A LIST, VECTOR OR STRING
  1543.             <expr>      the list, vector or string
  1544.             returns     the length of the list, vector or string
  1545.  
  1546.         (nth <n> <list>)  RETURN THE NTH ELEMENT OF A LIST
  1547.             <n>         the number of the element to return (zero origin)
  1548.             <list>      the list
  1549.             returns     the nth element or nil if the list isn't that long
  1550.  
  1551.         (nthcdr <n> <list>)  RETURN THE NTH CDR OF A LIST
  1552.             <n>         the number of the element to return (zero origin)
  1553.             <list>      the list
  1554.             returns     the nth cdr or nil if the list isn't that long
  1555.  
  1556.         (mapc <fcn> <list1> <list>...)  APPLY FUNCTION TO SUCCESSIVE CARS
  1557.             <fcn>       the function or function name
  1558.             <listn>     a list for each argument of the function
  1559.             returns     the first list of arguments
  1560.  
  1561.         (mapcar <fcn> <list1> <list>...)  APPLY FUNCTION TO SUCCESSIVE CARS
  1562.             <fcn>       the function or function name
  1563.             <listn>     a list for each argument of the function
  1564.             returns     a list of the values returned
  1565.  
  1566.         (mapl <fcn> <list1> <list>...)  APPLY FUNCTION TO SUCCESSIVE CDRS
  1567.             <fcn>       the function or function name
  1568.             <listn>     a list for each argument of the function
  1569.             returns     the first list of arguments
  1570.  
  1571.         (maplist <fcn> <list1> <list>...)  APPLY FUNCTION TO SUCCESSIVE CDRS
  1572.             <fcn>       the function or function name
  1573.             <listn>     a list for each argument of the function
  1574.             returns     a list of the values returned
  1575.  
  1576.  
  1577.  
  1578.  
  1579.  
  1580.  
  1581.  
  1582.  
  1583.  
  1584.  
  1585.  
  1586.  
  1587.  
  1588.         XLISP                    LIST FUNCTIONS                  Page 25
  1589.  
  1590.  
  1591.         (subst <to> <from> <expr> &key :test :test-not)  SUBSTITUTE EXPRESSIONS
  1592.             <to>        the new expression
  1593.             <from>      the old expression
  1594.             <expr>      the expression in which to do the substitutions
  1595.             :test       the test function (defaults to eql)
  1596.             :test-not   the test function (sense inverted)      
  1597.             returns     the expression with substitutions
  1598.  
  1599.         (sublis <alist> <expr> &key :test :test-not)  SUBSTITUTE WITH AN A-LIST
  1600.             <alist>     the association list
  1601.             <expr>      the expression in which to do the substitutions
  1602.             :test       the test function (defaults to eql)
  1603.             :test-not   the test function (sense inverted)      
  1604.             returns     the expression with substitutions
  1605.  
  1606.  
  1607.  
  1608.  
  1609.  
  1610.  
  1611.  
  1612.  
  1613.  
  1614.  
  1615.  
  1616.  
  1617.  
  1618.  
  1619.  
  1620.  
  1621.  
  1622.  
  1623.  
  1624.  
  1625.  
  1626.  
  1627.  
  1628.  
  1629.  
  1630.  
  1631.  
  1632.  
  1633.  
  1634.  
  1635.  
  1636.  
  1637.  
  1638.  
  1639.  
  1640.  
  1641.  
  1642.  
  1643.  
  1644.  
  1645.  
  1646.  
  1647.  
  1648.  
  1649.  
  1650.  
  1651.  
  1652.  
  1653.  
  1654.         XLISP              DESTRUCTIVE LIST FUNCTIONS            Page 26
  1655.  
  1656.  
  1657.         DESTRUCTIVE LIST FUNCTIONS
  1658.  
  1659.         (rplaca <list> <expr>)  REPLACE THE CAR OF A LIST NODE
  1660.             <list>      the list node
  1661.             <expr>      the new value for the car of the list node
  1662.             returns     the list node after updating the car
  1663.  
  1664.         (rplacd <list> <expr>)  REPLACE THE CDR OF A LIST NODE
  1665.             <list>      the list node
  1666.             <expr>      the new value for the cdr of the list node
  1667.             returns     the list node after updating the cdr
  1668.  
  1669.         (nconc <list>...)  DESTRUCTIVELY CONCATENATE LISTS
  1670.             <list>      lists to concatenate
  1671.             returns     the result of concatenating the lists
  1672.  
  1673.         (delete <expr> &key :test :test-not)  DELETE ELEMENTS FROM A LIST
  1674.             <expr>      the element to delete
  1675.             <list>      the list
  1676.             :test       the test function (defaults to eql)
  1677.             :test-not   the test function (sense inverted)      
  1678.             returns     the list with the matching expressions deleted
  1679.  
  1680.         (delete-if <test> <list>)  DELETE ELEMENTS THAT PASS TEST
  1681.             <test>      the test predicate
  1682.             <list>      the list
  1683.             returns     the list with matching elements deleted
  1684.  
  1685.         (delete-if-not <test> <list>)  DELETE ELEMENTS THAT FAIL TEST
  1686.             <test>      the test predicate
  1687.             <list>      the list
  1688.             returns     the list with non-matching elements deleted
  1689.  
  1690.         (sort <list> <test>)  SORT A LIST
  1691.             <list>      the list to sort
  1692.             <test>      the comparison function
  1693.             returns     the sorted list
  1694.  
  1695.  
  1696.  
  1697.  
  1698.  
  1699.  
  1700.  
  1701.  
  1702.  
  1703.  
  1704.  
  1705.  
  1706.  
  1707.  
  1708.  
  1709.  
  1710.  
  1711.  
  1712.  
  1713.  
  1714.  
  1715.  
  1716.  
  1717.  
  1718.  
  1719.  
  1720.         XLISP                 PREDICATE FUNCTIONS                Page 27
  1721.  
  1722.  
  1723.         PREDICATE FUNCTIONS
  1724.  
  1725.         (atom <expr>)  IS THIS AN ATOM?
  1726.             <expr>      the expression to check
  1727.             returns     t if the value is an atom, nil otherwise
  1728.  
  1729.         (symbolp <expr>)  IS THIS A SYMBOL?
  1730.             <expr>      the expression to check
  1731.             returns     t if the expression is a symbol, nil otherwise
  1732.  
  1733.         (numberp <expr>)  IS THIS A NUMBER?
  1734.             <expr>      the expression to check
  1735.             returns     t if the expression is a number, nil otherwise
  1736.  
  1737.         (null <expr>)  IS THIS AN EMPTY LIST?
  1738.             <expr>      the list to check
  1739.             returns     t if the list is empty, nil otherwise
  1740.  
  1741.         (not <expr>)  IS THIS FALSE?
  1742.             <expr>      the expression to check
  1743.             return      t if the value is nil, nil otherwise
  1744.  
  1745.         (listp <expr>)  IS THIS A LIST?
  1746.             <expr>      the expression to check
  1747.             returns     t if the value is a cons or nil, nil otherwise
  1748.  
  1749.         (endp <list>)  IS THIS THE END OF A LIST
  1750.             <list>      the list
  1751.             returns     t if the value is nil, nil otherwise
  1752.  
  1753.         (consp <expr>)  IS THIS A NON-EMPTY LIST?
  1754.             <expr>      the expression to check
  1755.             returns     t if the value is a cons, nil otherwise
  1756.  
  1757.         (integerp <expr>)  IS THIS AN INTEGER?
  1758.             <expr>      the expression to check
  1759.             returns     t if the value is an integer, nil otherwise
  1760.  
  1761.         (floatp <expr>)  IS THIS A FLOAT?
  1762.             <expr>      the expression to check
  1763.             returns     t if the value is a float, nil otherwise
  1764.  
  1765.         (stringp <expr>)  IS THIS A STRING?
  1766.             <expr>      the expression to check
  1767.             returns     t if the value is a string, nil otherwise
  1768.  
  1769.         (characterp <expr>)  IS THIS A CHARACTER?
  1770.             <expr>      the expression to check
  1771.             returns     t if the value is a character, nil otherwise
  1772.  
  1773.         (arrayp <expr>)  IS THIS AN ARRAY?
  1774.             <expr>      the expression to check
  1775.             returns     t if the value is an array, nil otherwise
  1776.  
  1777.  
  1778.  
  1779.  
  1780.  
  1781.  
  1782.  
  1783.  
  1784.  
  1785.  
  1786.         XLISP                 PREDICATE FUNCTIONS                Page 28
  1787.  
  1788.  
  1789.         (streamp <expr>)  IS THIS A STREAM?
  1790.             <expr>      the expression to check
  1791.             returns     t if the value is a stream, nil otherwise
  1792.  
  1793.         (objectp <expr>)  IS THIS AN OBJECT?
  1794.             <expr>      the expression to check
  1795.             returns     t if the value is an object, nil otherwise
  1796.  
  1797.         (boundp <sym>)  IS A VALUE BOUND TO THIS SYMBOL?
  1798.             <sym>       the symbol
  1799.             returns     t if a value is bound to the symbol, nil otherwise
  1800.  
  1801.         (fboundp <sym>)  IS A FUNCTIONAL VALUE BOUND TO THIS SYMBOL?
  1802.             <sym>       the symbol
  1803.             returns     t if a functional value is bound to the symbol,
  1804.                         nil otherwise
  1805.  
  1806.         (minusp <expr>)  IS THIS NUMBER NEGATIVE?
  1807.             <expr>      the number to test
  1808.             returns     t if the number is negative, nil otherwise
  1809.  
  1810.         (zerop <expr>)  IS THIS NUMBER ZERO?
  1811.             <expr>      the number to test
  1812.             returns     t if the number is zero, nil otherwise
  1813.  
  1814.         (plusp <expr>)  IS THIS NUMBER POSITIVE?
  1815.             <expr>      the number to test
  1816.             returns     t if the number is positive, nil otherwise
  1817.  
  1818.         (evenp <expr>)  IS THIS INTEGER EVEN?
  1819.             <expr>      the integer to test
  1820.             returns     t if the integer is even, nil otherwise
  1821.  
  1822.         (oddp <expr>)  IS THIS INTEGER ODD?
  1823.             <expr>      the integer to test
  1824.             returns     t if the integer is odd, nil otherwise
  1825.  
  1826.         (eq <expr1> <expr2>)  ARE THE EXPRESSIONS IDENTICAL?
  1827.             <expr1>     the first expression
  1828.             <expr2>     the second expression
  1829.             returns     t if they are equal, nil otherwise
  1830.  
  1831.         (eql <expr1> <expr2>)  ARE THE EXPRESSIONS IDENTICAL?
  1832.                                 (WORKS WITH ALL NUMBERS)
  1833.             <expr1>     the first expression
  1834.             <expr2>     the second expression
  1835.             returns     t if they are equal, nil otherwise
  1836.  
  1837.         (equal <expr1> <expr2>)  ARE THE EXPRESSIONS EQUAL?
  1838.             <expr1>     the first expression
  1839.             <expr2>     the second expression
  1840.             returns     t if they are equal, nil otherwise
  1841.  
  1842.  
  1843.  
  1844.  
  1845.  
  1846.  
  1847.  
  1848.  
  1849.  
  1850.  
  1851.  
  1852.         XLISP                  CONTROL CONSTRUCTS                Page 29
  1853.  
  1854.  
  1855.         CONTROL CONSTRUCTS
  1856.  
  1857.         (cond <pair>...)  EVALUATE CONDITIONALLY
  1858.             <pair>      pair consisting of:
  1859.                             (<pred> <expr>...)
  1860.                           where
  1861.                             <pred>      is a predicate expression
  1862.                             <expr>      evaluated if the predicate
  1863.                                         is not nil
  1864.             returns     the value of the first expression whose predicate
  1865.                         is not nil
  1866.  
  1867.         (and <expr>...)  THE LOGICAL AND OF A LIST OF EXPRESSIONS
  1868.             <expr>      the expressions to be ANDed
  1869.             returns     nil if any expression evaluates to nil,
  1870.                         otherwise the value of the last expression
  1871.                         (evaluation of expressions stops after the first
  1872.                          expression that evaluates to nil)
  1873.  
  1874.         (or <expr>...)  THE LOGICAL OR OF A LIST OF EXPRESSIONS
  1875.             <expr>      the expressions to be ORed
  1876.             returns     nil if all expressions evaluate to nil,
  1877.                         otherwise the value of the first non-nil expression
  1878.                         (evaluation of expressions stops after the first
  1879.                          expression that does not evaluate to nil)
  1880.  
  1881.         (if <texpr> <expr1> [<expr2>])  EVALUATE EXPRESSIONS CONDITIONALLY
  1882.             <texpr>     the test expression
  1883.             <expr1>     the expression to be evaluated if texpr is non-nil
  1884.             <expr2>     the expression to be evaluated if texpr is nil
  1885.             returns     the value of the selected expression
  1886.  
  1887.         (when <texpr> <expr>...)  EVALUATE ONLY WHEN A CONDITION IS TRUE
  1888.             <texpr>     the test expression
  1889.             <expr>      the expression(s) to be evaluted if texpr is non-nil
  1890.             returns     the value of the last expression or nil
  1891.  
  1892.         (unless <texpr> <expr>...)  EVALUATE ONLY WHEN A CONDITION IS FALSE
  1893.             <texpr>     the test expression
  1894.             <expr>      the expression(s) to be evaluated if texpr is nil
  1895.             returns     the value of the last expression or nil
  1896.  
  1897.           (case <expr> <case>...)  SELECT BY CASE
  1898.             <expr>      the selection expression
  1899.             <case>      pair consisting of:
  1900.                             (<value> <expr>...)
  1901.                           where:
  1902.                             <value>     is a single expression or a list of
  1903.                                         expressions (unevaluated)
  1904.                             <expr>      are expressions to execute if the
  1905.                                         case matches
  1906.             returns     the value of the last expression of the matching case
  1907.  
  1908.  
  1909.  
  1910.  
  1911.  
  1912.  
  1913.  
  1914.  
  1915.  
  1916.  
  1917.  
  1918.         XLISP                  CONTROL CONSTRUCTS                Page 30
  1919.  
  1920.  
  1921.         (let (<binding>...) <expr>...)  CREATE LOCAL BINDINGS
  1922.         (let* (<binding>...) <expr>...)  LET WITH SEQUENTIAL BINDING
  1923.             <binding>   the variable bindings each of which is either:
  1924.                         1)  a symbol (which is initialized to nil)
  1925.                         2)  a list whose car is a symbol and whose cadr
  1926.                                 is an initialization expression
  1927.             <expr>      the expressions to be evaluated
  1928.             returns     the value of the last expression
  1929.  
  1930.         (flet (<binding>...) <expr>...)  CREATE LOCAL FUNCTIONS
  1931.         (labels (<binding>...) <expr>...)  FLET WITH RECURSIVE FUNCTIONS
  1932.         (macrolet (<binding>...) <expr>...)  CREATE LOCAL MACROS
  1933.             <binding>   the function bindings each of which is:
  1934.                           (<sym> <fargs> <expr>...)
  1935.                         where:
  1936.                             <sym>       the function/macro name
  1937.                             <fargs>     formal argument list (lambda list)
  1938.                             <expr>      expressions constituting the body of
  1939.                                         the function/macro
  1940.             <expr>      the expressions to be evaluated
  1941.             returns     the value of the last expression
  1942.  
  1943.         (catch <sym> <expr>...)  EVALUATE EXPRESSIONS AND CATCH THROWS
  1944.             <sym>       the catch tag
  1945.             <expr>      expressions to evaluate
  1946.             returns     the value of the last expression the throw expression
  1947.  
  1948.         (throw <sym> [<expr>])  THROW TO A CATCH
  1949.             <sym>       the catch tag
  1950.             <expr>      the value for the catch to return (defaults to nil)
  1951.             returns     never returns
  1952.  
  1953.         (unwind-protect <expr> <cexpr>...)  PROTECT EVALUATION OF AN EXPRESSION
  1954.             <expr>      the expression to protect
  1955.             <cexpr>     the cleanup expressions
  1956.             returns     the value of the expression
  1957.           Note:  unwind-protect guarantees to execute the cleanup expressions
  1958.                  even if a non-local exit terminates the evaluation of the
  1959.                  protected expression
  1960.  
  1961.  
  1962.  
  1963.  
  1964.  
  1965.  
  1966.  
  1967.  
  1968.  
  1969.  
  1970.  
  1971.  
  1972.  
  1973.  
  1974.  
  1975.  
  1976.  
  1977.  
  1978.  
  1979.  
  1980.  
  1981.  
  1982.  
  1983.  
  1984.         XLISP                  LOOPING CONSTRUCTS                Page 31
  1985.  
  1986.  
  1987.         LOOPING CONSTRUCTS
  1988.  
  1989.         (loop <expr>...)  BASIC LOOPING FORM
  1990.             <expr>      the body of the loop
  1991.             returns     never returns (must use non-local exit)
  1992.  
  1993.         (do (<binding>...) (<texpr> <rexpr>...) <expr>...)
  1994.         (do* (<binding>...) (<texpr> <rexpr>...) <expr>...)
  1995.             <binding>   the variable bindings each of which is either:
  1996.                         1)  a symbol (which is initialized to nil)
  1997.                         2)  a list of the form: (<sym> <init> [<step>])
  1998.                             where:
  1999.                                 <sym>  is the symbol to bind
  2000.                                 <init> is the initial value of the symbol
  2001.                                 <step> is a step expression
  2002.             <texpr>     the termination test expression
  2003.             <rexpr>     result expressions (the default is nil)
  2004.             <expr>      the body of the loop (treated like an implicit prog)
  2005.             returns     the value of the last result expression
  2006.  
  2007.         (dolist (<sym> <expr> [<rexpr>]) <expr>...)  LOOP THROUGH A LIST
  2008.             <sym>       the symbol to bind to each list element
  2009.             <expr>      the list expression
  2010.             <rexpr>     the result expression (the default is nil)
  2011.             <expr>      the body of the loop (treated like an implicit prog)
  2012.  
  2013.         (dotimes (<sym> <expr> [<rexpr>]) <expr>...)  LOOP FROM ZERO TO N-1
  2014.             <sym>       the symbol to bind to each value from 0 to n-1
  2015.             <expr>      the number of times to loop
  2016.             <rexpr>     the result expression (the default is nil)
  2017.             <expr>      the body of the loop (treated like an implicit prog)
  2018.  
  2019.  
  2020.  
  2021.  
  2022.  
  2023.  
  2024.  
  2025.  
  2026.  
  2027.  
  2028.  
  2029.  
  2030.  
  2031.  
  2032.  
  2033.  
  2034.  
  2035.  
  2036.  
  2037.  
  2038.  
  2039.  
  2040.  
  2041.  
  2042.  
  2043.  
  2044.  
  2045.  
  2046.  
  2047.  
  2048.  
  2049.  
  2050.         XLISP                 THE PROGRAM FEATURE                Page 32
  2051.  
  2052.  
  2053.         THE PROGRAM FEATURE
  2054.  
  2055.         (prog (<binding>...) <expr>...)  THE PROGRAM FEATURE
  2056.         (prog* (<binding>...) <expr>...)  PROG WITH SEQUENTIAL BINDING
  2057.             <binding>   the variable bindings each of which is either:
  2058.                         1)  a symbol (which is initialized to nil)
  2059.                         2)  a list whose car is a symbol and whose cadr
  2060.                                 is an initialization expression
  2061.             <expr>      expressions to evaluate or tags (symbols)
  2062.             returns     nil or the argument passed to the return function
  2063.  
  2064.         (block <name> <expr>...)  NAMED BLOCK
  2065.             <name>      the block name (symbol)
  2066.             <expr>      the block body
  2067.             returns     the value of the last expression
  2068.  
  2069.         (return [<expr>])  CAUSE A PROG CONSTRUCT TO RETURN A VALUE
  2070.             <expr>      the value (defaults to nil)
  2071.             returns     never returns
  2072.  
  2073.         (return-from <name> [<value>])  RETURN FROM A NAMED BLOCK
  2074.             <name>      the block name (symbol)
  2075.             <value>     the value to return (defaults to nil)
  2076.             returns     never returns
  2077.  
  2078.         (tagbody <expr>...)  BLOCK WITH LABELS
  2079.             <expr>      expression(s) to evaluate or tags (symbols)
  2080.             returns     nil
  2081.  
  2082.         (go <sym>)  GO TO A TAG WITHIN A TAGBODY OR PROG
  2083.             <sym>       the tag (quoted)
  2084.             returns     never returns
  2085.  
  2086.         (progv <slist> <vlist> <expr>...)  DYNAMICALLY BIND SYMBOLS
  2087.             <slist>     list of symbols
  2088.             <vlist>     list of values to bind to the symbols
  2089.             <expr>      expression(s) to evaluate
  2090.             returns     the value of the last expression
  2091.  
  2092.         (prog1 <expr1> <expr>...)  EXECUTE EXPRESSIONS SEQUENTIALLY
  2093.             <expr1>     the first expression to evaluate
  2094.             <expr>      the remaining expressions to evaluate
  2095.             returns     the value of the first expression
  2096.  
  2097.         (prog2 <expr1> <expr2> <expr>...)  EXECUTE EXPRESSIONS SEQUENTIALLY
  2098.             <expr1>     the first expression to evaluate
  2099.             <expr2>     the second expression to evaluate
  2100.             <expr>      the remaining expressions to evaluate
  2101.             returns     the value of the second expression
  2102.  
  2103.         (progn <expr>...)  EXECUTE EXPRESSIONS SEQUENTIALLY
  2104.             <expr>      the expressions to evaluate
  2105.             returns     the value of the last expression (or nil)
  2106.  
  2107.  
  2108.  
  2109.  
  2110.  
  2111.  
  2112.  
  2113.  
  2114.  
  2115.  
  2116.         XLISP             DEBUGGING AND ERROR HANDLING           Page 33
  2117.  
  2118.  
  2119.         DEBUGGING AND ERROR HANDLING
  2120.  
  2121.         (trace <sym>)  ADD A FUNCTION TO THE TRACE LIST
  2122.             <sym>       the function to add (quoted)
  2123.             returns     the trace list
  2124.  
  2125.         (untrace <sym>)  REMOVE A FUNCTION FROM THE TRACE LIST
  2126.             <sym>       the function to remove (quoted)
  2127.             returns     the trace list
  2128.  
  2129.         (error <emsg> [<arg>])  SIGNAL A NON-CORRECTABLE ERROR
  2130.             <emsg>      the error message string
  2131.             <arg>       the argument expression (printed after the message)
  2132.             returns     never returns
  2133.  
  2134.         (cerror <cmsg> <emsg> [<arg>])  SIGNAL A CORRECTABLE ERROR
  2135.             <cmsg>      the continue message string
  2136.             <emsg>      the error message string
  2137.             <arg>       the argument expression (printed after the message)
  2138.             returns     nil when continued from the break loop
  2139.  
  2140.         (break [<bmsg> [<arg>]])  ENTER A BREAK LOOP
  2141.             <bmsg>      the break message string (defaults to "**BREAK**")
  2142.             <arg>       the argument expression (printed after the message)
  2143.             returns     nil when continued from the break loop
  2144.  
  2145.         (clean-up)  CLEAN-UP AFTER AN ERROR
  2146.             returns     never returns
  2147.  
  2148.         (top-level)  CLEAN-UP AFTER AN ERROR AND RETURN TO THE TOP LEVEL
  2149.             returns     never returns
  2150.  
  2151.         (continue)  CONTINUE FROM A CORRECTABLE ERROR
  2152.             returns     never returns
  2153.  
  2154.         (errset <expr> [<pflag>])  TRAP ERRORS
  2155.             <expr>      the expression to execute
  2156.             <pflag>     flag to control printing of the error message
  2157.             returns     the value of the last expression consed with nil
  2158.                         or nil on error
  2159.  
  2160.         (baktrace [<n>])  PRINT N LEVELS OF TRACE BACK INFORMATION
  2161.             <n>         the number of levels (defaults to all levels)
  2162.             returns     nil
  2163.  
  2164.         (evalhook <expr> <ehook> <ahook> [<env>])  EVALUATE WITH HOOKS
  2165.             <expr>      the expression to evaluate
  2166.             <ehook>     the value for *evalhook*
  2167.             <ahook>     the value for *applyhook*
  2168.             <env>       the environment (default is nil)
  2169.             returns     the result of evaluating the expression
  2170.  
  2171.  
  2172.  
  2173.  
  2174.  
  2175.  
  2176.  
  2177.  
  2178.  
  2179.  
  2180.  
  2181.  
  2182.         XLISP                 ARITHMETIC FUNCTIONS               Page 34
  2183.  
  2184.  
  2185.         ARITHMETIC FUNCTIONS
  2186.  
  2187.         (truncate <expr>)  TRUNCATES A FLOATING POINT NUMBER TO AN INTEGER
  2188.             <expr>      the number
  2189.             returns     the result of truncating the number
  2190.  
  2191.         (float <expr>)  CONVERTS AN INTEGER TO A FLOATING POINT NUMBER
  2192.             <expr>      the number
  2193.             returns     the result of floating the integer
  2194.  
  2195.         (+ <expr>...)  ADD A LIST OF NUMBERS
  2196.             <expr>      the numbers
  2197.             returns     the result of the addition
  2198.  
  2199.         (- <expr>...)  SUBTRACT A LIST OF NUMBERS OR NEGATE A SINGLE NUMBER
  2200.             <expr>      the numbers
  2201.             returns     the result of the subtraction
  2202.  
  2203.         (* <expr>...)  MULTIPLY A LIST OF NUMBERS
  2204.             <expr>      the numbers
  2205.             returns     the result of the multiplication
  2206.  
  2207.         (/ <expr>...)  DIVIDE A LIST OF NUMBERS
  2208.             <expr>      the numbers
  2209.             returns     the result of the division
  2210.  
  2211.         (1+ <expr>)  ADD ONE TO A NUMBER
  2212.             <expr>      the number
  2213.             returns     the number plus one
  2214.  
  2215.         (1- <expr>)  SUBTRACT ONE FROM A NUMBER
  2216.             <expr>      the number
  2217.             returns     the number minus one
  2218.  
  2219.         (rem <expr>...)  REMAINDER OF A LIST OF NUMBERS
  2220.             <expr>      the numbers
  2221.             returns     the result of the remainder operation
  2222.  
  2223.         (min <expr>...)  THE SMALLEST OF A LIST OF NUMBERS
  2224.             <expr>      the expressions to be checked
  2225.             returns     the smallest number in the list
  2226.  
  2227.         (max <expr>...)  THE LARGEST OF A LIST OF NUMBERS
  2228.             <expr>      the expressions to be checked
  2229.             returns     the largest number in the list
  2230.  
  2231.         (abs <expr>)  THE ABSOLUTE VALUE OF A NUMBER
  2232.             <expr>      the number
  2233.             returns     the absolute value of the number
  2234.  
  2235.         (gcd <n1> <n2>...)  COMPUTE THE GREATEST COMMON DIVISOR
  2236.             <n1>        the first number (integer)
  2237.             <n2>        the second number(s) (integer)
  2238.             returns     the greatest common divisor
  2239.  
  2240.  
  2241.  
  2242.  
  2243.  
  2244.  
  2245.  
  2246.  
  2247.  
  2248.         XLISP                 ARITHMETIC FUNCTIONS               Page 35
  2249.  
  2250.  
  2251.         (random <n>)  COMPUTE A RANDOM NUMBER BETWEEN 1 and N-1
  2252.             <n>         the upper bound (integer)
  2253.             returns     a random number
  2254.  
  2255.         (sin <expr>)  COMPUTE THE SINE OF A NUMBER
  2256.             <expr>      the floating point number
  2257.             returns     the sine of the number
  2258.  
  2259.         (cos <expr>)  COMPUTE THE COSINE OF A NUMBER
  2260.             <expr>      the floating point number
  2261.             returns     the cosine of the number
  2262.  
  2263.         (tan <expr>)  COMPUTE THE TANGENT OF A NUMBER
  2264.             <expr>      the floating point number
  2265.             returns     the tangent of the number
  2266.  
  2267.         (expt <x-expr> <y-expr>)  COMPUTE X TO THE Y POWER
  2268.             <x-expr>    the floating point number
  2269.             <y-expr>    the floating point exponent
  2270.             returns     x to the y power
  2271.  
  2272.         (exp <x-expr>)  COMPUTE E TO THE X POWER
  2273.             <x-expr>    the floating point number
  2274.             returns     e to the x power
  2275.  
  2276.         (sqrt <expr>)  COMPUTE THE SQUARE ROOT OF A NUMBER
  2277.             <expr>      the floating point number
  2278.             returns     the square root of the number
  2279.  
  2280.         (< <n1> <n2>...)  TEST FOR LESS THAN
  2281.         (<= <n1> <n2>...)  TEST FOR LESS THAN OR EQUAL TO
  2282.         (= <n1> <n2>...)  TEST FOR EQUAL TO
  2283.         (/= <n1> <n2>...)  TEST FOR NOT EQUAL TO
  2284.         (>= <n1> <n2>...)  TEST FOR GREATER THAN OR EQUAL TO
  2285.         (> <n1> <n2>...)  TEST FOR GREATER THAN
  2286.             <n1>        the first number to compare
  2287.             <n2>        the second number to compare
  2288.             returns     the result of comparing <n1> with <n2>...
  2289.  
  2290.  
  2291.  
  2292.  
  2293.  
  2294.  
  2295.  
  2296.  
  2297.  
  2298.  
  2299.  
  2300.  
  2301.  
  2302.  
  2303.  
  2304.  
  2305.  
  2306.  
  2307.  
  2308.  
  2309.  
  2310.  
  2311.  
  2312.  
  2313.  
  2314.         XLISP              BITWISE LOGICAL FUNCTIONS             Page 36
  2315.  
  2316.  
  2317.         BITWISE LOGICAL FUNCTIONS
  2318.  
  2319.         (logand <expr>...)  THE BITWISE AND OF A LIST OF NUMBERS
  2320.             <expr>      the numbers
  2321.             returns     the result of the and operation
  2322.  
  2323.         (logior <expr>...)  THE BITWISE INCLUSIVE OR OF A LIST OF NUMBERS
  2324.             <expr>      the numbers
  2325.             returns     the result of the inclusive or operation
  2326.  
  2327.         (logxor <expr>...)  THE BITWISE EXCLUSIVE OR OF A LIST OF NUMBERS
  2328.             <expr>      the numbers
  2329.             returns     the result of the exclusive or operation
  2330.  
  2331.         (lognot <expr>)  THE BITWISE NOT OF A NUMBER
  2332.             <expr>      the number
  2333.             returns     the bitwise inversion of number
  2334.  
  2335.  
  2336.  
  2337.  
  2338.  
  2339.  
  2340.  
  2341.  
  2342.  
  2343.  
  2344.  
  2345.  
  2346.  
  2347.  
  2348.  
  2349.  
  2350.  
  2351.  
  2352.  
  2353.  
  2354.  
  2355.  
  2356.  
  2357.  
  2358.  
  2359.  
  2360.  
  2361.  
  2362.  
  2363.  
  2364.  
  2365.  
  2366.  
  2367.  
  2368.  
  2369.  
  2370.  
  2371.  
  2372.  
  2373.  
  2374.  
  2375.  
  2376.  
  2377.  
  2378.  
  2379.  
  2380.         XLISP                   STRING FUNCTIONS                 Page 37
  2381.  
  2382.  
  2383.         STRING FUNCTIONS
  2384.  
  2385.         (string <expr>)  MAKE A STRING FROM AN INTEGER ASCII VALUE
  2386.             <expr>      the integer
  2387.             returns     a one character string
  2388.  
  2389.         (string-trim <bag> <str>)  TRIM BOTH ENDS OF A STRING
  2390.             <bag>       a string containing characters to trim
  2391.             <str>       the string to trim
  2392.             returns     a trimed copy of the string
  2393.  
  2394.         (string-left-trim <bag> <str>)  TRIM THE LEFT END OF A STRING
  2395.             <bag>       a string containing characters to trim
  2396.             <str>       the string to trim
  2397.             returns     a trimed copy of the string
  2398.  
  2399.         (string-right-trim <bag> <str>)  TRIM THE RIGHT END OF A STRING
  2400.             <bag>       a string containing characters to trim
  2401.             <str>       the string to trim
  2402.             returns     a trimed copy of the string
  2403.  
  2404.         (string-upcase <str> &key :start :end)  CONVERT TO UPPERCASE
  2405.             <str>       the string
  2406.             :start      the starting offset
  2407.             :end        the ending offset + 1
  2408.             returns     a converted copy of the string
  2409.  
  2410.         (string-downcase <str> &key :start :end)  CONVERT TO LOWERCASE
  2411.             <str>       the string
  2412.             :start      the starting offset
  2413.             :end        the ending offset + 1
  2414.             returns     a converted copy of the string
  2415.  
  2416.         (nstring-upcase <str> &key :start :end)  CONVERT TO UPPERCASE
  2417.             <str>       the string
  2418.             :start      the starting offset
  2419.             :end        the ending offset + 1
  2420.             returns     the converted string (not a copy)
  2421.  
  2422.         (nstring-downcase <str> &key :start :end)  CONVERT TO LOWERCASE
  2423.             <str>       the string
  2424.             :start      the starting offset
  2425.             :end        the ending offset + 1
  2426.             returns     the converted string (not a copy)
  2427.  
  2428.         (strcat <expr>...)  CONCATENATE STRINGS
  2429.             <expr>      the strings to concatenate
  2430.             returns     the result of concatenating the strings
  2431.  
  2432.         (subseq <string> <start> [<end>]) EXTRACT A SUBSTRING
  2433.             <string>    the string
  2434.             <start>     the starting position (zero origin)
  2435.             <end>       the ending position + 1 (defaults to end)
  2436.             returns     substring between <start> and <end>
  2437.  
  2438.  
  2439.  
  2440.  
  2441.  
  2442.  
  2443.  
  2444.  
  2445.  
  2446.         XLISP                   STRING FUNCTIONS                 Page 38
  2447.  
  2448.  
  2449.         (string< <str1> <str2> &key :start1 :end1 :start2 :end2)
  2450.         (string<= <str1> <str2> &key :start1 :end1 :start2 :end2)
  2451.         (string= <str1> <str2> &key :start1 :end1 :start2 :end2)
  2452.         (string/= <str1> <str2> &key :start1 :end1 :start2 :end2)
  2453.         (string>= <str1> <str2> &key :start1 :end1 :start2 :end2)
  2454.         (string> <str1> <str2> &key :start1 :end1 :start2 :end2)
  2455.             <str1>      the first string to compare
  2456.             <str2>      the second string to compare
  2457.             :start1     first substring starting offset
  2458.             :end1       first substring ending offset + 1
  2459.             :start2     second substring starting offset
  2460.             :end2       second substring ending offset + 1
  2461.             returns     t if predicate is true, nil otherwise
  2462.           Note: case is significant with these comparison functions.
  2463.  
  2464.         (string-lessp <str1> <str2> &key :start1 :end1 :start2 :end2)
  2465.         (string-not-greaterp <str1> <str2> &key :start1 :end1 :start2 :end2)
  2466.         (string-equalp <str1> <str2> &key :start1 :end1 :start2 :end2)
  2467.         (string-not-equalp <str1> <str2> &key :start1 :end1 :start2 :end2)
  2468.         (string-not-lessp <str1> <str2> &key :start1 :end1 :start2 :end2)
  2469.         (string-greaterp <str1> <str2> &key :start1 :end1 :start2 :end2)
  2470.             <str1>      the first string to compare
  2471.             <str2>      the second string to compare
  2472.             :start1     first substring starting offset
  2473.             :end1       first substring ending offset + 1
  2474.             :start2     second substring starting offset
  2475.             :end2       second substring ending offset + 1
  2476.             returns     t if predicate is true, nil otherwise
  2477.           Note: case is not significant with these comparison functions.
  2478.  
  2479.  
  2480.  
  2481.  
  2482.  
  2483.  
  2484.  
  2485.  
  2486.  
  2487.  
  2488.  
  2489.  
  2490.  
  2491.  
  2492.  
  2493.  
  2494.  
  2495.  
  2496.  
  2497.  
  2498.  
  2499.  
  2500.  
  2501.  
  2502.  
  2503.  
  2504.  
  2505.  
  2506.  
  2507.  
  2508.  
  2509.  
  2510.  
  2511.  
  2512.         XLISP                 CHARACTER FUNCTIONS                Page 39
  2513.  
  2514.  
  2515.         CHARACTER FUNCTIONS
  2516.  
  2517.         (char <string> <index>)  EXTRACT A CHARACTER FROM A STRING
  2518.             <string>    the string
  2519.             <index>     the string index (zero relative)
  2520.             returns     the ascii code of the character
  2521.  
  2522.         (upper-case-p <chr>)  IS THIS AN UPPER CASE CHARACTER?
  2523.             <chr>       the character
  2524.             returns     true if the character is upper case, nil otherwise
  2525.  
  2526.         (lower-case-p <chr>)  IS THIS A LOWER CASE CHARACTER?
  2527.             <chr>       the character
  2528.             returns     true if the character is lower case, nil otherwise
  2529.  
  2530.         (both-case-p <chr>)  IS THIS AN ALPHABETIC (EITHER CASE) CHARACTER?
  2531.             <chr>       the character
  2532.             returns     true if the character is alphabetic, nil otherwise
  2533.  
  2534.         (digit-char-p <chr>)  IS THIS A DIGIT CHARACTER?
  2535.             <chr>       the character
  2536.             returns     the digit weight if character is a digit, nil otherwise
  2537.  
  2538.         (char-code <chr>)  GET THE ASCII CODE OF A CHARACTER
  2539.             <chr>       the character
  2540.             returns     the ASCII character code (integer)
  2541.  
  2542.         (code-char <code>)  GET THE CHARACTER WITH A SPECFIED ASCII CODE
  2543.             <code>      the ASCII code (integer)
  2544.             returns     the character with that code or nil
  2545.  
  2546.         (char-upcase <chr>)  CONVERT A CHARACTER TO UPPER CASE
  2547.             <chr>       the character
  2548.             returns     the upper case character
  2549.  
  2550.         (char-downcase <chr>)  CONVERT A CHARACTER TO LOWER CASE
  2551.             <chr>       the character
  2552.             returns     the lower case character
  2553.  
  2554.         (digit-char <n>)  CONVERT A DIGIT WEIGHT TO A DIGIT
  2555.             <n>         the digit weight (integer)
  2556.             returns     the digit character or nil
  2557.  
  2558.         (char-int <chr>) CONVERT A CHARACTER TO AN INTEGER
  2559.             <chr>       the character
  2560.             returns     the ASCII character code
  2561.  
  2562.         (int-char <int>) CONVERT AN INTEGER TO A CHARACTER
  2563.             <int>       the ASCII character code
  2564.             returns     the character with that code
  2565.  
  2566.  
  2567.  
  2568.  
  2569.  
  2570.  
  2571.  
  2572.  
  2573.  
  2574.  
  2575.  
  2576.  
  2577.  
  2578.         XLISP                 CHARACTER FUNCTIONS                Page 40
  2579.  
  2580.  
  2581.         (char< <chr1> <chr2>...)
  2582.         (char<= <chr1> <chr2>...)
  2583.         (char= <chr1> <chr2>...)
  2584.         (char/= <chr1> <chr2>...)
  2585.         (char>= <chr1> <chr2>...)
  2586.         (char> <chr1> <chr2>...)
  2587.             <chr1>      the first character to compare
  2588.             <chr2>      the second character(s) to compare
  2589.             returns     t if predicate is true, nil otherwise
  2590.           Note: case is significant with these comparison functions.
  2591.  
  2592.         (char-lessp <chr1> <chr2>...)
  2593.         (char-not-greaterp <chr1> <chr2>...)
  2594.         (char-equalp <chr1> <chr2>...)
  2595.         (char-not-equalp <chr1> <chr2>...)
  2596.         (char-not-lessp <chr1> <chr2>...)
  2597.         (char-greaterp <chr1> <chr2>...)
  2598.             <chr1>      the first string to compare
  2599.             <chr2>      the second string(s) to compare
  2600.             returns     t if predicate is true, nil otherwise
  2601.           Note: case is not significant with these comparison functions.
  2602.  
  2603.  
  2604.  
  2605.  
  2606.  
  2607.  
  2608.  
  2609.  
  2610.  
  2611.  
  2612.  
  2613.  
  2614.  
  2615.  
  2616.  
  2617.  
  2618.  
  2619.  
  2620.  
  2621.  
  2622.  
  2623.  
  2624.  
  2625.  
  2626.  
  2627.  
  2628.  
  2629.  
  2630.  
  2631.  
  2632.  
  2633.  
  2634.  
  2635.  
  2636.  
  2637.  
  2638.  
  2639.  
  2640.  
  2641.  
  2642.  
  2643.  
  2644.         XLISP                INPUT/OUTPUT FUNCTIONS              Page 41
  2645.  
  2646.  
  2647.         INPUT/OUTPUT FUNCTIONS
  2648.  
  2649.         (read [<stream> [<eof> [<rflag>]]])  READ AN EXPRESSION
  2650.             <stream>    the input stream (default is standard input)
  2651.             <eof>       the value to return on end of file (default is nil)
  2652.             <rflag>     recursive read flag (default is nil)
  2653.             returns     the expression read
  2654.  
  2655.         (print <expr> [<stream>])  PRINT AN EXPRESSION ON A NEW LINE
  2656.             <expr>      the expression to be printed
  2657.             <stream>    the output stream (default is standard output)
  2658.             returns     the expression
  2659.  
  2660.         (prin1 <expr> [<stream>])  PRINT AN EXPRESSION
  2661.             <expr>      the expression to be printed
  2662.             <stream>    the output stream (default is standard output)
  2663.             returns     the expression
  2664.  
  2665.         (princ <expr> [<stream>])  PRINT AN EXPRESSION WITHOUT QUOTING
  2666.             <expr>      the expressions to be printed
  2667.             <stream>    the output stream (default is standard output)
  2668.             returns     the expression
  2669.  
  2670.         (pprint <expr> [<stream>])  PRETTY PRINT AN EXPRESSION
  2671.             <expr>      the expressions to be printed
  2672.             <stream>    the output stream (default is standard output)
  2673.             returns     the expression
  2674.  
  2675.         (terpri [<stream>])  TERMINATE THE CURRENT PRINT LINE
  2676.             <stream>    the output stream (default is standard output)
  2677.             returns     nil
  2678.  
  2679.         (flatsize <expr>)  LENGTH OF PRINTED REPRESENTATION USING PRIN1
  2680.             <expr>      the expression
  2681.             returns     the length
  2682.  
  2683.         (flatc <expr>)  LENGTH OF PRINTED REPRESENTATION USING PRINC
  2684.             <expr>      the expression
  2685.             returns     the length
  2686.  
  2687.  
  2688.  
  2689.  
  2690.  
  2691.  
  2692.  
  2693.  
  2694.  
  2695.  
  2696.  
  2697.  
  2698.  
  2699.  
  2700.  
  2701.  
  2702.  
  2703.  
  2704.  
  2705.  
  2706.  
  2707.  
  2708.  
  2709.  
  2710.         XLISP                 THE FORMAT FUNCTION                Page 42
  2711.  
  2712.  
  2713.         THE FORMAT FUNCTION
  2714.  
  2715.         (format <stream> <fmt> <arg>...)  DO FORMATTED OUTPUT
  2716.             <stream>    the output stream
  2717.             <fmt>       the format string
  2718.             <arg>       the format arguments
  2719.             returns     output string if <stream> is nil, nil otherwise
  2720.  
  2721.         The format string can contain characters that should be copied
  2722.         directly to the output and formatting directives.  The
  2723.         formatting directives are:
  2724.  
  2725.             ~A          print next argument using princ
  2726.             ~S          print next argument using prin1
  2727.             ~%          start a new line
  2728.             ~~          print a tilde character
  2729.  
  2730.  
  2731.  
  2732.  
  2733.  
  2734.  
  2735.  
  2736.  
  2737.  
  2738.  
  2739.  
  2740.  
  2741.  
  2742.  
  2743.  
  2744.  
  2745.  
  2746.  
  2747.  
  2748.  
  2749.  
  2750.  
  2751.  
  2752.  
  2753.  
  2754.  
  2755.  
  2756.  
  2757.  
  2758.  
  2759.  
  2760.  
  2761.  
  2762.  
  2763.  
  2764.  
  2765.  
  2766.  
  2767.  
  2768.  
  2769.  
  2770.  
  2771.  
  2772.  
  2773.  
  2774.  
  2775.  
  2776.         XLISP                  FILE I/O FUNCTIONS                Page 43
  2777.  
  2778.  
  2779.         FILE I/O FUNCTIONS
  2780.  
  2781.         (open <fname> &key :direction)  OPEN A FILE STREAM
  2782.             <fname>     the file name string or symbol
  2783.             :direction  :input or :output (default is :input)
  2784.             returns     a stream
  2785.  
  2786.         (close <stream>)  CLOSE A FILE STREAM
  2787.             <stream>    the stream
  2788.             returns     nil
  2789.  
  2790.         (read-char [<stream>])  READ A CHARACTER FROM A STREAM
  2791.             <stream>    the input stream (default is standard input)
  2792.             returns     the character
  2793.  
  2794.         (peek-char [<flag> [<stream>]])  PEEK AT THE NEXT CHARACTER
  2795.             <flag>      flag for skipping white space (default is nil)
  2796.             <stream>    the input stream (default is standard input)
  2797.             returns     the character (integer)
  2798.  
  2799.         (write-char <ch> [<stream>])  WRITE A CHARACTER TO A STREAM
  2800.             <ch>        the character to write
  2801.             <stream>    the output stream (default is standard output)
  2802.             returns     the character
  2803.  
  2804.         (read-line [<stream>])  READ A LINE FROM A STREAM
  2805.             <stream>    the input stream (default is standard input)
  2806.             returns     the string
  2807.  
  2808.         (read-byte [<stream>])  READ A BYTE FROM A STREAM
  2809.             <stream>    the input stream (default is standard input)
  2810.             returns     the byte (integer)
  2811.  
  2812.         (write-byte <byte> [<stream>])  WRITE A BYTE TO A STREAM
  2813.             <byte>      the byte to write (integer)
  2814.             <stream>    the output stream (default is standard output)
  2815.             returns     the byte (integer)
  2816.  
  2817.  
  2818.  
  2819.  
  2820.  
  2821.  
  2822.  
  2823.  
  2824.  
  2825.  
  2826.  
  2827.  
  2828.  
  2829.  
  2830.  
  2831.  
  2832.  
  2833.  
  2834.  
  2835.  
  2836.  
  2837.  
  2838.  
  2839.  
  2840.  
  2841.  
  2842.         XLISP               STRING STREAM FUNCTIONS              Page 44
  2843.  
  2844.  
  2845.         STRING STREAM FUNCTIONS
  2846.  
  2847.         These functions operate on unnamed streams.  An unnamed output
  2848.         stream collects characters sent to it when it is used as the
  2849.         destination of any output function.  The functions 'get-output-
  2850.         stream-string' and string or a list of characters.
  2851.  
  2852.         An unnamed input stream is setup with the 'make-string-input-
  2853.         stream' function and returns each character of the string when
  2854.         it is used as the source of any input function.
  2855.  
  2856.         (make-string-input-stream <str> [<start> [<end>]])
  2857.             <str>       the string
  2858.             <start>     the starting offset
  2859.             <end>       the ending offset + 1
  2860.             returns     an unnamed stream that reads from the string
  2861.  
  2862.         (make-string-output-stream)
  2863.             returns     an unnamed output stream
  2864.  
  2865.         (get-output-stream-string <stream>)
  2866.             <stream>    the output stream
  2867.             returns     the output so far as a string
  2868.           Note:  the output stream is emptied by this function
  2869.  
  2870.         (get-output-stream-list <stream>)
  2871.             <stream>    the output stream
  2872.             returns     the output so far as a list
  2873.           Note:  the output stream is emptied by this function
  2874.  
  2875.  
  2876.  
  2877.  
  2878.  
  2879.  
  2880.  
  2881.  
  2882.  
  2883.  
  2884.  
  2885.  
  2886.  
  2887.  
  2888.  
  2889.  
  2890.  
  2891.  
  2892.  
  2893.  
  2894.  
  2895.  
  2896.  
  2897.  
  2898.  
  2899.  
  2900.  
  2901.  
  2902.  
  2903.  
  2904.  
  2905.  
  2906.  
  2907.  
  2908.         XLISP                   SYSTEM FUNCTIONS                 Page 45
  2909.  
  2910.  
  2911.         SYSTEM FUNCTIONS
  2912.  
  2913.         (load <fname> &key :verbose :print)  LOAD A SOURCE FILE
  2914.             <fname>     the filename string or symbol
  2915.             :verbose    the verbose flag (default is t)
  2916.             :print      the print flag (default is nil)
  2917.             returns     the filename
  2918.  
  2919.         (save <fname>) SAVE WORKSPACE TO A FILE
  2920.             <fname>     the filename string or symbol
  2921.             returns     t if workspace was written, nil otherwise
  2922.  
  2923.         (restore <fname>) RESTORE WORKSPACE FROM A FILE
  2924.             <fname>     the filename string or symbol
  2925.             returns     nil on failure, otherwise never returns
  2926.  
  2927.         (dribble [<fname>])  CREATE A FILE WITH A TRANSCRIPT OF A SESSION
  2928.             <fname>     file name string or symbol
  2929.                         (if missing, close current transcript)
  2930.             returns     t if the transcript is opened, nil if it is closed
  2931.  
  2932.         (gc)  FORCE GARBAGE COLLECTION
  2933.             returns     nil
  2934.  
  2935.         (expand <num>)  EXPAND MEMORY BY ADDING SEGMENTS
  2936.             <num>       the number of segments to add
  2937.             returns     the number of segments added
  2938.  
  2939.         (alloc <num>)  CHANGE NUMBER OF NODES TO ALLOCATE IN EACH SEGMENT
  2940.             <num>       the number of nodes to allocate
  2941.             returns     the old number of nodes to allocate
  2942.  
  2943.         (room)  SHOW MEMORY ALLOCATION STATISTICS
  2944.             returns     nil
  2945.  
  2946.         (type-of <expr>)  RETURNS THE TYPE OF THE EXPRESSION
  2947.             <expr>      the expression to return the type of
  2948.             returns     nil if the value is nil otherwise one of the symbols:
  2949.                           SYMBOL          for symbols
  2950.                           OBJECT          for objects
  2951.                           CONS            for conses
  2952.                           SUBR            for built-in functions
  2953.                           FSUBR           for special forms
  2954.                           CLOSURE         for defined functions
  2955.                           STRING          for strings
  2956.                           FIXNUM          for integers
  2957.                           FLONUM          for floating point numbers
  2958.                           CHARACTER       for characters
  2959.                           FILE-STREAM     for file pointers
  2960.                           UNNAMED-STREAM  for unnamed streams
  2961.                           ARRAY           for arrays
  2962.  
  2963.  
  2964.  
  2965.  
  2966.  
  2967.  
  2968.  
  2969.  
  2970.  
  2971.  
  2972.  
  2973.  
  2974.         XLISP                   SYSTEM FUNCTIONS                 Page 46
  2975.  
  2976.  
  2977.         (peek <addrs>)  PEEK AT A LOCATION IN MEMORY
  2978.             <addrs>     the address to peek at (integer)
  2979.             returns     the value at the specified address (integer)
  2980.  
  2981.         (poke <addrs> <value>)  POKE A VALUE INTO MEMORY
  2982.             <addrs>     the address to poke (integer)
  2983.             <value>     the value to poke into the address (integer)
  2984.             returns     the value
  2985.  
  2986.         (address-of <expr>)  GET THE ADDRESS OF AN XLISP NODE
  2987.             <expr>      the node
  2988.             returns     the address of the node (integer)
  2989.  
  2990.         (exit)  EXIT XLISP
  2991.             returns     never returns
  2992.  
  2993.  
  2994.  
  2995.  
  2996.  
  2997.  
  2998.  
  2999.  
  3000.  
  3001.  
  3002.  
  3003.  
  3004.  
  3005.  
  3006.  
  3007.  
  3008.  
  3009.  
  3010.  
  3011.  
  3012.  
  3013.  
  3014.  
  3015.  
  3016.  
  3017.  
  3018.  
  3019.  
  3020.  
  3021.  
  3022.  
  3023.  
  3024.  
  3025.  
  3026.  
  3027.  
  3028.  
  3029.  
  3030.  
  3031.  
  3032.  
  3033.  
  3034.  
  3035.  
  3036.  
  3037.  
  3038.  
  3039.  
  3040.         XLISP                       EXAMPLES                     Page 47
  3041.  
  3042.  
  3043.         FILE I/O FUNCTIONS
  3044.  
  3045.         Input from a File
  3046.  
  3047.         To open a file for input, use the OPEN function with the keyword
  3048.         argument :DIRECTION set to :INPUT.  To open a file for output,
  3049.         use the OPEN function with the keyword argument :DIRECTION set
  3050.         to :OUTPUT.  The OPEN function takes a single required argument
  3051.         which is the name of the file to be opened.  This name can be in
  3052.         the form of a string or a symbol.  The OPEN function returns an
  3053.         object of type FILE-STREAM if it succeeds in opening the
  3054.         specified file.  It returns the value NIL if it fails.  In order
  3055.         to manipulate the file, it is necessary to save the value
  3056.         returned by the OPEN function.  This is usually done by
  3057.         assigning it to a variable with the SETQ special form or by
  3058.         binding it using LET or LET*.  Here is an example:
  3059.  
  3060.             (setq fp (open "init.lsp" :direction :input))
  3061.  
  3062.         Evaluating this expression will result in the file "init.lsp"
  3063.         being opened.  The file object that will be returned by the OPEN
  3064.         function will be assigned to the variable "fp".
  3065.  
  3066.         It is now possible to use the file for input.  To read an
  3067.         expression from the file, just supply the value of the "fp"
  3068.         variable as the optional "stream" argument to READ.
  3069.  
  3070.             (read fp)
  3071.  
  3072.         Evaluating this expression will result in reading the first
  3073.         expression from the file "init.lsp".  The expression will be
  3074.         returned as the result of the READ function.  More expressions
  3075.         can be read from the file using further calls to the READ
  3076.         function.  When there are no more expressions to read, the READ
  3077.         function will return NIL (or whatever value was supplied as the
  3078.         second argument to READ).
  3079.  
  3080.         Once you are done reading from the file, you should close it.
  3081.         To close the file, use the following expression:
  3082.  
  3083.             (close fp)
  3084.  
  3085.         Evaluating this expression will cause the file to be closed.
  3086.  
  3087.  
  3088.  
  3089.  
  3090.  
  3091.  
  3092.  
  3093.  
  3094.  
  3095.  
  3096.  
  3097.  
  3098.  
  3099.  
  3100.  
  3101.  
  3102.  
  3103.  
  3104.  
  3105.  
  3106.         XLISP                       EXAMPLES                     Page 48
  3107.  
  3108.  
  3109.         Output to a File
  3110.  
  3111.         Writing to a file is pretty much the same as reading from one.
  3112.         You need to open the file first.  This time you should use the
  3113.         OPEN function to indicate that you will do output to the file.
  3114.         For example:
  3115.  
  3116.             (setq fp (open "test.dat" :direction :output))
  3117.  
  3118.         Evaluating this expression will open the file "test.dat" for
  3119.         output.  If the file already exists, its current contents will
  3120.         be discarded.  If it doesn't already exist, it will be created.
  3121.         In any case, a FILE-STREAM object will be returned by the OPEN
  3122.         function.  This file object will be assigned to the "fp"
  3123.         variable.
  3124.  
  3125.         It is now possible to write to this file by supplying the value
  3126.         of the "fp" variable as the optional "stream" parameter in the
  3127.         PRINT function.
  3128.  
  3129.             (print "Hello there" fp)
  3130.  
  3131.         Evaluating this expression will result in the string "Hello
  3132.         there" being written to the file "test.dat".  More data can be
  3133.         written to the file using the same technique.
  3134.  
  3135.         Once you are done writing to the file, you should close it.
  3136.         Closing an output file is just like closing an input file.
  3137.  
  3138.             (close fp)
  3139.  
  3140.         Evaluating this expression will close the output file and make
  3141.         it permanent.
  3142.  
  3143.  
  3144.  
  3145.  
  3146.  
  3147.  
  3148.  
  3149.  
  3150.  
  3151.  
  3152.  
  3153.  
  3154.  
  3155.  
  3156.  
  3157.  
  3158.  
  3159.  
  3160.  
  3161.  
  3162.  
  3163.  
  3164.  
  3165.  
  3166.  
  3167.  
  3168.  
  3169.  
  3170.  
  3171.  
  3172.         XLISP                       EXAMPLES                     Page 49
  3173.  
  3174.  
  3175.         A Slightly More Complicated File Example
  3176.  
  3177.         This example shows how to open a file, read each Lisp expression
  3178.         from the file and print it.  It demonstrates the use of files
  3179.         and the use of the optional "stream" argument to the READ
  3180.         function.
  3181.  
  3182.             (do* ((fp (open "test.dat" :direction :input))
  3183.                   (ex (read fp) (read fp)))
  3184.                  ((null ex) nil)
  3185.               (print ex))
  3186.  
  3187.  
  3188.  
  3189.  
  3190.  
  3191.  
  3192.  
  3193.  
  3194.  
  3195.  
  3196.  
  3197.  
  3198.  
  3199.  
  3200.  
  3201.  
  3202.  
  3203.  
  3204.  
  3205.  
  3206.  
  3207.  
  3208.  
  3209.  
  3210.  
  3211.  
  3212.  
  3213.  
  3214.  
  3215.  
  3216.  
  3217.  
  3218.  
  3219.  
  3220.  
  3221.  
  3222.  
  3223.  
  3224.  
  3225.  
  3226.  
  3227.  
  3228.  
  3229.  
  3230.  
  3231.  
  3232.  
  3233.  
  3234.  
  3235.