home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / LISP / PDLISP.ZIP / MANUAL1.DOC < prev    next >
Encoding:
Text File  |  1986-08-13  |  204.1 KB  |  9,188 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.                           Cybermetrics PDLISP Language Manual
  36.  
  37.  
  38.                               Author: Dave Morein
  39.  
  40.  
  41.                           Document Version: 1.10
  42.                           Release Date:     August 11, 1986
  43.  
  44.  
  45.                           Copyright (c) 1985, 1986 by Cybermetrics
  46.                           All rights reserved, worldwide.
  47.  
  48.  
  49.                           Published by
  50.  
  51.                           Cybermetrics
  52.                           P.O. Box 1194
  53.                           Los Gatos, California 95031
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.                           TRADEMARK ACKNOWLEDGMENTS:
  94.  
  95.                  MS-DOS is a trademark of Microsoft, Inc.
  96.                  UNIX is a trademark of ATT Bell Laboratories
  97.                  Intel is a trademark of Intel Corporation
  98.                  IBM and PC-DOS are trademarks of
  99.                    International Business Machines, Inc.
  100.  
  101.                  All other product names are trademarks of their
  102.                  associated manufacturers/publishers.
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.  
  141.  
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  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.  
  203.  
  204.  
  205.  
  206.  
  207.  
  208.  
  209.  
  210.  
  211.  
  212.  
  213.  
  214.  
  215.  
  216.  
  217.  
  218.  
  219.  
  220.  
  221.  
  222.  
  223.  
  224.                     About PDLISP, UNXLISP and Cybermetrics
  225.  
  226.           PDLISP  and UNXLISP are products which I developed over  the
  227.           period of time from  1981 to the present.  I am distributing
  228.           binary  copies  of  PDLISP  for free through bulletin  board
  229.           systems  (BBS's)  to  people who are interested in  learning
  230.           about LISP and artificial intelligence programming.  UNXLISP
  231.           is a commercial product,  which I distribute through several
  232.           dealers who are listed in the  appendix to the manual called
  233.           "product support." 
  234.  
  235.             At the  present time (August, 1986) both products are in a
  236.           state of flux.  PDLISP is distributed with a  manual  on  an
  237.           MS-DOS disk.  UNXLISP is distributed with a printed  manual,
  238.           and  contains some features which PDLISP does not.  Most  of
  239.           these  features  are  still  a month or two away from  being
  240.           released.  However, I provide free updates to purchasers  of
  241.           the commercial product. 
  242.  
  243.             While neither product is  "Common  LISP" compatible at the
  244.           present  time,  I  am  working  hard  in this direction.  By
  245.           sometime  in  1987, I hope  to  have  achieved  Common  LISP
  246.           compatibility with UNXLISP. Free updates, of course, will be
  247.           provided to all of my early customers. 
  248.  
  249.             Anyone is free to copy this diskette as long as it is for
  250.           personal use, and not commercial, and as long as it is not
  251.           altered and all copyright messages are preserved.
  252.  
  253.             I am distributing PDLISP even though it is not my "primary
  254.           income generating activity."   In  other  words, I'm doing
  255.           it for fun.  My hope is  that others will see them in the same
  256.           light. 
  257.  
  258.             - Dave Morein
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.  
  272.  
  273.  
  274.  
  275.  
  276.  
  277.  
  278.  
  279.  
  280.  
  281.  
  282.  
  283.  
  284.  
  285.  
  286.  
  287.  
  288.  
  289.  
  290.  
  291.  
  292.  
  293.  
  294.  
  295.  
  296.  
  297.  
  298.  
  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.  
  335.  
  336.  
  337.  
  338.  
  339.  
  340.  
  341.  
  342.  
  343.  
  344.  
  345.  
  346.  
  347.  
  348.           PDLISP language manual An Overview of LISP
  349.           
  350.  
  351.  
  352.  
  353.  
  354.  
  355.  
  356.  
  357.  
  358.  
  359.                                     Chapter 1
  360.  
  361.                                An Overview of LISP
  362.  
  363.  
  364.  
  365.           LISP  is  a  language  intended   primarily   for   symbolic
  366.           manipulation.  It has been used for programming solutions to
  367.           problems in computer science, the integral calculus, circuit
  368.           theory,  mathematical  logic,  question-answering   systems,
  369.           game-playing, and other fields  of  artificial  intelligence
  370.           research.  LISP's versatility  is  probably unmatched in the
  371.           field of programming languages. 
  372.  
  373.             LISP differs radically from most other  computer languages
  374.           in two main respects.  First, data is stored in LISP in what
  375.           are  known as symbolic  expressions,  or  S-expressions  for
  376.           short.    S-expressions  are,  abstractly,   tree-structured
  377.           constructs  of variable length.  In LISP, S-expressions  are
  378.           allocated automatically, so  that  the  programmer  is freed
  379.           from the necessity of  manually  organizing  storage for his
  380.           variables.   Secondly,  in  LISP  there  is  no  distinction
  381.           between   programs   and  data.   LISP  programs  are   just
  382.           S-expressions which the user  has specified to be executed. 
  383.           LISP programs can even produce programs in the  form of data
  384.           to be executed. 
  385.  
  386.           
  387.  
  388.  
  389.  
  390.  
  391.           1.1 Symbolic Expressions
  392.  
  393.  
  394.             Symbolic  Expressions  can  exist  in  PDLISP in  several
  395.           forms,  including  atoms  and  lists.  Atoms  are  the  most
  396.           primitive unit of data, corresponding to "words" in English.
  397.           Lists   are   more  abstract   groups   of   data,   roughly
  398.           corresponding to "sentences" in  English.  They  are used to
  399.           group  data to make it more  convenient  to  manipulate  and
  400.           interpret it. 
  401.  
  402.           
  403.  
  404.  
  405.  
  406.                                       - 1 -               Version 1.10
  407.           
  408.  
  409.  
  410.  
  411.  
  412.  
  413.  
  414.           PDLISP language manual                  An Overview of LISP
  415.           
  416.  
  417.  
  418.  
  419.  
  420.  
  421.           1.1.1 Atoms and Lists
  422.  
  423.           As an initial definition, atoms in PDLISP are  sequences of
  424.           indefinite  length  composed  of  letters, digits, or a  few
  425.           other characters but not beginning  with  a  digit.   A more
  426.           precise  definition  is  given in the section entitled  "The
  427.           PDLISP Reader".
  428.  
  429.             For example, the following are legal atoms in PDLISP:
  430.  
  431.  
  432.                    A
  433.                    Thisisalongatom
  434.                    Thisisaverylongatom
  435.                    Thisisanevenlongeratom
  436.                    someatomsaretalented
  437.                    THX1138
  438.  
  439.           The following are not legal atoms in PDLISP:
  440.  
  441.  
  442.           234a                       -   (does not begin with a letter)
  443.           This is not an atom        -   (contains imbedded spaces)
  444.           "I am not a legal string.  -   (no closing quote)
  445.  
  446.  
  447.           1.1.2 Reserved Words
  448.  
  449.           The following is a list of all  of  the  reserved  words  in
  450.           PDLISP. Any attempt to use one of these words as an  atomic
  451.           name will probably result in an error. 
  452.  
  453.  
  454.               BLOCK           LEXPR           T
  455.               CDQ             MACRO           TAGBODY
  456.               CNSUBR          MCDQ            UNBOUND
  457.               CSUBR           NIL             VAR
  458.               DEXPR           NLAMBDA         -
  459.               FIN             NSUBR           +
  460.               GLOBAL          PUTD            &AUX
  461.               LAMBDA          QUOTE           &OPTIONAL
  462.               LET             SUBR            &REST
  463.               LET*            SETQQ
  464.  
  465.  
  466.  
  467.  
  468.  
  469.  
  470.  
  471.  
  472.                                       - 2 -               Version 1.10
  473.           
  474.  
  475.  
  476.  
  477.  
  478.  
  479.  
  480.           PDLISP language manual                  An Overview of LISP
  481.           
  482.  
  483.  
  484.  
  485.  
  486.  
  487.           1.1.3 Numbers
  488.  
  489.           PDLISP  currently  supports  fixed  point  ("integer")  and
  490.           floating point ("float") numbers.  Floats carry can be input
  491.           either  in  ordinary  format (e.g., 423.7) or in  scientific
  492.           notation (e.g., 4.237E2). The  following  are  legal PDLISP
  493.           floats:
  494.  
  495.  
  496.                3.14159
  497.                6.02E23
  498.                -1.02
  499.                +5.6
  500.                4.29E-5
  501.  
  502.  
  503.           1.1.4 Quoted Strings
  504.  
  505.             Characters besides letters, digits,  and  a few others are
  506.           not ordinarily permitted in  PDLISP  atoms.   They  can  be
  507.           included  with  the  use  of  the  double  quote  mark  ("),
  508.           however.   For  example,  the  following are perfectly  good
  509.           PDLISP atoms:
  510.  
  511.  
  512.                "certain inalienable rights"
  513.                "1962 was a very good year."
  514.                "!#$`|%&'&'(()*:{}[]<>?+`"
  515.  
  516.           Lists are  just  groups  of  atoms which are surrounded by a
  517.           balanced pair of parenthesis and separated by blank spaces. 
  518.  
  519.             Here are some legal lists:
  520.  
  521.  
  522.                (This is a list)
  523.                (Fourscore and seven years ago)
  524.                (Jimmie Ted and Ronnie)
  525.                (some lists are talented)
  526.  
  527.           Here are some illegal (poorly formed) lists:
  528.  
  529.  
  530.                (this one does not have a right parenthesis
  531.                 this one does not have a left parenthesis)
  532.                 this one does not have either
  533.  
  534.  
  535.  
  536.  
  537.  
  538.                                       - 3 -               Version 1.10
  539.           
  540.  
  541.  
  542.  
  543.  
  544.  
  545.  
  546.           PDLISP language manual                  An Overview of LISP
  547.           
  548.  
  549.  
  550.  
  551.  
  552.  
  553.  
  554.  
  555.           1.2 The PDLISP evaluator
  556.  
  557.  
  558.             In high  school  algebra,  most  people are exposed to the
  559.           notion of  a  function.  For  example,  when we write down a
  560.           function named 'f' which adds 4  to  its  argument, we write
  561.           f(x)  =  x  +  4.  Later on, if we should wish to apply this
  562.           function f, we might write, for example, h = f(2). 
  563.  
  564.             Things are similar in PDLISP. We can define functions and
  565.           apply  them  to  arguments  by  enclosing  the  name of  the
  566.           function along with its  arguments  in a set of parenthesis,
  567.           thusly  forming  a list.  For example, if we should wish  to
  568.           apply the function 'f' from the above example to the  number
  569.           2, we would write:
  570.  
  571.  
  572.                (f 2)
  573.  
  574.           The above s-expression constitutes what is known in LISP  as
  575.           a form because it  can be evaluated. Evaluation is performed
  576.           in PDLISP by another function, called eval. Normally,  when
  577.           the user logs  into  PDLISP, the interpreter prints out the
  578.           prompt:
  579.  
  580.  
  581.           /USR/LOGIN->
  582.  
  583.           The above prompt consists of a directory name  which  is the
  584.           "/USR/LOGIN" part, and the right arrow,  which  is  the "->"
  585.           part.   Directories  will be covered in a later chapter, but
  586.           for now, they can safely be ignored. 
  587.  
  588.             The interpreter will wait until the  user types in a valid
  589.           s-expression,  will  then  evaluate  that  expression,   and
  590.           finally print out the result onto the user's  console.  This
  591.           is known as a  READ-EVAL-PRINT  loop.  For example, assuming
  592.           that  the  function  'f'  had  previously  been  defined  as
  593.           described  above  (more  about  that  later), the  following
  594.           dialog might occur:
  595.  
  596.  
  597.  
  598.  
  599.  
  600.  
  601.  
  602.  
  603.  
  604.                                       - 4 -               Version 1.10
  605.           
  606.  
  607.  
  608.  
  609.  
  610.  
  611.  
  612.           PDLISP language manual                  An Overview of LISP
  613.           
  614.  
  615.  
  616.  
  617.  
  618.  
  619.           /USR/LOGIN->(f 2)
  620.           4
  621.           /USR/LOGIN->(f 5)
  622.           7
  623.  
  624.             In  order  to  allow the programmer to document his  code,
  625.           PDLISP ignores  any  input on a line after a semicolon (;).
  626.           For example, we could have typed:
  627.  
  628.  
  629.           /USR/LOGIN->(f 2)       ;invoke f(2)
  630.           4
  631.           /USR/LOGIN->(f 5)       ;invoke f(5)
  632.           7
  633.  
  634.           Each time that the user types in a  list  which  is  a  form
  635.           (meaning that the evaluator  can  evaluate  it),  the system
  636.           will print  out  the  value of the expression which the user
  637.           typed  in,   and   then   an   "/USR/LOGIN->"  prompt.   The
  638.           "/USR/LOGIN->" prompt means that  the evaluator is ready for
  639.           more input.  If the user enters the form  (EXIT),  then  the
  640.           interpreter  will  exit  to  the operating system, as  shown
  641.           below:
  642.  
  643.  
  644.           /USR/LOGIN->(exit)
  645.           %           ;(or some other operating system prompt,
  646.                       ; such as A> on MS-DOS).
  647.  
  648.  
  649.  
  650.  
  651.           1.3 The Pause which Refreshes
  652.  
  653.  
  654.             If you purchased a version of PDLISP which contains  what
  655.           is called a "mark  and  sweep  garbage  collector", then you
  656.           will find that occaisionally, the system pauses and  appears
  657.           to do nothing.  Please be patient ! On a  slow  machine (IBM
  658.           PC), this  function can take six or seven seconds; on a fast
  659.           machine,  (IBM PC-AT), it will take about a  third  of  that
  660.           time.  If you wish, you can  set  things  up so that PDLISP
  661.           beeps  each  time  that  it begins this function.  For  more
  662.           information,  consult  the  section  on  storage  management
  663.           functions. 
  664.  
  665.  
  666.  
  667.  
  668.  
  669.  
  670.                                       - 5 -               Version 1.10
  671.           
  672.  
  673.  
  674.  
  675.  
  676.  
  677.  
  678.           PDLISP language manual                  An Overview of LISP
  679.           
  680.  
  681.  
  682.  
  683.  
  684.  
  685.  
  686.  
  687.           1.4 Assigning Values to Variables
  688.  
  689.  
  690.             Suppose that in the above example where f(x) = x + 2, that
  691.           we  wished to assign a value to the variable  x.   That  is,
  692.           suppose we wish to say,
  693.  
  694.  
  695.                let x = 3
  696.  
  697.           The way in which this would ordinarily be  done  in  PDLISP
  698.           would be through the use of the SETQ function.  For example,
  699.           one might enter the following:
  700.  
  701.  
  702.           /USR/LOGIN->(setq x 3)      ;sets x = 3
  703.           3                           ;Now, we can apply f
  704.           /USR/LOGIN->(f x)           ;to the variable x.
  705.           5                           ;f is as described previously.
  706.  
  707.           A  form  containing  SETQ  is  evaluated just like any other
  708.           form, and it even  returns  a  value  of  5  in  this case. 
  709.           However, unlike  our  function f, it also has a side effect,
  710.           which  is  another  way  of  saying  that it does  something
  711.           besides  returning  a  value.  In this case, SETQ binds  the
  712.           value  3  to  the variable x.  From now on, unless we  apply
  713.           SETQ to x again, x will have a value of  3.  In fact, as the
  714.           following  dialog  with  PDLISP   demonstrates,  x  can  be
  715.           evaluated as a form:
  716.  
  717.  
  718.           /USR/LOGIN->x
  719.           3
  720.  
  721.           Functions can also take more than one argument,  as  in  the
  722.           case of some  function  'g'  of two arguments.  For example,
  723.           let g(x,y) be defined as x + y.  Then  the  following dialog
  724.           might occur:
  725.  
  726.  
  727.  
  728.  
  729.  
  730.  
  731.  
  732.  
  733.  
  734.  
  735.  
  736.                                       - 6 -               Version 1.10
  737.           
  738.  
  739.  
  740.  
  741.  
  742.  
  743.  
  744.           PDLISP language manual                  An Overview of LISP
  745.           
  746.  
  747.  
  748.  
  749.  
  750.  
  751.           /USR/LOGIN->(g 3 2)
  752.           5
  753.           /USR/LOGIN->(setq x 1)
  754.           1
  755.           /USR/LOGIN->(setq y 2)
  756.           2
  757.           /USR/LOGIN->(g x y)
  758.           3
  759.  
  760.           It should be noted that as in the  above examples, a form in
  761.           LISP consists of two parts: a function name and an  argument
  762.           list.  For example, when  the interpreter evaluated the form
  763.           (g x y), g was the function name,  and  x  and y constituted
  764.           the argument list of the form. 
  765.  
  766.             Generally   speaking,   as  in  the  above  examples,  the
  767.           interpreter  (or  the  "evaluator"   for   short)  reads  an
  768.           s-expression from the console, prints out the value  of that
  769.           s-expression,  and  then loops around again, until the  user
  770.           enters invokes the EXIT function as follows:
  771.  
  772.  
  773.           /USR/LOGIN->(exit)
  774.           %                   ;host operating system prompt.
  775.  
  776.             We  are  ready  to   make  what  is  called  a  'recursive
  777.           definition' of  the  term 'symbolic-expression.' A recursive
  778.           definition is a mathematical term for  a definition which is
  779.           expressed in terms of itself.   For example, suppose that we
  780.           wished to describe the set of  all  positive  integers  to a
  781.           stranger from Mars. We could start by saying "0, 1, 2, 3, 4,
  782.           ...",  but  the stranger would surely run  out  of  patience
  783.           before we had enumerated all of  the  positive integers, and
  784.           we might find ourselves getting cooked by a ray gun.  Or  we
  785.           could say the following:
  786.  
  787.  
  788.               (1) "0 is a positive integer"
  789.               (2) "a number is a positive integer if it is equal
  790.                   to the sum of 1 and a positive integer"
  791.               (3) "a number is a positive integer if and only if
  792.                   it is compelled to be one by conditions (1)
  793.                   and (2) stated above."
  794.  
  795.           Given the above definition of a positive  integer,  we could
  796.           write what is called  a  recursive  algorthm  which  decides
  797.           whether or not a  given  number  is  a positive integer.  An
  798.           algorithm is a well-defined procedure of steps which even  a
  799.  
  800.  
  801.  
  802.                                       - 7 -               Version 1.10
  803.           
  804.  
  805.  
  806.  
  807.  
  808.  
  809.  
  810.           PDLISP language manual                  An Overview of LISP
  811.           
  812.  
  813.  
  814.  
  815.           computer can follow which eventually terminates. 
  816.  
  817.  
  818.                In English, here is the algorithm:
  819.  
  820.                step 1: if the number is 0, then stop with a positive
  821.                        integer recognized;
  822.                step 2: if the number is less than 0, then stop with
  823.                        a number which has been determined not to be
  824.                        a positive integer;
  825.                step 3: otherwise, our number is a positive integer
  826.                        if and only if this algorithm determines that
  827.                        the number minus 1 is a positive integer.
  828.                        So, start over again at step 1, with our
  829.                        number diminished by 1.
  830.  
  831.           The  above algorithm is  recursive,  because  if  it  cannot
  832.           immediately determine in step 1 or step 2 whether the number
  833.           is a positive integer, it calls itself with a new argument. 
  834.  
  835.             Likewise,  we  can  give  a  recursive  definition  of   a
  836.           symbolic-expression:
  837.  
  838.  
  839.                (1) An atom is a symbolic expression.
  840.                (2) A list of the form
  841.                    (<s-expr> <s-expr> ... <s-expr>)
  842.                    is a symbolic expression if and only if each of
  843.                    the <s-expr> constructs is a symbolic expression.
  844.                (3) Nothing is a symbolic expression unless it is
  845.                    compelled to be one by (1) and (2) above.
  846.  
  847.           What we are actually saying here is that a string of symbols
  848.           is defined to be a symbolic expression if  and only if it is
  849.           either an atom or a list of symbolic expressions. 
  850.  
  851.  
  852.  
  853.  
  854.  
  855.  
  856.  
  857.  
  858.  
  859.  
  860.  
  861.  
  862.  
  863.  
  864.  
  865.  
  866.  
  867.  
  868.                                       - 8 -               Version 1.10
  869.           
  870.  
  871.  
  872.  
  873.  
  874.  
  875.  
  876.           PDLISP language manual                  An Overview of LISP
  877.           
  878.  
  879.  
  880.  
  881.  
  882.  
  883.  
  884.  
  885.           1.5 Parenthesis Counting
  886.  
  887.  
  888.           PDLISP also  keeps track of how many parenthesis need to be
  889.           matched  in  the  current  expression  being  entered.   For
  890.           example, instead of entering:
  891.  
  892.  
  893.           /USR/LOGIN->(setq a 4)
  894.           4
  895.  
  896.           one  could  have  entered  the same expression on  different
  897.           lines, as in the following:
  898.  
  899.  
  900.           /USR/LOGIN->(
  901.           1 ->setq
  902.           1 -> a
  903.           1 ->4
  904.           1 ->)
  905.           4
  906.  
  907.           The "1 ->" part  of  each line was printed out by PDLISP to
  908.           indicate the number of  right  parenthesis  which  would  be
  909.           necessary  to complete the expression  being  entered.   The
  910.           primary reason for this additional  bit of interaction is to
  911.           prevent us from prematurely concluding that we have  entered
  912.           a  complete  symbolic  expression while the interpreter sits
  913.           waiting for us to finish the  job.   This  feature is called
  914.           parenthesis counting. 
  915.  
  916.  
  917.  
  918.  
  919.  
  920.  
  921.  
  922.  
  923.  
  924.  
  925.  
  926.  
  927.  
  928.  
  929.  
  930.  
  931.  
  932.  
  933.  
  934.                                       - 9 -               Version 1.10
  935.           
  936.  
  937.  
  938.  
  939.  
  940.  
  941.  
  942.           PDLISP language manual                  An Overview of LISP
  943.           
  944.  
  945.  
  946.  
  947.  
  948.                        This page intentionally left blank
  949.  
  950.  
  951.  
  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.  
  995.  
  996.  
  997.  
  998.  
  999.  
  1000.                                      - 10 -               Version 1.10
  1001.           
  1002.  
  1003.  
  1004.  
  1005.  
  1006.  
  1007.  
  1008.           PDLISP language manual                  An Overview of LISP
  1009.           
  1010.  
  1011.  
  1012.  
  1013.  
  1014.                        This page intentionally left blank
  1015.  
  1016.  
  1017.  
  1018.  
  1019.  
  1020.  
  1021.  
  1022.  
  1023.  
  1024.  
  1025.  
  1026.  
  1027.  
  1028.  
  1029.  
  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.  
  1061.  
  1062.  
  1063.  
  1064.  
  1065.  
  1066.                                      - 11 -               Version 1.10
  1067.           
  1068.  
  1069.  
  1070.  
  1071.  
  1072.  
  1073.  
  1074.           PDLISP language manual               Some System Primitives
  1075.           
  1076.  
  1077.  
  1078.  
  1079.  
  1080.  
  1081.  
  1082.  
  1083.  
  1084.  
  1085.                                     Chapter 2
  1086.  
  1087.                              Some System Primitives
  1088.  
  1089.  
  1090.  
  1091.             In this chapter we will examine  a  set of functions which
  1092.           are called primitives because  they  are  supplied  with the
  1093.           PDLISP  interpreter and do not have to be  written  by  the
  1094.           user.   They  constitute the basic 'building blocks' out  of
  1095.           which we will be able to construct useful programs. 
  1096.  
  1097.  
  1098.  
  1099.  
  1100.           2.1 Some Primitive Functions
  1101.  
  1102.  
  1103.           Besides  being able to work with numbers, LISP has a  number
  1104.           of primitive functions designed  to work on the structure of
  1105.           symbolic expressions.  For example, consider a list like
  1106.  
  1107.  
  1108.                (SMALL COMPUTERS ARE FRIENDLY)
  1109.  
  1110.           One might want to pick off the first element  of  the  above
  1111.           list leaving
  1112.  
  1113.  
  1114.                (COMPUTERS ARE FRIENDLY)
  1115.  
  1116.           or  one  might  wish  to add an element to the front of  the
  1117.           list, resulting in the list:
  1118.  
  1119.  
  1120.                (FAST SMALL COMPUTERS ARE FRIENDLY)
  1121.  
  1122.           In  this  section  we  shall examine the built-in  functions
  1123.           provided with PDLISP (and  most  other  LISP  dialects) for
  1124.           doing  such  things.   Their names are strange; Some of  the
  1125.           basic ones are called CAR, CDR, APPEND, LIST,  and  CONS. It
  1126.           may seem that functions  with  names  like  CAR and CDR must
  1127.           have come from another planet.  That is nearly correct; they
  1128.           came from Boston.
  1129.  
  1130.  
  1131.  
  1132.                                      - 12 -               Version 1.10
  1133.           
  1134.  
  1135.  
  1136.  
  1137.  
  1138.  
  1139.  
  1140.           PDLISP language manual               Some System Primitives
  1141.           
  1142.  
  1143.  
  1144.  
  1145.  
  1146.           
  1147.  
  1148.  
  1149.           2.1.1 CAR and CDR
  1150.  
  1151.           CAR  returns  as its value the first element of a list.  For
  1152.           example,  if  we  were  sitting  down at the  computer,  the
  1153.           following dialog could occur:
  1154.  
  1155.  
  1156.           /USR/LOGIN->(car '(small computers are friendly))
  1157.           SMALL
  1158.           /USR/LOGIN->(car '(a little boat plied the seas))
  1159.           A
  1160.  
  1161.           In the following example,  the  argument given to CAR is the
  1162.           two-element list  ((once in a) while).  The first element of
  1163.           this list is also a list, (once in a), and  since  it is the
  1164.           first element of the argument, CAR returns it:
  1165.  
  1166.  
  1167.           /USR/LOGIN->(car '((once in a) while)
  1168.           (ONCE IN A)
  1169.  
  1170.           CDR does exactly the opposite of what CAR  does.  It returns
  1171.           a list containing everything but the first element. 
  1172.  
  1173.  
  1174.           /USR/LOGIN->(cdr '(small computers are capable))
  1175.           (COMPUTERS ARE CAPABLE)
  1176.           /USR/LOGIN->(cdr '(a b c))
  1177.           (B C)
  1178.  
  1179.           One important distinction between  CAR and CDR is that while
  1180.           CAR  may  sometimes  return  an  atom, CDR always returns  a
  1181.           list.  For example, (car '(a b c)) would result in  A, which
  1182.           is an atom, but (cdr '(a  b c)) would result in (B C), which
  1183.           is a list.  CAR extracts the  element  A  from  the argument
  1184.           list,  whereas CDR moves  the  parenthesis  over  the  first
  1185.           element  of  the  list  and  deletes it.  In  fact,  as  the
  1186.           following   conversation   illustrates,   a   very   curious
  1187.           phenomenon  occurs  when  CDR   is  presented  with  certain
  1188.           arguments:
  1189.  
  1190.  
  1191.           /USR/LOGIN->(cdr '(a))
  1192.           NIL
  1193.  
  1194.           What is happening?   Did  we  supply CDR with a list and get
  1195.  
  1196.  
  1197.  
  1198.                                      - 13 -               Version 1.10
  1199.           
  1200.  
  1201.  
  1202.  
  1203.  
  1204.  
  1205.  
  1206.           PDLISP language manual               Some System Primitives
  1207.           
  1208.  
  1209.  
  1210.  
  1211.           back an atom?  Well,  the answer is yes and no.  What we got
  1212.           back is a very  special atom in the LISP system, called NIL.
  1213.           NIL is  simultaneously  an  atom  and  a  list.  The list is
  1214.           called the empty list, and it is written as (). Whenever the
  1215.           PDLISP interpreter prints out an  empty list, it prints out
  1216.           the name of the  atom  NIL.  When we supplied (A) to CDR, it
  1217.           moved  the  left  parenthesis over the first element of  the
  1218.           argument list, resulting in (). Then,  when it came time for
  1219.           PDLISP to print out  (), it printed out NIL. NIL and () are
  1220.           completely   equivalent  in  every  respect,  and  they  are
  1221.           represented identically internally. 
  1222.  
  1223.             One  should  note  that  CAR and CDR both  take  lists  as
  1224.           arguments.  If either function is invoked with an atom as an
  1225.           argument, it will return an error message.  This is natural,
  1226.           because the jobs of  CAR  and  CDR are to divide a list into
  1227.           two parts and to return one of them.   Since  an  atom is by
  1228.           definition  an  indivisible unit, it cannot be divided  into
  1229.           two  parts.   The  following dialog with PDLISP illustrates
  1230.           this fact:
  1231.  
  1232.  
  1233.           /USR/LOGIN->(car 'A)
  1234.           ***> CAR: arg is atomic.            ;evaluation causes error
  1235.           /USR/LOGIN->(cdr 'A)
  1236.           ***> CDR: arg is atomic.
  1237.           /USR/LOGIN->
  1238.  
  1239.           NIL is the only atom which is a legal argument for CAR
  1240.           and CDR. That is, (CDR 'NIL) ==> NIL, and (CAR 'NIL) ==> NIL.
  1241.  
  1242.  
  1243.  
  1244.  
  1245.  
  1246.  
  1247.  
  1248.  
  1249.  
  1250.  
  1251.  
  1252.  
  1253.  
  1254.  
  1255.  
  1256.  
  1257.  
  1258.  
  1259.  
  1260.  
  1261.  
  1262.  
  1263.  
  1264.                                      - 14 -               Version 1.10
  1265.           
  1266.  
  1267.  
  1268.  
  1269.  
  1270.  
  1271.  
  1272.           PDLISP language manual               Some System Primitives
  1273.           
  1274.  
  1275.  
  1276.  
  1277.           Here, we are using the symbol "==>" as  an  abreviation  for
  1278.           the  phrase  "evaluates to."  I will use this symbol in  the
  1279.           rest of  this manual, as well as the related symbol, "<==>",
  1280.           which means "is equivalent to."  By "equivalent to", I  mean
  1281.           that two expressions evaluate to the same value.  That is, I
  1282.           will write  A <==> B whenever the evaluation of A equals the
  1283.           evaluation of B.
  1284.  
  1285.             [1]
  1286.  
  1287.           
  1288.  
  1289.  
  1290.           2.1.2 Quote Marks and the Evaluator
  1291.  
  1292.           I will now explain those funny little quote marks which have
  1293.           been  appearing  in  symbolic  expressions.  Suppose that we
  1294.           wish to find the first element of a  list  by using CAR, and
  1295.           type in the following s-expression:
  1296.  
  1297.  
  1298.           /USR/LOGIN->(car (a b c))
  1299.           ***> APPLY: function A is UNBOUND.  ;function APPLY inside the
  1300.                                               ;interpreter complains.
  1301.  
  1302.           What  happened?   It  may  seem  that  the  meaning  of  the
  1303.           s-expression (CAR (A B C)) is perfectly  obvious: namely, to
  1304.           return the first element of the list (A B C). However,  LISP
  1305.           does   not  quite  see  things  that  way.   In   evaluating
  1306.           (CAR (A B C)), the  interpreter  goes  through the following
  1307.           process:
  1308.  
  1309.             First it  checks to see if the form is a list or an atom. 
  1310.           Since it is a list, the  interpreter  assumes that the first
  1311.           element of the list is a function  name,  which in this case
  1312.           is CAR. Next, since CAR is defined as a function which wants
  1313.           its arguments  to  be  evaluated,  the interpreter evaluates
  1314.           (A B C).  However,  this is where it encounters a  problem. 
  1315.           (A B C) is evaluated just as any other form would be, so the
  1316.           interpreter assumes that the first element, A,  is  the name
  1317.           of a function.  Since A  is  not  defined  as a function, an
  1318.           error message is output. 
  1319.  
  1320.  
  1321.           ----------
  1322.  
  1323.           1. More  precisely,  A <==> B means that the evaluation of A
  1324.           is EQ to the evaluation of B, where  EQ  is  a LISP function
  1325.           which tests for a particular  form of equality.  This notion
  1326.           is covered more fully in the section on equality functions.
  1327.  
  1328.  
  1329.  
  1330.                                      - 15 -               Version 1.10
  1331.           
  1332.  
  1333.  
  1334.  
  1335.  
  1336.  
  1337.  
  1338.           PDLISP language manual               Some System Primitives
  1339.           
  1340.  
  1341.  
  1342.  
  1343.             The problem in the above example, aside from the fact that
  1344.           the  computer tried to do exactly what we told it to do,  is
  1345.           that  we   need   a  way  to  supply  literal  arguments  to
  1346.           functions.  That is, we need a way to turn off the evaluator
  1347.           at some point in its computation, so that  instead of trying
  1348.           to evaluate (A B C), it merely accepts  (A B C) as a literal
  1349.           argument to CAR. Fortunately, there is such a  way.   It  is
  1350.           called the QUOTE function. 
  1351.  
  1352.             The  QUOTE  function is a function of one argument,  which
  1353.           may be a list  or  a single atom, which returns the value of
  1354.           its argument.  For example,
  1355.  
  1356.  
  1357.           /USR/LOGIN->(quote (a b c))
  1358.           (A B C)
  1359.           /USR/LOGIN->(car (quote (a b c)))
  1360.           A
  1361.  
  1362.           Quote  performs  the  useful   function   of   telling   the
  1363.           interpreter   to   turn   off  the   evaluator   inside   an
  1364.           s-expression,  so  that  we can supply literal arguments  to
  1365.           functions.   Since  the  word  "quote" is so cumbersome,  an
  1366.           alternative notation has been developed.  Typing '(a b c) is
  1367.           the same as typing (quote (a b c)) as far as the interpreter
  1368.           is concerned.  Both expressions  are  converted  to the same
  1369.           internal  form,  and they are  evaluated  identically.   For
  1370.           example,
  1371.  
  1372.  
  1373.           /USR/LOGIN->(quote (a b c))
  1374.           (A B C)
  1375.           /USR/LOGIN->'(a b c)
  1376.           (A B C)
  1377.           /USR/LOGIN->(car (quote (a b c)))
  1378.           A
  1379.           /USR/LOGIN->(car '(a b c))
  1380.           A
  1381.  
  1382.  
  1383.           2.1.3 Auto-Quoting Functions and Atoms
  1384.  
  1385.             Some PDLISP  functions have the property of automatically
  1386.           quoting some or all  of  their  arguments.  For example, the
  1387.           SETQ function, which we  have  already  observed, quotes its
  1388.           first argument.   There  is  another,  equivalent  function,
  1389.           called SET, which does  the  same  thing as SETQ without the
  1390.           auto-quoting.
  1391.  
  1392.  
  1393.  
  1394.  
  1395.  
  1396.                                      - 16 -               Version 1.10
  1397.           
  1398.  
  1399.  
  1400.  
  1401.  
  1402.  
  1403.  
  1404.           PDLISP language manual               Some System Primitives
  1405.           
  1406.  
  1407.  
  1408.  
  1409.           /USR/LOGIN->(set 'a 'b)
  1410.           B
  1411.           /USR/LOGIN->(setq a 'c)
  1412.           C
  1413.  
  1414.           One  should  note that in the above dialog,  SETQ  does  not
  1415.           quote  its  second argument; only the first one is  quoted. 
  1416.           The second argument must be  quoted  manually  to  keep  the
  1417.           evaluator from evaluating it as a separate s-expression. 
  1418.  
  1419.             Some atoms are automatically quoted.  For example, numbers
  1420.           are always auto-quoted.  That is, normally when an atom name
  1421.           is  entered,  no  value  is associated  with  it  until  the
  1422.           variable  is  bound  by a SET or SETQ. However, numbers  are
  1423.           always bound to themselves automatically, and a call to  SET
  1424.           or SETQ with a number as the  first  argument will result in
  1425.           an error:
  1426.  
  1427.  
  1428.           /USR/LOGIN->3
  1429.           3
  1430.           /USR/LOGIN->(set 3 '4)
  1431.           ***> SET: first arg cannot be a number.
  1432.           /USR/LOGIN->
  1433.  
  1434.           Numbers and  strings  in PDLISP are constants in that their
  1435.           value can never be changed by a call to SET or SETQ. Quoting
  1436.           a number or a string, by  the  way,  has  no  effect,  since
  1437.           quoting just returns the number or string (which is equal to
  1438.           its value). 
  1439.  
  1440.             There are also symbolic constants in PDLISP. Any reserved
  1441.           word (see section 1.1.2) evaluates to itself.  Of these, the
  1442.           most  important  are  the  symbols  T   and  NIL.  That  is,
  1443.           (eval T) ==> T, and (eval NIL) ==> NIL.
  1444.  
  1445.  
  1446.  
  1447.  
  1448.  
  1449.  
  1450.  
  1451.  
  1452.  
  1453.  
  1454.  
  1455.  
  1456.  
  1457.  
  1458.  
  1459.  
  1460.  
  1461.  
  1462.                                      - 17 -               Version 1.10
  1463.           
  1464.  
  1465.  
  1466.  
  1467.  
  1468.  
  1469.  
  1470.           PDLISP language manual               Some System Primitives
  1471.           
  1472.  
  1473.  
  1474.  
  1475.  
  1476.  
  1477.           2.1.4 CONS and CONSP
  1478.  
  1479.           CONS  stands for "list CONStructor". It creates a  new  cell
  1480.           which is a "dotted pair" of its two arguments.  For example,
  1481.  
  1482.  
  1483.           (cons 'a 'b)         ==> (a . b)
  1484.           (cons 'a '(b c d e)) ==> (a b c d e)
  1485.           (cons 'nil 'nil)     ==> (nil . nil)
  1486.  
  1487.             Because non-atomic cells  can  only be created by the CONS
  1488.           function, such cells are often called cons cells. 
  1489.  
  1490.             CONSP is a function of one argument which returns T if and
  1491.           only if its argument is a cons cell.  For example,
  1492.  
  1493.  
  1494.           (consp 'a)      ==> NIL
  1495.           (consp '(a b))  ==> T
  1496.           (consp 'nil)    ==> NIL
  1497.           (consp '())     ==> NIL
  1498.  
  1499.           In the above examples, NIL is treated as an atom, and not as
  1500.           a list.  This is purely a matter of  convention,  and things
  1501.           could have wound up being the other way around. 
  1502.  
  1503.           
  1504.  
  1505.  
  1506.           2.1.5 APPEND
  1507.  
  1508.             APPEND is a built-in  primitive  function which produces a
  1509.           list out of the  elements  of  its  arguments (which must be
  1510.           lists).  For example,
  1511.  
  1512.  
  1513.           /USR/LOGIN->(append '(LISP is an) '(interactive language))
  1514.           (LISP IS AN INTERACTIVE LANGUAGE)
  1515.           /USR/LOGIN->(append '(LISP) '(is an interactive language))
  1516.           (LISP IS AN INTERACTIVE LANGUAGE)
  1517.           /USR/LOGIN->(append '(LISP) '(is an) '(interactive language))
  1518.           (LISP IS AN INTERACTIVE LANGUAGE)
  1519.           /USR/LOGIN->(append '() '(LISP is an interactive language))
  1520.           (LISP IS AN INTERACTIVE LANGUAGE)
  1521.           /USR/LOGIN->(append 'nil '(LISP is an interactive language))
  1522.           (LISP IS AN INTERACTIVE LANGUAGE)
  1523.  
  1524.  
  1525.  
  1526.  
  1527.  
  1528.                                      - 18 -               Version 1.10
  1529.           
  1530.  
  1531.  
  1532.  
  1533.  
  1534.  
  1535.  
  1536.           PDLISP language manual               Some System Primitives
  1537.           
  1538.  
  1539.  
  1540.  
  1541.  
  1542.  
  1543.           2.1.6 LIST
  1544.  
  1545.             LIST is a function which is similar to APPEND except  that
  1546.           instead of  combining  the  elements of its arguments into a
  1547.           list, LIST produces a list of its arguments.  For example:
  1548.  
  1549.  
  1550.           /USR/LOGIN->(list '(LISP is an) '(interactive language))
  1551.           ((LISP IS AN) (INTERACTIVE LANGUAGE))
  1552.           /USR/LOGIN->(list '(LISP) '(is an interactive language))
  1553.           ((LISP) (IS AN INTERACTIVE LANGUAGE))
  1554.           /USR/LOGIN->(list '(LISP) '(is an) '(interactive language))
  1555.           ((LISP) (IS AN) (INTERACTIVE LANGUAGE))
  1556.           /USR/LOGIN->(list 'LISP '(is an interactive language))
  1557.           (LISP (IS AN INTERACTIVE LANGUAGE))
  1558.           /USR/LOGIN->(list '() '(LISP is an interactive language))
  1559.           ((LISP IS AN INTERACTIVE LANGUAGE))
  1560.           /USR/LOGIN->(list 'nil '(LISP is an interactive language))
  1561.           ((LISP IS AN INTERACTIVE LANGUAGE))
  1562.  
  1563.  
  1564.           2.1.7 REVERSE
  1565.  
  1566.           REVERSE simply constructs  a  new list which is the reversal
  1567.           of its single argument, which must be a list.  For example,
  1568.  
  1569.  
  1570.           (reverse '(a b c)) ==> (c b a)
  1571.           (reverse '())      ==> ()
  1572.  
  1573.  
  1574.  
  1575.  
  1576.  
  1577.  
  1578.  
  1579.  
  1580.  
  1581.  
  1582.  
  1583.  
  1584.  
  1585.  
  1586.  
  1587.  
  1588.  
  1589.  
  1590.  
  1591.  
  1592.  
  1593.  
  1594.                                      - 19 -               Version 1.10
  1595.           
  1596.  
  1597.  
  1598.  
  1599.  
  1600.  
  1601.  
  1602.           PDLISP language manual               Some System Primitives
  1603.           
  1604.  
  1605.  
  1606.  
  1607.  
  1608.  
  1609.  
  1610.  
  1611.           2.2 Some Useful Predicates
  1612.  
  1613.  
  1614.           Predicates are functions  which  only  return T or NIL. What
  1615.           follows is a survey of the most common ones. 
  1616.  
  1617.  
  1618.           2.2.1 ATOM and SYMBOLP
  1619.  
  1620.           ATOM  returns T if (and only if) its argument is atomic.  It
  1621.           should be noted that there are several types of atoms:
  1622.  
  1623.  
  1624.             - floating point numbers, such as 3.14159 and 6.02E+23
  1625.  
  1626.             - integers, such as 2, 3, and 5
  1627.  
  1628.             - strings, such as "I am not a crook."
  1629.  
  1630.             - variables and functions, such as CAR, CDR, and CONS.
  1631.  
  1632.           Of the four types of atoms, only the last  type have names. 
  1633.           They are called symbols, and  PDLISP  maintains  a table of
  1634.           them called the symbol table, which is also sometimes called
  1635.           the object list. 
  1636.  
  1637.             Symbols can be identified with the SYMBOLP predicate.  For
  1638.           example, (SYMBOLP 'A) ==> T, whereas (SYMBOLP 3.14) ==> NIL.
  1639.  
  1640.           
  1641.  
  1642.  
  1643.           2.2.2 EQ, EQL, and EQUAL
  1644.  
  1645.           This  group of predicates  is  used  to  determine  equality
  1646.           between s-expressions.  EQUAL is the most general predicate,
  1647.           and the novice should stick to it in preference to the other
  1648.           ones.   EQ  and  EQL  are  special purpose predicates  which
  1649.           presume some  knowledge  on the part of the programmer about
  1650.           the  way  that s-expressions are  stored  internally.   More
  1651.           information  about  these  functions  is  contained  in  the
  1652.           section on equality later in this chapter. 
  1653.  
  1654.           
  1655.  
  1656.  
  1657.  
  1658.  
  1659.  
  1660.                                      - 20 -               Version 1.10
  1661.           
  1662.  
  1663.  
  1664.  
  1665.  
  1666.  
  1667.  
  1668.           PDLISP language manual               Some System Primitives
  1669.           
  1670.  
  1671.  
  1672.  
  1673.           2.2.3 NULL
  1674.  
  1675.           NULL  is  a  function  of 1 argument which returns T if  its
  1676.           argument   evaluates   to   NIL,  and  T  otherwise.   e.g.,
  1677.           (NULL 'a) ==> NIL, (NULL 'NIL) ==> T, (NULL T) ==> NIL
  1678.  
  1679.  
  1680.           2.2.4 NUMBERP
  1681.  
  1682.           NUMBERP returns  T  if  its  argument  is a number (either a
  1683.           float  or  an  integer).   For  example,  (NUMBERP 1) ==> T,
  1684.           (NUMBERP 2.6) ==> T, and after (SETQ A 6), (NUMBERP A) ==> T
  1685.  
  1686.  
  1687.           2.2.5 ZEROP
  1688.  
  1689.           ZEROP is  a  function  which  returns T if its argument is a
  1690.           number and is equal  to 0. Otherwise, ZEROP returns NIL. For
  1691.           example,   (ZEROP 0) ==> T,  (ZEROP 1) ==> NIL,  and   after
  1692.           (SETQ A 0), (ZEROP A) ==> T
  1693.  
  1694.  
  1695.           2.2.6 EVAL and explicit evaluation
  1696.  
  1697.           EVAL  allows  us  to  explicitly invoke the evaluator.   For
  1698.           example,
  1699.  
  1700.  
  1701.           /USR/LOGIN->(setq a 4)
  1702.           4
  1703.           /USR/LOGIN->a
  1704.           4
  1705.           /USR/LOGIN->(eval 'a)
  1706.           4
  1707.  
  1708.  
  1709.  
  1710.  
  1711.  
  1712.  
  1713.  
  1714.  
  1715.  
  1716.  
  1717.  
  1718.  
  1719.  
  1720.  
  1721.  
  1722.  
  1723.  
  1724.  
  1725.  
  1726.                                      - 21 -               Version 1.10
  1727.           
  1728.  
  1729.  
  1730.  
  1731.  
  1732.  
  1733.  
  1734.           PDLISP language manual               Some System Primitives
  1735.           
  1736.  
  1737.  
  1738.  
  1739.  
  1740.  
  1741.  
  1742.  
  1743.           2.3 Internal Representation of Symbolic Expressions
  1744.  
  1745.  
  1746.           Comprehension  of  the  material  in  this  section  is  not
  1747.           absolutely necessary  to  be  able  to  use  LISP, but it is
  1748.           likely   to  be  helpful.   In   particular,   knowing   how
  1749.           s-expressions  are represented inside of the machine enables
  1750.           one  to have a better idea as to "what is actually going  on
  1751.           in there" when lists are being manipulated. 
  1752.  
  1753.             S-expressions are, in principle, composed of two types  of
  1754.           elements: nodes and  atoms.   Atoms  are  primitive objects,
  1755.           such  as  variables, numbers, and strings.  Lists are  built
  1756.           out  of  nodes,  which "hold the  list  together",  and  the
  1757.           objects which are elements  of  the  list.   These  elements
  1758.           could be  atoms  or  other  lists.   To explain how symbolic
  1759.           expressions  are represented inside a computer memory, I  am
  1760.           introducing the concept of memory cells.  Computer memory is
  1761.           organized as an array of cells. Each cell can hold a number,
  1762.           and each cell has an address, which  is also a number.  When
  1763.           the computer memory is presented with the address of a cell,
  1764.           the contents of the cell can be read out, or they can be set
  1765.           to a new value. 
  1766.  
  1767.           
  1768.  
  1769.  
  1770.           2.3.1 Nodes and Lists
  1771.  
  1772.           Nodes permit the construction of lists of atoms  or of other
  1773.           lists.  Here's what they look like:
  1774.  
  1775.  
  1776.                    -------------------------
  1777.                   |  car cell  |  cdr cell  |
  1778.                    -----+------------+------
  1779.                         |            |
  1780.                         |            |
  1781.                         |            +-------> to some s-expression
  1782.                         +--------------------> to some s-expression
  1783.  
  1784.           Each node consists of two cells, which are  just pointers to
  1785.           some other cell  in  memory.  The first cell in each node is
  1786.           called the  "CAR  pointer",  or  "CAR field", and the second
  1787.           cell  is called the "CDR pointer" or the  "CDR  field."   By
  1788.           pointer, I mean that the contents of the cell are used as an
  1789.  
  1790.  
  1791.  
  1792.                                      - 22 -               Version 1.10
  1793.           
  1794.  
  1795.  
  1796.  
  1797.  
  1798.  
  1799.  
  1800.           PDLISP language manual               Some System Primitives
  1801.           
  1802.  
  1803.  
  1804.  
  1805.           address of some other location in memory.  So,  when  I  say
  1806.           that cell A "points" to cell B, the  implicit  assumption is
  1807.           that the address of cell B is contained in the cell A.
  1808.  
  1809.             Because of the boxlike  nature of my pictures of nodes and
  1810.           memory cells, I shall refer to my diagrams as box notation. 
  1811.  
  1812.             The  nodes  which I have been discussing are often  called
  1813.           cons cells, because they  can  only  be created via the CONS
  1814.           function.  A list is represented inside the LISP system by a
  1815.           very  specific  arrangement  of  cons  cells,  whereby  each
  1816.           element of the list  is  pointed  to by the CAR field of one
  1817.           cons-cell, and the list is joined together by  the CDR field
  1818.           of each cons-cell.  One could represent a list  on  paper as
  1819.           follows:
  1820.  
  1821.  
  1822.            ---------------------       ---------------------
  1823.           | car cell | cdr cell | +-->| car cell | cdr cell |
  1824.            -----+----------+----  |    -----+----------+----
  1825.                 |          |      |         |          |
  1826.                 |          +------+         |          +---> to next
  1827.                 |                           |                cons-cell
  1828.                 |                           |                in list
  1829.                 |                           |
  1830.                 +-----> to 1st element      +-----> to 2nd element
  1831.                         of list                     of list
  1832.  
  1833.  
  1834.  
  1835.  
  1836.  
  1837.  
  1838.  
  1839.  
  1840.  
  1841.  
  1842.  
  1843.  
  1844.  
  1845.  
  1846.  
  1847.  
  1848.  
  1849.  
  1850.  
  1851.  
  1852.  
  1853.  
  1854.  
  1855.  
  1856.  
  1857.  
  1858.                                      - 23 -               Version 1.10
  1859.           
  1860.  
  1861.  
  1862.  
  1863.  
  1864.  
  1865.  
  1866.           PDLISP language manual               Some System Primitives
  1867.           
  1868.  
  1869.  
  1870.  
  1871.           In the  above diagram, the cdr cell of the last cons-cell in
  1872.           the list points  to  NIL,  which  is  a  pre-defined  memory
  1873.           location in the PDLISP system.  Thus, the representation of
  1874.           a list contains one cons-cell for each element in the list. 
  1875.           The elements of a list could  be  symbols, numbers, or other
  1876.           lists. 
  1877.  
  1878.           
  1879.  
  1880.  
  1881.               As an example of a list, consider the s-expression (A B C).
  1882.           It could be represented in box notation as:
  1883.  
  1884.                -----------
  1885.               | car | cdr |
  1886.                --+-----+--
  1887.                  |     |      -----------
  1888.                  |     +---->| car | cdr |
  1889.                  |            --+-----+--
  1890.                  +---> A        |     |      -----------
  1891.                                 |     +---->| car | cdr |
  1892.                                 |            --+-----+--
  1893.                                 +---> B        |     |
  1894.                                                |     +----> NIL
  1895.                                                |
  1896.                                                +---> C
  1897.  
  1898.           The above list is terminated by a pointer to NIL, which is a
  1899.           built-in symbol.  Notice that there is exactly one cons-cell
  1900.           for each element of the list. 
  1901.  
  1902.           
  1903.  
  1904.  
  1905.           2.3.2 Dotted Pairs
  1906.  
  1907.           Not all s-expressions can be  printed  as  lists.   For this
  1908.           reason,  a  more comprehensive notation has been  developed,
  1909.           called "dotted pair notation."  In essence, a dotted pair is
  1910.           a representation of a single cons cell, and consists of  the
  1911.           following elements, in order:
  1912.  
  1913.  
  1914.           (1) a left parenthesis
  1915.           (2) the dotted pair representation of the CAR of the cons cell
  1916.           (3) a dot (".")
  1917.           (4) the dotted pair representation of the CDR of the cons cell
  1918.           (5) a right parenthesis
  1919.  
  1920.  
  1921.  
  1922.  
  1923.  
  1924.                                      - 24 -               Version 1.10
  1925.           
  1926.  
  1927.  
  1928.  
  1929.  
  1930.  
  1931.  
  1932.           PDLISP language manual               Some System Primitives
  1933.           
  1934.  
  1935.  
  1936.  
  1937.           For example, consider the following two s-expressions in box
  1938.           notation:
  1939.  
  1940.  
  1941.           expression # 1:
  1942.  
  1943.                -----------
  1944.               | car | cdr |
  1945.                --+-----+--
  1946.                  |     |      -----------
  1947.                  |     +---->| car | cdr |
  1948.                  |            --+-----+--
  1949.                  +---> A        |     |
  1950.                                 |     +----> NIL
  1951.                                 |
  1952.                                 +---> B
  1953.  
  1954.  
  1955.           expression # 2:
  1956.                             -----------
  1957.                            | car | cdr |
  1958.                             --+-----+--
  1959.                               |     |
  1960.                               |     +------> B
  1961.                               |
  1962.                               +------------> A
  1963.  
  1964.           The  reader  should recognize the first expression as  being
  1965.           the list, (A B). The second expression,  however,  cannot be
  1966.           written as a list.  According to the rules  of  dot notation
  1967.           as stated above, one would write it as  "(A . B)", using the
  1968.           dot to separate the two halves of the cons cell. 
  1969.  
  1970.             Because  dotted  pair  notation is defined for every  cons
  1971.           cell,  all s-expressions can be written as dotted pairs.  In
  1972.           particular, one  can  write  all lists as dotted pairs.  For
  1973.           example,  the   following   pairs   of   s-expressions   are
  1974.           equivalent:
  1975.  
  1976.  
  1977.           (A)     <==>  (A . NIL)
  1978.           (A B)   <==>  (A . (B . NIL))
  1979.           (A B C) <==>  (A . (B . (C . NIL)))
  1980.  
  1981.  
  1982.  
  1983.  
  1984.  
  1985.  
  1986.  
  1987.  
  1988.  
  1989.  
  1990.                                      - 25 -               Version 1.10
  1991.           
  1992.  
  1993.  
  1994.  
  1995.  
  1996.  
  1997.  
  1998.           PDLISP language manual               Some System Primitives
  1999.           
  2000.  
  2001.  
  2002.  
  2003.  
  2004.  
  2005.           2.3.3 Atoms and Symbols
  2006.  
  2007.           An atom is an indivisible element which  cannot  be  further
  2008.           decomposed using the  LISP  primitives CAR and CDR. As noted
  2009.           above, there are four  types  of atoms in PDLISP: integers,
  2010.           floats, strings,  and  user-defined atoms (symbols). Symbols
  2011.           are stored uniquely  in the system.  That is, two references
  2012.           to the same symbol  name  will  be interpreted by PDLISP as
  2013.           being references to the  same  symbol.  LISP interpreters do
  2014.           this  by maintaining a symbol table of all  of  the  symbols
  2015.           which they have encountered, which is also sometimes  called
  2016.           the object list. Whenever a symbol  name is read in from the
  2017.           console (or a file), the symbol table is  first  checked  to
  2018.           see if a  symbol  by  the  same name already exists.  If one
  2019.           does, then the symbol being read in is interpreted as  being
  2020.           a reference to the one already in the system.  Otherwise,  a
  2021.           new entry is created  which  corresponds  to  the new symbol
  2022.           name.   The process of  creating  a  new  symbol  is  called
  2023.           internment, and a symbol which has been placed in the symbol
  2024.           table in this manner is said to be "interned."
  2025.  
  2026.  
  2027.           2.3.4 Symbolic Structure
  2028.  
  2029.           Here  is  a  little   diagram  which  depicts  the  internal
  2030.           structure of a symbol in PDLISP:
  2031.  
  2032.  
  2033.  
  2034.            ----------------
  2035.           | print-name    +-----------> to name of the atom
  2036.            ----------------
  2037.           | variable cell +-----------> to variable value
  2038.            ----------------
  2039.           | function cell +-----------> to function value
  2040.            ----------------
  2041.           | property list +-----------> to property list
  2042.            ----------------
  2043.  
  2044.           A symbol can be thought of as a structure  of  four "cells."
  2045.           Each cell contains the address of  a  memory location in the
  2046.           memory  space  of  the  host  computer where the  associated
  2047.           information is stored.  These cells are:
  2048.  
  2049.  
  2050.  
  2051.  
  2052.  
  2053.  
  2054.  
  2055.  
  2056.                                      - 26 -               Version 1.10
  2057.           
  2058.  
  2059.  
  2060.  
  2061.  
  2062.  
  2063.  
  2064.           PDLISP language manual               Some System Primitives
  2065.           
  2066.  
  2067.  
  2068.  
  2069.  
  2070.  
  2071.           (1) The print-name cell, often called the pname cell by
  2072.               some authors. This cell points to the beginning of a
  2073.               string in the memory space of the host machine. It is
  2074.               set to a meaningful value when a symbol is read in by
  2075.               the interpreter, and it is rarely changed during execution.
  2076.  
  2077.           (2) The variable cell, often referred to as the value cell
  2078.               by some authors, contains the value of the symbol when
  2079.               it is being used as a variable. This cell can be manip-
  2080.               ulated using the SET and SETQ functions.
  2081.  
  2082.           (3) The function cell contains a pointer to an s-expression
  2083.               which represents the function definition of the symbol
  2084.               when it is being used as a function. This cell can be
  2085.               acessed and set using the GETD (or SYMBOL-FUNCTION) and
  2086.               PUTD functions.
  2087.           
  2088.           (4) The plist cell points to the beginning of the property
  2089.               list for this symbol. For more information, consult
  2090.               the chapter about property lists.
  2091.  
  2092.             The  important thing to note about how symbols are  stored
  2093.           in LISP is that a symbol can be  defined  as both a variable
  2094.           and as a function.   When  evaluating  an  s-expression, the
  2095.           interpreter decides which value  to  use  depending upon the
  2096.           position of the  reference to the symbol in the expression. 
  2097.           For  example,  in evaluating the expression (FOO A  B),  the
  2098.           symbol  FOO  would be interpreted as a function.  But if  we
  2099.           just typed in the symbol FOO, the interpreter would look  up
  2100.           the value cell of the symbol FOO and return that value. 
  2101.  
  2102.           
  2103.  
  2104.  
  2105.           2.3.5 Unique Representation and Equality
  2106.  
  2107.           Unlike other lisp objects, symbols are represented  uniquely
  2108.           in PDLISP; that is, two references to the same symbol  name
  2109.           refer to the same  object.   Other  types  of atoms (such as
  2110.           numbers and strings) are not stored uniquely.  For  example,
  2111.           if the number 4 were read in  twice, it would be represented
  2112.           internally in two different places.  Cons cells, as would be
  2113.           used   to   represent  lists  or  dotted  pairs  are   never
  2114.           represented uniquely.  For example, if the list (A B C) were
  2115.           read  in twice, it would be represented twice.  The  symbols
  2116.           A, B, and C would only be represented once, however. 
  2117.  
  2118.             Several  different  functions which test for equality  are
  2119.  
  2120.  
  2121.  
  2122.                                      - 27 -               Version 1.10
  2123.           
  2124.  
  2125.  
  2126.  
  2127.  
  2128.  
  2129.  
  2130.           PDLISP language manual               Some System Primitives
  2131.           
  2132.  
  2133.  
  2134.  
  2135.           provided  with  PDLISP  (and Common LISP). They are  EQUAL,
  2136.           EQL, and EQ.
  2137.  
  2138.           
  2139.  
  2140.  
  2141.           The most general of these is EQUAL. EQUAL sees equality as most
  2142.           people see it. When comparing symbols, EQUAL returns T if and only
  2143.           if both of its arguments are the same symbol. For example,
  2144.  
  2145.           (EQUAL 'A 'A) ==> T
  2146.           (EQUAL 'A 'B) ==> NIL
  2147.  
  2148.           When comparing strings, EQUAL returns T if the two strings have
  2149.           the same contents, even though strings are not stored uniquely.
  2150.           For example,
  2151.  
  2152.           (EQUAL "this is a string" "this is a string") ==> T
  2153.  
  2154.           When comparing numbers, EQUAL returns T if the two numbers
  2155.           are of the same type (integer or float) and if their arithmetic
  2156.           difference is 0. So,
  2157.  
  2158.           (EQUAL 9 9)   ==> T
  2159.           (EQUAL 9 9.0) ==> NIL
  2160.           (EQUAL 0 0.0) ==> NIL
  2161.  
  2162.           When comparing conses (lists or dotted pairs), EQUAL calls itself
  2163.           recursively to obtain a solution. In particular, if X and Y are
  2164.           two conses, then (EQUAL X Y) evaluates to T if (CAR X) is EQUAL to
  2165.           (CAR Y), and (CDR X) is EQUAL to (CDR Y). So,
  2166.  
  2167.           (EQUAL '(A B) '(A B))     ==> T
  2168.           (EQUAL '(A . B) '(A . B)) ==> T
  2169.           (EQUAL '(A B) '(A C))     ==> T
  2170.           (EQUAL '(A (B . C)) '((B . C) A)) ==> NIL
  2171.  
  2172.           EQ is a much simpler function; it returns T if its two arguments
  2173.           point to the same lisp argument. For example,
  2174.  
  2175.           (EQ 'A 'A)                 ==> T
  2176.           (EQ 4 4)                   ==> NIL   ;numbers not stored uniquely
  2177.           (EQ '(A B) '(A B))         ==> NIL   ;neither are conses
  2178.           (EQ "a string" "a string") ==> NIL   ;or strings
  2179.  
  2180.           EQL is intermediate in complexity (and usefulness) between EQ
  2181.           and EQUAL. It compares symbols, strings, and numbers as EQUAL
  2182.           does, but it does not call itself recursively to compare conses.
  2183.           For example,
  2184.  
  2185.  
  2186.  
  2187.  
  2188.                                      - 28 -               Version 1.10
  2189.           
  2190.  
  2191.  
  2192.  
  2193.  
  2194.  
  2195.  
  2196.           PDLISP language manual               Some System Primitives
  2197.           
  2198.  
  2199.  
  2200.  
  2201.           (EQL 'A 'A) ==> T
  2202.           (EQL 4 4)   ==> T                 ;numbers are equal, of same type
  2203.           (EQL 4 4.0) ==> NIL               ;numbers are not of the same type
  2204.           (EQL "a string" "a string") ==> T ;EQL examines strings...
  2205.           (EQL '(A B) '(A B)) ==> NIL       ;  but not conses.
  2206.  
  2207.  
  2208.  
  2209.  
  2210.           2.4 Exercises
  2211.  
  2212.  
  2213.  
  2214.           2.1 - Implement a function OUR-EQUAL which performs exactly
  2215.                 like EQUAL. This function should be implemented in
  2216.                 terms of itself, EQ, and EQL.
  2217.  
  2218.  
  2219.  
  2220.  
  2221.  
  2222.  
  2223.  
  2224.  
  2225.  
  2226.  
  2227.  
  2228.  
  2229.  
  2230.  
  2231.  
  2232.  
  2233.  
  2234.  
  2235.  
  2236.  
  2237.  
  2238.  
  2239.  
  2240.  
  2241.  
  2242.  
  2243.  
  2244.  
  2245.  
  2246.  
  2247.  
  2248.  
  2249.  
  2250.  
  2251.  
  2252.  
  2253.  
  2254.                                      - 29 -               Version 1.10
  2255.           
  2256.  
  2257.  
  2258.  
  2259.  
  2260.  
  2261.  
  2262.           PDLISP language manual               User-Defined Functions
  2263.           
  2264.  
  2265.  
  2266.  
  2267.  
  2268.  
  2269.  
  2270.  
  2271.  
  2272.  
  2273.                                     Chapter 3
  2274.  
  2275.                              User-Defined Functions
  2276.  
  2277.  
  2278.  
  2279.           In LISP,  a  symbolic  expression  which is a list is always
  2280.           interpreted as being  a  function  followed  by  a  list  of
  2281.           arguments.  For example, the  symbolic expression "(FN ARG)"
  2282.           would  be  interpreted  by  PDLISP  as  a function  of  one
  2283.           argument.  If the expression were "(FN)", then PDLISP would
  2284.           interpret it as a function of zero (no) arguments. 
  2285.  
  2286.             Likewise, an s-expression which  consists of just the name
  2287.           of a symbol, such as "X"  would be interpreted by PDLISP as
  2288.           being the contents of the variable cell of the symbol. 
  2289.  
  2290.             For example,  consider  the  following  conversation  with
  2291.           PDLISP:
  2292.  
  2293.  
  2294.           /USR/LOGIN->(setq a 4)  ;setting a variable to a value.
  2295.           4                       ;PDLISP echoes the value.
  2296.           /USR/LOGIN->a           ;evaluate A as a variable.
  2297.           4                       ;PDLISP prints A's value cell.
  2298.           /USR/LOGIN->(a)         ;let's say we erroneously entered this.
  2299.           ***> APPLY: function A is UNBOUND ;error for unbound function.
  2300.  
  2301.             A   form   in   PDLISP  is  a  symbolic  expression   (or
  2302.           "s-expression") which can be evaluated.  An symbol name is a
  2303.           form if  it  is defined as a variable.  Another type of form
  2304.           can be represented as:
  2305.  
  2306.  
  2307.                   (fn arg1 arg2 ... argn)
  2308.  
  2309.           where fn is some function which has been previously defined,
  2310.           and arg1, arg2, etc.  are its arguments.  Let's consider the
  2311.           following s-expression:
  2312.  
  2313.  
  2314.                       (f a b)
  2315.  
  2316.           If f  is  a  defined  function,  and  a  and  b  are defined
  2317.  
  2318.  
  2319.  
  2320.                                      - 30 -               Version 1.10
  2321.           
  2322.  
  2323.  
  2324.  
  2325.  
  2326.  
  2327.  
  2328.           PDLISP language manual               User-Defined Functions
  2329.           
  2330.  
  2331.  
  2332.  
  2333.           variables, then (f ab) is called a "form" , because it is an
  2334.           s-expression which can be evaluated.  Suppose, for the  sake
  2335.           of  argument,  that  f  has  been previously defined as  the
  2336.           function  which  adds  its arguments together.  Suppose also
  2337.           that a  and  b  have already been defined as variables using
  2338.           the SETQ function as described above.  Then the  interpreter
  2339.           would evaluate (f a b) as follows:
  2340.  
  2341.             The  first  thing  that  the  interpreter notices is  that
  2342.           (f a b) is a list.  Consequently, it can infer that the form
  2343.           is composed of two parts, namely, a function and an argument
  2344.           list.  At this point, UNXLISP breaks up the  form into these
  2345.           two parts, which are:
  2346.  
  2347.  
  2348.           part 1 = f, part 2 = (a b)
  2349.  
  2350.           The next thing that PDLISP does is to evaluate each element
  2351.           of the argument  list.   Let's assume that a and b have been
  2352.           previously defined,  using  SETQ,  as  the integers 1 and 2,
  2353.           respectively.  Then parts 1 and 2 would be:
  2354.  
  2355.  
  2356.           part 1 = f  part 2 = (1 2)
  2357.  
  2358.           Part  2 is now the evaluated  argument  list.   PDLISP  now
  2359.           applies the  part 1, f to part 2, (1 2). Without delving any
  2360.           deeper into the interpreter, the result is 3.
  2361.  
  2362.             The  relevance  of all of this to function  definition  is
  2363.           that  when  the  interpreter  looked  up the value of f,  it
  2364.           looked  in  a  different place than when it  looked  up  the
  2365.           values of a and b.  When looking up  the value of f, PDLISP
  2366.           examined the "function cell" for the symbol f.  When looking
  2367.           up the values of  a  and  b,  PDLISP examined the "variable
  2368.           cells" of a and b. 
  2369.  
  2370.           
  2371.  
  2372.  
  2373.  
  2374.  
  2375.           3.1 Defining Functions
  2376.  
  2377.  
  2378.           The easiest way to  define  a  function in PDLISP is to use
  2379.           the DEFUN form, which uses  a syntax similar to the one used
  2380.           in  conventional mathematics.  For example, if we wished  to
  2381.           define a function, FOO, of one argument, X, as the sum of  X
  2382.           and 1, we could write:
  2383.  
  2384.  
  2385.  
  2386.                                      - 31 -               Version 1.10
  2387.           
  2388.  
  2389.  
  2390.  
  2391.  
  2392.  
  2393.  
  2394.           PDLISP language manual               User-Defined Functions
  2395.           
  2396.  
  2397.  
  2398.  
  2399.  
  2400.  
  2401.           (defun foo (x) (+ x 1))
  2402.  
  2403.           The following are illustrations of the usage of DEFUN:
  2404.  
  2405.  
  2406.           (defun foo (x y) (+ x y))
  2407.           (defun bar (x) (* x (foo x)))
  2408.           (defun foobar (x) (+ (foo x) (bar x)))
  2409.  
  2410.           DEFUN itself  is defined in terms of the DEF function, which
  2411.           is in  turn defined in terms of the primitive function PUTD.
  2412.           PUTD  is called a  "primitive"  because  it  is  essentially
  2413.           built-in to PDLISP; it  is  defined  as  a machine-language
  2414.           routine, and is not defined in terms of anything else. 
  2415.  
  2416.             DEFUN returns as its value the name of the function  which
  2417.           was just defined. 
  2418.  
  2419.           
  2420.  
  2421.  
  2422.  
  2423.  
  2424.           3.2 DEF and PUTD
  2425.  
  2426.  
  2427.           The following material is provided for  those  who  wish  to
  2428.           have a  deeper understanding of how functions are defined in
  2429.           PDLISP, and who wish to understand LAMBDA's, NLAMBDA's, and
  2430.           MACRO's.
  2431.  
  2432.             Functions in PDLISP  are  defined  using  PUTD  in  a way
  2433.           similar to  the  way  that variables are assigned a value by
  2434.           SET,  except  that instead of setting the value cell of  the
  2435.           symbol, PUTD sets its function cell.  PUTD  returns  as  its
  2436.           value the new value of the function cell.  The function  DEF
  2437.           behaves the same way as the  built-in  function PUTD, except
  2438.           that it returns the name of the argument which was defined. 
  2439.  
  2440.             First,  let us  define  a  function  in  the  language  of
  2441.           high-school algebra.  Let us say that  we  wish  to define a
  2442.           function 'g' of one variable which adds 3 to that variable. 
  2443.           Then we might write:
  2444.  
  2445.  
  2446.                let g (x) = x + 3
  2447.  
  2448.           The part of the above statement to the right of the '=' sign
  2449.  
  2450.  
  2451.  
  2452.                                      - 32 -               Version 1.10
  2453.           
  2454.  
  2455.  
  2456.  
  2457.  
  2458.  
  2459.  
  2460.           PDLISP language manual               User-Defined Functions
  2461.           
  2462.  
  2463.  
  2464.  
  2465.           corresponds to a LISP  form  because,  assuming that we know
  2466.           ahead of  time  what  the  value  of  x  is, we can properly
  2467.           evaluate  the  value  of  'x + 3'. Taken  as  a  whole,  the
  2468.           statement constitutes a definition, because we have  defined
  2469.           g in  terms  of  an evaluable form.  The variable 'x' in the
  2470.           above example is called a dummy  variable  because it has no
  2471.           meaning  except  as  a  'place  holder'  for our  definition
  2472.           purposes.  In LISP, we would call x a bound variable. 
  2473.  
  2474.             To  write the same statement in PDLISP, let us break  the
  2475.           problem down into 2 parts: let us write first the right-hand
  2476.           side of the definition, and then the entire thing. 
  2477.  
  2478.  
  2479.           To encode the 'x + 3' part, we would write:
  2480.  
  2481.                   (+ x 3)
  2482.  
  2483.           To encode the entire statement 'let g (x) = x + 3'
  2484.           we would write:
  2485.  
  2486.                   (def g (lambda (x) (+ x 3)))
  2487.  
  2488.           We are actually setting the function cell of  g, which is an
  2489.           s-expression, to  be the value (lambda (x) (+ x 3)), another
  2490.           s-expression, which is  called  the  lambda expression.  For
  2491.           now, it might be profitable to think of the word 'LAMBDA' in
  2492.           LISP as  meaning 'is a function of'.  After having defined g
  2493.           as in the above  example,  we  can verify and manipulate its
  2494.           value as follows:
  2495.  
  2496.  
  2497.           ;
  2498.           ; let's start by defining a function:
  2499.           ;
  2500.           /USR/LOGIN->(def g (lambda (x) (+ x 3)))
  2501.           G                              ;returns name of the function.
  2502.           /USR/LOGIN->(getd 'g)          ;get contents of function cell.
  2503.           (LAMBDA (X)(+ X 3))            ;it's a lambda-expression.
  2504.           /USR/LOGIN->(car (getd 'g))    ;we can get the
  2505.           LAMBDA                         ;head of the lambda form
  2506.           /USR/LOGIN->(cdr (getd 'g))    ;
  2507.           ((X) (+ X 3))                  ; ...and the tail.
  2508.  
  2509.  
  2510.  
  2511.  
  2512.  
  2513.  
  2514.  
  2515.  
  2516.  
  2517.  
  2518.                                      - 33 -               Version 1.10
  2519.           
  2520.  
  2521.  
  2522.  
  2523.  
  2524.  
  2525.  
  2526.           PDLISP language manual               User-Defined Functions
  2527.           
  2528.  
  2529.  
  2530.  
  2531.  
  2532.  
  2533.  
  2534.  
  2535.           3.3 Lambda Binding
  2536.  
  2537.  
  2538.           Lambda binding, as occurs with the parameters of a function,
  2539.           is different in its effects than assignment, as performed by
  2540.           SETQ.  With  SETQ, the previous value of the variable  being
  2541.           assigned a value  is discarded, and is no longer available. 
  2542.           However, with lambda binding,  the  previous  value is saved
  2543.           away somewhere, and upon exiting the lambda-expression,  the
  2544.           old value is restored.  A more succint way of saying this is
  2545.           that  each lambda-variable has  a  scope,  where  its  value
  2546.           "makes  sense."  When the scope of the lambda-expression  is
  2547.           exited,  then  the  lambda-variables  no  longer   have  any
  2548.           meaning. 
  2549.  
  2550.             The set  of  symbols and their bindings is often called an
  2551.           environment.  Each  time  that  a  function is entered,  the
  2552.           environment  is altered to reflect the  new  values  of  the
  2553.           lambda-variables  which were bound.  This event is called  a
  2554.           lambda-binding transaction, since it is usually best thought
  2555.           of as an indivisible  event.   After the function is exited,
  2556.           of   course,   the   environment    is   restored   as   the
  2557.           lambda-variables are rebound to their entry values. 
  2558.  
  2559.  
  2560.  
  2561.  
  2562.  
  2563.  
  2564.  
  2565.  
  2566.  
  2567.  
  2568.  
  2569.  
  2570.  
  2571.  
  2572.  
  2573.  
  2574.  
  2575.  
  2576.  
  2577.  
  2578.  
  2579.  
  2580.  
  2581.  
  2582.  
  2583.  
  2584.                                      - 34 -               Version 1.10
  2585.           
  2586.  
  2587.  
  2588.  
  2589.  
  2590.  
  2591.  
  2592.           PDLISP language manual               User-Defined Functions
  2593.           
  2594.  
  2595.  
  2596.  
  2597.  
  2598.  
  2599.  
  2600.  
  2601.           3.4 NLAMBDA's
  2602.  
  2603.  
  2604.           NLAMBDA forms are like  LAMBDA's,  except that the arguments
  2605.           of  an  NLAMBDA  are  not evaluated before  it  is  applied,
  2606.           whereas  the arguments of  a  LAMBDA  are  always  evaluated
  2607.           before function application. 
  2608.  
  2609.           
  2610.  
  2611.  
  2612.  
  2613.  
  2614.           3.5 LEXPR's
  2615.  
  2616.  
  2617.           LEXPR's  are an archaic  programming  technique  which  were
  2618.           dropped from the Common  LISP  standard,  but  which  I will
  2619.           probably implement at some point in the future for backwards
  2620.           compatibility. 
  2621.  
  2622.           
  2623.  
  2624.  
  2625.  
  2626.  
  2627.           3.6 MACRO's
  2628.  
  2629.  
  2630.           Macros are  an  idea  which  originated outside of LISP, and
  2631.           which found its way into  the  language.   A macro basically
  2632.           manipulates its arguments,  and  produces  a new expression,
  2633.           which is called the macro expansion.  This new expression is
  2634.           then evaluated, and the  result is returned as the result of
  2635.           the macro.  For example, suppose we had defined mactest as:
  2636.  
  2637.  
  2638.           (def mactest (macro (carpart cdrpart)
  2639.               (list 'cons carpart cdrpart)))
  2640.  
  2641.           Then we could type:
  2642.  
  2643.           /USR/LOGIN->(mactest 1 2)
  2644.           (1 . 2)
  2645.  
  2646.  
  2647.  
  2648.  
  2649.  
  2650.                                      - 35 -               Version 1.10
  2651.           
  2652.  
  2653.  
  2654.  
  2655.  
  2656.  
  2657.  
  2658.           PDLISP language manual               User-Defined Functions
  2659.           
  2660.  
  2661.  
  2662.  
  2663.  
  2664.           The first time that the macro is evaluated, it is evaluated as
  2665.           if it were an NLAMBDA; that is, its arguments are not evaluated.
  2666.           When the result of this first evaluation is itself evaluated,
  2667.           it is evaluated normally. For example, in the above example,
  2668.           the result of the first evaluation is
  2669.  
  2670.           (list 'cons '1 '2)
  2671.  
  2672.           Since LIST evaluates its arguments, the expression evaluates to
  2673.  
  2674.           (1 . 2)
  2675.  
  2676.  
  2677.           3.6.1 Displacing Macros
  2678.  
  2679.           So far, I have assumed that macros are  expanded  each  time
  2680.           that  they  are  used.   However,  this  approach  is   very
  2681.           expensive in terms of speed degradation, and so various LISP
  2682.           interpreter implementors have  devised ways of insuring that
  2683.           macros  are  only  expanded  once.   Some LISP  interpreters
  2684.           expand macros when functions are defined.   PDLISP provides
  2685.           a facility whereby macros  can be expanded on only the first
  2686.           occaision that they are  used,  and  the  s-expression being
  2687.           evaluated   is   altered   to   incorporate   the   expanded
  2688.           sub-expression.   The original contents of the  s-expression
  2689.           being evaluated are discarded (or "smashed").
  2690.  
  2691.           
  2692.  
  2693.  
  2694.           3.6.2 Backquoting
  2695.  
  2696.           A useful construct when  writing  MACRO's is the backquoting
  2697.           system.  When an s-expression is  read into the system which
  2698.           is preceeded by a backquote ("`"), it is  quoted.   However,
  2699.           if it is a  list,  then  every  element of the list which is
  2700.           preceeded by  a  comma is not quoted.  For example, consider
  2701.           the following dialog:
  2702.  
  2703.  
  2704.           /USR/LOGIN->`(take out the trash)
  2705.           (TAKE OUT THE TRASH)
  2706.           /USR/LOGIN->(setq trash 'junk)     ;give TRASH a value.
  2707.           JUNK
  2708.           /USR/LOGIN->`(take out the ,trash) ;un-quote TRASH
  2709.           (TAKE OUT THE JUNK)
  2710.  
  2711.           Backquote also does something interesting with symbols which
  2712.           are preceeded by a comma followed by an at-sign, ",@".  This
  2713.  
  2714.  
  2715.  
  2716.                                      - 36 -               Version 1.10
  2717.           
  2718.  
  2719.  
  2720.  
  2721.  
  2722.  
  2723.  
  2724.           PDLISP language manual               User-Defined Functions
  2725.           
  2726.  
  2727.  
  2728.  
  2729.           sequence unquotes the expression  which follows, just as the
  2730.           comma does, except that  the resulting value must be a list.
  2731.           The elements  of  this  list  are then spliced into the list
  2732.           which was preceeded by the backquote.  For example:
  2733.  
  2734.  
  2735.           /USR/LOGIN->`(by the light of the moon)
  2736.           (BY THE LIGHT OF THE MOON)
  2737.           /USR/LOGIN->(setq moon '(silvery globe))
  2738.           (SILVERY GLOBE)
  2739.           /USR/LOGIN->`(by the light of the ,@moon)
  2740.           (BY THE LIGHT OF THE SILVERY GLOBE)
  2741.  
  2742.           In  the  previous  example of MACTEST, we could have defined
  2743.           MACTEST as
  2744.  
  2745.  
  2746.           (def mactest (macro (carpart cdrpart)
  2747.               `(cons ,carpart ,cdrpart)))
  2748.  
  2749.           The functions defining the behavior of backquote, comma, and
  2750.           comma-at are  in  the  file  bakquote.l,  which  is  on  the
  2751.           distribution disk. 
  2752.  
  2753.           
  2754.  
  2755.  
  2756.           3.6.3 The Smash Hook
  2757.  
  2758.           PDLISP provides a facility for controlling macro  expansion
  2759.           called the smash hook.  The actual mechanics of setting this
  2760.           hook are covered in the chapter on the STATUS function. 
  2761.  
  2762.             On boot up, the macro  smash flag is set to T. This is the
  2763.           ordinary  mode  of operation,  but  it  does  introduce  the
  2764.           inconvenience  of  not  being  able  to look at  un-expanded
  2765.           macros with  a  BAKTRACE  or  SHOWSTACK.  In  order  to make
  2766.           debugging easier, certain functions  clear the smash flag on
  2767.           entry, and restore it to its original value  on  exit.  (The
  2768.           debugger, for example, does this.) 
  2769.  
  2770.  
  2771.  
  2772.  
  2773.  
  2774.  
  2775.  
  2776.  
  2777.  
  2778.  
  2779.  
  2780.  
  2781.  
  2782.                                      - 37 -               Version 1.10
  2783.           
  2784.  
  2785.  
  2786.  
  2787.  
  2788.  
  2789.  
  2790.           PDLISP language manual               User-Defined Functions
  2791.           
  2792.  
  2793.  
  2794.  
  2795.  
  2796.  
  2797.  
  2798.  
  2799.           3.7 Optional, Rest, and Auxilliary Parameters
  2800.  
  2801.  
  2802.           Each function has in  its  declaration  a list of parameters
  2803.           which correspond to arguments which can or must be passed to
  2804.           it when it is run.  This list is variously called the lambda
  2805.           variable  list,  the  lambda  list, or the formal  parameter
  2806.           list.  I shall use the last term for this concept. 
  2807.  
  2808.             The parameters which are actually passed  to a function at
  2809.           run-time are  called  its  arguments, or actual parameters. 
  2810.           These parameters are not  known at function definition time,
  2811.           since they may vary from one  invocation  of the function to
  2812.           the next. 
  2813.  
  2814.             When  a  function is executed, a part of  the  interpreter
  2815.           called the binder associates the formal  parameter list of a
  2816.           function with the actual parameters  which  are being fed to
  2817.           it. 
  2818.  
  2819.             Optional,  rest,  and  auxilliary  parameters  are an idea
  2820.           which  originated  with  MDL,  a  LISP  offshoot  which  was
  2821.           developed at M.I.T. They  provide  additional flexibility in
  2822.           specifying parameter  lists.   Optional  and rest parameters
  2823.           later found their way into  LISP  Machine LISP, or ZETALISP,
  2824.           as described in Moon [1974], and from there into PDLISP.
  2825.  
  2826.             In general, a function  in  PDLISP  (or  Common LISP) has
  2827.           zero  or more required parameters, which may be followed  by
  2828.           one or more optional parameters, which may be followed by  a
  2829.           rest parameter, which may in turn be followed by any  number
  2830.           of auxilliary  parameters.   The  caller must provide enough
  2831.           arguments so that all of the required parameters are bound. 
  2832.           Any  extra  arguments are bound  by  the  evaluator  to  the
  2833.           optional parameters in the  function's  lambda-list.   If an
  2834.           optional  parameter is not "covered" by an argument, then it
  2835.           is bound to NIL. If the  function's  lambda  list contains a
  2836.           rest parameter, then it will be bound to a list of any extra
  2837.           arguments which  are left over after all of the required and
  2838.           optional  parameters  have been  bound.   If  there  are  no
  2839.           arguments left over, then  the  rest  parameter  is bound to
  2840.           NIL.
  2841.  
  2842.             Optional parameters are specified by inserting the keyword
  2843.           &OPTIONAL in the lambda-list  of a function.  All parameters
  2844.           which  occur  after  the  &OPTIONAL keyword  are  considered
  2845.  
  2846.  
  2847.  
  2848.                                      - 38 -               Version 1.10
  2849.           
  2850.  
  2851.  
  2852.  
  2853.  
  2854.  
  2855.  
  2856.           PDLISP language manual               User-Defined Functions
  2857.           
  2858.  
  2859.  
  2860.  
  2861.           optional by the evaluator. 
  2862.  
  2863.             Rest parameters are specified in a function definition  by
  2864.           the  use  of  the  keyword  &REST  in  the lambda-list of  a
  2865.           function.  The parameter after the &REST keyword is taken by
  2866.           the interpreter to be the rest parameter for the function. 
  2867.  
  2868.             Here is an illustration of how this works.   Suppose  that
  2869.           we have defined a function as follows:
  2870.  
  2871.  
  2872.           (defun funny (a b &optional c d &rest e)
  2873.             (prog ()
  2874.               ((print a)      ;print a
  2875.                (terpri)       ;terpri terminates the current print line
  2876.                (print b)      ;print b
  2877.                (terpri)       ;
  2878.                (print c)      ;and so on...
  2879.                (terpri)
  2880.                (print d)
  2881.                (terpri)
  2882.                (print e)
  2883.                (terpri))))
  2884.  
  2885.           Then we could engage in a terminal session as follows:
  2886.  
  2887.  
  2888.           /USR/LOGIN->(funny 1 2 3 4 5)
  2889.           1
  2890.           2
  2891.           3
  2892.           4
  2893.           (5)
  2894.           /USR/LOGIN->(funny 1 2 3)
  2895.           1
  2896.           2
  2897.           3
  2898.           NIL     ;C was bound to NIL
  2899.           NIL     ;as was D.
  2900.           NIL     ;E, the &REST parameter, was bound to NIL
  2901.  
  2902.           It  is  somewhat  redundant  to  have  an  &OPTIONAL   &REST
  2903.           parameter; all &REST parameters  are optional.  If no actual
  2904.           parameters are supplied to  a  &REST  formal parameter, then
  2905.           the &REST parameter is bound to NIL.
  2906.  
  2907.           
  2908.  
  2909.  
  2910.  
  2911.  
  2912.  
  2913.  
  2914.                                      - 39 -               Version 1.10
  2915.           
  2916.  
  2917.  
  2918.  
  2919.  
  2920.  
  2921.  
  2922.           PDLISP language manual               User-Defined Functions
  2923.           
  2924.  
  2925.  
  2926.  
  2927.  
  2928.  
  2929.  
  2930.  
  2931.           3.8 Initialized &OPTIONAL parameters
  2932.  
  2933.  
  2934.             &OPTIONAL  parameters  can be  initialized  to  a  default
  2935.           value.   If  the  parameter is not "covered" by an argument,
  2936.           then the interpreter will set it to its default value. 
  2937.  
  2938.             In  order  for  an &OPTIONAL parameter to have  a  default
  2939.           value, it must be declared as a list of the form
  2940.  
  2941.  
  2942.                (NAME VALUE)
  2943.  
  2944.           where NAME is the name of the formal parameter, and VALUE is
  2945.           its default value.  For example, in the following example, B
  2946.           is an initialized &OPTIONAL parameter:
  2947.  
  2948.  
  2949.           (def inittest (nlambda (a &optional (b 3))
  2950.               (progn
  2951.                   (princ "a = ")
  2952.                   (print a)
  2953.                   (terpri)
  2954.                   (princ "b = ")
  2955.                   (print b)
  2956.                   (terpri))))
  2957.  
  2958.               We could then invoke INITTEST as follows:
  2959.  
  2960.           /USR/LOGIN->(inittest 2)
  2961.           a = 2
  2962.           b = 3
  2963.  
  2964.  
  2965.  
  2966.  
  2967.           3.9 Auxilliary Parameters
  2968.  
  2969.  
  2970.           Auxilliary  parameters   serve   as  "local  variables"  for
  2971.           functions.    Auxilliary   parameters  are  declared  in   a
  2972.           function's lambda-list by including  the  keyword  &AUX, and
  2973.           then   the  names  of  the  auxilliary  variables.   If   an
  2974.           auxilliary variable is declared as a  list of the form (name
  2975.           value),  then  the  variable   is   initialized   the  value
  2976.           specified.    For   example,   in  the  following   function
  2977.  
  2978.  
  2979.  
  2980.                                      - 40 -               Version 1.10
  2981.           
  2982.  
  2983.  
  2984.  
  2985.  
  2986.  
  2987.  
  2988.           PDLISP language manual               User-Defined Functions
  2989.           
  2990.  
  2991.  
  2992.  
  2993.           definition, B and C are auxilliary parameters:
  2994.  
  2995.  
  2996.           (def auxtest (nlambda (a &aux b (c 6))
  2997.               (progn
  2998.                   (princ "a = ")
  2999.                   (print a)
  3000.                   (terpri)
  3001.                   (princ "b = ")
  3002.                   (print b)
  3003.                   (terpri)
  3004.                   (princ "c = ")
  3005.                   (print c)
  3006.                   (terpri))))
  3007.  
  3008.           In the above example, B is  initialized  to  a value of NIL,
  3009.           and C is initialized to a value of  6.  So (auxtest 3) would
  3010.           result in the output:
  3011.  
  3012.  
  3013.           a = 3
  3014.           b = NIL
  3015.           c = 6
  3016.  
  3017.           Several   possible  error  conditions  are  checked  by  the
  3018.           interpreter when a function is applied.  They are:
  3019.  
  3020.  
  3021.               Not enough arguments (actual parameters) to "cover"
  3022.           all of the non-&OPTIONAL formal parameters in a function's
  3023.           lambda-list will result in the error message:
  3024.  
  3025.               "***> BINDER(): too few arguments."
  3026.  
  3027.  
  3028.               Initialization of a parameter which is not an &OPTIONAL
  3029.           or &AUX parameter will produce the error message:
  3030.  
  3031.               "***> BINDER(): initialization of non-&OPTIONAL param."
  3032.  
  3033.  
  3034.               No parameter after the &REST keyword. This will produce
  3035.           the message:
  3036.  
  3037.               "***> BINDER(): missing &REST formal parameter."
  3038.  
  3039.  
  3040.  
  3041.  
  3042.  
  3043.  
  3044.  
  3045.  
  3046.                                      - 41 -               Version 1.10
  3047.           
  3048.  
  3049.  
  3050.  
  3051.  
  3052.  
  3053.  
  3054.           PDLISP language manual               User-Defined Functions
  3055.           
  3056.  
  3057.  
  3058.  
  3059.  
  3060.               More than one formal parameter after a &REST keyword,
  3061.           with no &AUX parameter will produce the message:
  3062.  
  3063.               "***> BINDER(): more than 1 &REST formal param."
  3064.  
  3065.  
  3066.               Lack of a formal parameter after an &OPTIONAL keyword
  3067.           will produce the message:
  3068.  
  3069.               "***> BINDER(): missing &OPTIONAL formal param."
  3070.  
  3071.  
  3072.               Missing parameters after the &AUX keyword. This will
  3073.           result in the message:
  3074.  
  3075.               "***> BINDER(): missing &AUX parameter(s)"
  3076.  
  3077.  
  3078.               The &AUX keyword must be the last keyword in the formal
  3079.           parameter list. Having a keyword (such as &OPTIONAL) in the
  3080.           parameter list after &AUX will trigger the message:
  3081.  
  3082.               "***> SETATOM(): formal parameter is not a symbol."
  3083.  
  3084.           
  3085.  
  3086.  
  3087.  
  3088.  
  3089.           3.10 PDLISP Function Descriptions
  3090.  
  3091.  
  3092.           Throughout the rest of this manual, I will  use  a  specific
  3093.           format for function descriptions.  Each description is begun
  3094.           with a line in the following format:
  3095.  
  3096.           
  3097.           FN-NAME     FN-TYPE     FORMAL PARAMETER LIST
  3098.  
  3099.           where,
  3100.  
  3101.               FN-NAME is the name of the function,
  3102.  
  3103.               FN-TYPE describes the way that the function handles
  3104.               its parameters. This is also called the discipline
  3105.               of the function. The possible values for FN-TYPE are:
  3106.  
  3107.               CSUBR       -   the symbol is bound as a C subroutine, which
  3108.                               means that it is a primitive subroutine in
  3109.  
  3110.  
  3111.  
  3112.                                      - 42 -               Version 1.10
  3113.           
  3114.  
  3115.  
  3116.  
  3117.  
  3118.  
  3119.  
  3120.           PDLISP language manual               User-Defined Functions
  3121.           
  3122.  
  3123.  
  3124.  
  3125.                               the kernel of the interpreter (which is
  3126.                               written in C) which evaluates its parameters.
  3127.  
  3128.               CNSUBR      -   the symbol is bound as a C subroutine which
  3129.                               does not evaluate its parameters. This
  3130.                               discipline is used to describe many
  3131.                               so-called special forms which may
  3132.                               evaluate some or all of their arguments,
  3133.                               but in a non-standard order.
  3134.  
  3135.               LAMBDA      -   the symbol is bound as a LAMBDA function,
  3136.                               which means that it is interpreted and
  3137.                               evaluates its parameters.
  3138.  
  3139.               NLAMBDA     -   the symbol is bound as an NLAMBDA function,
  3140.                               which means that it is interpreted and does
  3141.                               not evaluate its parameters.
  3142.  
  3143.               SUBR        -   the symbol is bound as a compiled LISP
  3144.                               function which evaluates its parameters.
  3145.           
  3146.               NSUBR       -   the symbol is bound as a compiled LISP
  3147.                               function which does not evaluate its
  3148.                               parameters.
  3149.  
  3150.               MACRO       -   the symbol is bound as a macro, which is
  3151.                               explained in the text.
  3152.  
  3153.               built-in    -   the symbol corresponds to a key-word in
  3154.                               the language, and  resides  in  an  invisible
  3155.                               "super-directory" which is not directly
  3156.                               accessible to the user. The reason why
  3157.                               this directory exists is so that certain
  3158.                               symbols which are critical to the operation
  3159.                               of the system (such as T and NIL) cannot
  3160.                               be bashed. The actual way that the function
  3161.                               handles arguments varies; see the individual
  3162.                               function description.
  3163.  
  3164.           FORMAL PARAMETER LIST is a representation of the  parameters
  3165.           which  the  function takes.  Generally,  these  symbols  are
  3166.           self-descriptive;  for  example,  a  parameter named  ANATOM
  3167.           means  that  the  corresponding  actual  parameter  must  be
  3168.           atomic, STR1 and STR2 mean that the corresponding parameters
  3169.           must  be strings, etc.  X, X1, X2, and so on  correspond  to
  3170.           arbitrary  s-expressions.   If the  &OPTIONAL  parameter  is
  3171.           included, then the subsequent parameters are optional. 
  3172.  
  3173.  
  3174.  
  3175.  
  3176.  
  3177.  
  3178.                                      - 43 -               Version 1.10
  3179.           
  3180.  
  3181.  
  3182.  
  3183.  
  3184.  
  3185.  
  3186.           PDLISP language manual               User-Defined Functions
  3187.           
  3188.  
  3189.  
  3190.  
  3191.  
  3192.  
  3193.  
  3194.  
  3195.           3.11 Summary of Functions Presented So Far
  3196.  
  3197.  
  3198.           Having  put  forth  the  format of a function description, I
  3199.           have  some  catching  up  to do.  Here is a listing  of  the
  3200.           functions which I have  already  discussed, as well as a few
  3201.           more which are generally useful in manipulating lists:
  3202.  
  3203.           
  3204.  
  3205.  
  3206.           APPEND              CSUBR       (&REST X)
  3207.  
  3208.           Non-destructive function which constructs a list composed
  3209.           of the elements of each of its arguments (which must be lists).
  3210.  
  3211.           for example:
  3212.           /USR/LOGIN->(append '(a b) '(c d) '(e) '() '(f))
  3213.           (a b c d e f)
  3214.  
  3215.           The last argument does not actually have to be a list, but
  3216.           may in fact be atomic, and it becomes the tail of the
  3217.           constructed list.
  3218.  
  3219.           for example:
  3220.           /USR/LOGIN->(append '(a b) '4)
  3221.           (a b . 4)
  3222.  
  3223.           See also NCONC, which is similar except that it alters all
  3224.           of its arguments except the last one.
  3225.  
  3226.  
  3227.           ATOM                CSUBR       (ANATOM)
  3228.  
  3229.           Returns T if its argument is atomic, otherwise returns NIL.
  3230.           (ATOM 'NIL) and (ATOM '()) both return T. Recall that
  3231.           something is an atom if it is a symbol, number, or string.
  3232.           See SYMBOLP.
  3233.  
  3234.           CAR                 CSUBR       (X)
  3235.  
  3236.           Returns the car half of the cell X. X must not be atomic, or
  3237.           an error results. (CAR '()) ==> NIL.
  3238.  
  3239.  
  3240.  
  3241.  
  3242.  
  3243.  
  3244.                                      - 44 -               Version 1.10
  3245.           
  3246.  
  3247.  
  3248.  
  3249.  
  3250.  
  3251.  
  3252.           PDLISP language manual               User-Defined Functions
  3253.           
  3254.  
  3255.  
  3256.  
  3257.  
  3258.           CDR                 CSUBR       (X)
  3259.  
  3260.           Returns the cdr half of the cell X. X must not be atomic, or
  3261.           an error results. (CDR '()) ==> NIL.
  3262.  
  3263.  
  3264.           CONS                CSUBR       (X1 X2)
  3265.  
  3266.           List constructor function. (CONS X1 X2) produces a cell which
  3267.           is a dotted pair, with the car part of the cell being set
  3268.           equal to X1, and the cdr part of the cell equal to X2.
  3269.  
  3270.  
  3271.           EQ                  CSUBR       (X1 X2)
  3272.  
  3273.           Returns T if and only if X1 and X2 are the same object or
  3274.           structure in s-expression space. Otherwise, returns NIL.
  3275.           EQ can be used to compare symbols, which are stored uniquely
  3276.           in the symbol table, but numbers and strings will not
  3277.           compare, since they are not. For example,
  3278.           (eq 'b 'b) ==> T, but (eq '(a b) '(a b)) ==> NIL.
  3279.  
  3280.  
  3281.           EQL                 CSUBR       (X1 X2)
  3282.  
  3283.           Returns T if and only if X1 and X2 are EQ to each other
  3284.           or if they are both numbers of the same type (integer or
  3285.           float) with the same value. Since character objects are
  3286.           actually stored as symbols in PDLISP, two character
  3287.           objects are EQL if they have the same name. (See the
  3288.           chapter on directory support.) EQL does not do anything
  3289.           intelligent about comparing strings; see the descriptions
  3290.           of STREQ and STRCMP. For example,
  3291.           (eql 'a 'a)         ==> T
  3292.           (eql '(a b) '(a b)) ==> NIL
  3293.           (eql 4 4)           ==> T
  3294.           (eql 4 4.0)         ==> NIL
  3295.  
  3296.  
  3297.           EQUAL               CSUBR       (X1 X2)
  3298.  
  3299.           Returns T if and only if X1 and X2 are equivalent structures.
  3300.           That is, all symbols referenced by X1 and X2 must be the same,
  3301.           but everything else must merely be isomorphic. For example,
  3302.           (equal 'a 'a)         ==> T
  3303.           (equal '(a b) '(a b)) ==> T, but (eq '(a b) '(a b)) ==> NIL.
  3304.           (equal 4 4)           ==> T, but (eq 4 4)           ==> NIL.
  3305.  
  3306.  
  3307.  
  3308.  
  3309.  
  3310.                                      - 45 -               Version 1.10
  3311.           
  3312.  
  3313.  
  3314.  
  3315.  
  3316.  
  3317.  
  3318.           PDLISP language manual               User-Defined Functions
  3319.           
  3320.  
  3321.  
  3322.  
  3323.  
  3324.           LIST                CSUBR       (&rest X)
  3325.  
  3326.           Constructs a list which is composed of the values of its
  3327.           arguments. For example, if A were previously defined as 4,
  3328.           then (LIST A 'B) would evaluate to (4 B).
  3329.  
  3330.  
  3331.           NUMBERP             CSUBR       (X)
  3332.  
  3333.           Returns T if X is an integer or a float; otherwise, returns NIL.
  3334.  
  3335.  
  3336.           QUOTE               CNSUBR      (X)
  3337.  
  3338.           (QUOTE X) evaluates to X. QUOTE is used to prevent evaluation
  3339.           of a form. Because QUOTE is so useful, the reader has been
  3340.           designed to translate any form preceded be a single quote
  3341.           mark (') into a QUOTE form. For example,
  3342.           ;
  3343.           ;the following expression really means (SETQ APPLE (QUOTE ORANGE))
  3344.           ;
  3345.           /USR/LOGIN->(SETQ APPLE 'ORANGE)
  3346.           ORANGE                           ;APPLE is set to this value
  3347.           ;
  3348.           ; omitting the quote mark causes an error, as in the following:
  3349.           ;
  3350.           /USR/LOGIN->(SETQ APPLE ORANGE)  ;without the quote mark.
  3351.           ***> EVAL: variable ORANGE is unbound
  3352.           ;
  3353.           ; the evaluator tried to look up the value of ORANGE.
  3354.           ;
  3355.  
  3356.           ZEROP           CSUBR       (X)
  3357.  
  3358.           Returns T if X is an integer or a float equal to zero;
  3359.           otherwise returns a value of NIL. This function will not
  3360.           return reliable results on floats, since they are rarely
  3361.           exactly equal to anything.
  3362.  
  3363.  
  3364.           The following functions access or set the value and
  3365.           function definition cells of symbols:
  3366.  
  3367.           DEF             NLAMBDA         (X Y)
  3368.  
  3369.           Sets the function definition cell of X to Y. X must be
  3370.           a symbol, or an error results. Neither argument is evaluated.
  3371.  
  3372.  
  3373.  
  3374.  
  3375.  
  3376.                                      - 46 -               Version 1.10
  3377.           
  3378.  
  3379.  
  3380.  
  3381.  
  3382.  
  3383.  
  3384.           PDLISP language manual               User-Defined Functions
  3385.           
  3386.  
  3387.  
  3388.  
  3389.           GETD            CSUBR       (ASYMBOL)
  3390.  
  3391.           Gets the contents of the function definition cell of ASYMBOL.
  3392.  
  3393.  
  3394.           PUTD            CSUBR       (ASYMBOL DEFINITION)
  3395.  
  3396.           Sets the function definition cell of ASYMBOL to DEFINITION.
  3397.           Both arguments are evaluated.
  3398.  
  3399.  
  3400.           SET             CSUBR       (ASYMBOL VALUE)
  3401.  
  3402.           Sets the value cell of a symbol (ASYMBOL) to VALUE. Unlike
  3403.           lambda-binding, this operation is destructive, in that the
  3404.           previous binding of ASYMBOL is not saved somewhere and
  3405.           restored later. The current function cell value of ASYMBOL,
  3406.           if it has one, is not altered.
  3407.  
  3408.  
  3409.           SETQ            CNSUBR      (ASYMBOL VALUE)
  3410.  
  3411.           Same as SET, except that this function quotes (does not
  3412.           evaluate) its first argument.
  3413.  
  3414.  
  3415.  
  3416.  
  3417.  
  3418.  
  3419.  
  3420.  
  3421.  
  3422.  
  3423.  
  3424.  
  3425.  
  3426.  
  3427.  
  3428.  
  3429.  
  3430.  
  3431.  
  3432.  
  3433.  
  3434.  
  3435.  
  3436.  
  3437.  
  3438.  
  3439.  
  3440.  
  3441.  
  3442.                                      - 47 -               Version 1.10
  3443.           
  3444.  
  3445.  
  3446.  
  3447.  
  3448.  
  3449.  
  3450.           PDLISP language manual               User-Defined Functions
  3451.           
  3452.  
  3453.  
  3454.  
  3455.  
  3456.                        This page intentionally left blank
  3457.  
  3458.  
  3459.  
  3460.  
  3461.  
  3462.  
  3463.  
  3464.  
  3465.  
  3466.  
  3467.  
  3468.  
  3469.  
  3470.  
  3471.  
  3472.  
  3473.  
  3474.  
  3475.  
  3476.  
  3477.  
  3478.  
  3479.  
  3480.  
  3481.  
  3482.  
  3483.  
  3484.  
  3485.  
  3486.  
  3487.  
  3488.  
  3489.  
  3490.  
  3491.  
  3492.  
  3493.  
  3494.  
  3495.  
  3496.  
  3497.  
  3498.  
  3499.  
  3500.  
  3501.  
  3502.  
  3503.  
  3504.  
  3505.  
  3506.  
  3507.  
  3508.                                      - 48 -               Version 1.10
  3509.           
  3510.  
  3511.  
  3512.  
  3513.  
  3514.  
  3515.  
  3516.           PDLISP language manual               User-Defined Functions
  3517.           
  3518.  
  3519.  
  3520.  
  3521.  
  3522.                        This page intentionally left blank
  3523.  
  3524.  
  3525.  
  3526.  
  3527.  
  3528.  
  3529.  
  3530.  
  3531.  
  3532.  
  3533.  
  3534.  
  3535.  
  3536.  
  3537.  
  3538.  
  3539.  
  3540.  
  3541.  
  3542.  
  3543.  
  3544.  
  3545.  
  3546.  
  3547.  
  3548.  
  3549.  
  3550.  
  3551.  
  3552.  
  3553.  
  3554.  
  3555.  
  3556.  
  3557.  
  3558.  
  3559.  
  3560.  
  3561.  
  3562.  
  3563.  
  3564.  
  3565.  
  3566.  
  3567.  
  3568.  
  3569.  
  3570.  
  3571.  
  3572.  
  3573.  
  3574.                                      - 49 -               Version 1.10
  3575.           
  3576.  
  3577.  
  3578.  
  3579.  
  3580.  
  3581.  
  3582.           PDLISP language manual               User-Defined Functions
  3583.           
  3584.  
  3585.  
  3586.  
  3587.  
  3588.                        This page intentionally left blank
  3589.  
  3590.  
  3591.  
  3592.  
  3593.  
  3594.  
  3595.  
  3596.  
  3597.  
  3598.  
  3599.  
  3600.  
  3601.  
  3602.  
  3603.  
  3604.  
  3605.  
  3606.  
  3607.  
  3608.  
  3609.  
  3610.  
  3611.  
  3612.  
  3613.  
  3614.  
  3615.  
  3616.  
  3617.  
  3618.  
  3619.  
  3620.  
  3621.  
  3622.  
  3623.  
  3624.  
  3625.  
  3626.  
  3627.  
  3628.  
  3629.  
  3630.  
  3631.  
  3632.  
  3633.  
  3634.  
  3635.  
  3636.  
  3637.  
  3638.  
  3639.  
  3640.                                      - 50 -               Version 1.10
  3641.           
  3642.  
  3643.  
  3644.  
  3645.  
  3646.  
  3647.  
  3648.           PDLISP language manual               User-Defined Functions
  3649.           
  3650.  
  3651.  
  3652.  
  3653.  
  3654.                        This page intentionally left blank
  3655.  
  3656.  
  3657.  
  3658.  
  3659.  
  3660.  
  3661.  
  3662.  
  3663.  
  3664.  
  3665.  
  3666.  
  3667.  
  3668.  
  3669.  
  3670.  
  3671.  
  3672.  
  3673.  
  3674.  
  3675.  
  3676.  
  3677.  
  3678.  
  3679.  
  3680.  
  3681.  
  3682.  
  3683.  
  3684.  
  3685.  
  3686.  
  3687.  
  3688.  
  3689.  
  3690.  
  3691.  
  3692.  
  3693.  
  3694.  
  3695.  
  3696.  
  3697.  
  3698.  
  3699.  
  3700.  
  3701.  
  3702.  
  3703.  
  3704.  
  3705.  
  3706.                                      - 51 -               Version 1.10
  3707.           
  3708.  
  3709.  
  3710.  
  3711.  
  3712.  
  3713.  
  3714.           PDLISP language manual               User-Defined Functions
  3715.           
  3716.  
  3717.  
  3718.  
  3719.  
  3720.                        This page intentionally left blank
  3721.  
  3722.  
  3723.  
  3724.  
  3725.  
  3726.  
  3727.  
  3728.  
  3729.  
  3730.  
  3731.  
  3732.  
  3733.  
  3734.  
  3735.  
  3736.  
  3737.  
  3738.  
  3739.  
  3740.  
  3741.  
  3742.  
  3743.  
  3744.  
  3745.  
  3746.  
  3747.  
  3748.  
  3749.  
  3750.  
  3751.  
  3752.  
  3753.  
  3754.  
  3755.  
  3756.  
  3757.  
  3758.  
  3759.  
  3760.  
  3761.  
  3762.  
  3763.  
  3764.  
  3765.  
  3766.  
  3767.  
  3768.  
  3769.  
  3770.  
  3771.  
  3772.                                      - 52 -               Version 1.10
  3773.           
  3774.  
  3775.  
  3776.  
  3777.  
  3778.  
  3779.  
  3780.           PDLISP language manual               User-Defined Functions
  3781.           
  3782.  
  3783.  
  3784.  
  3785.  
  3786.                        This page intentionally left blank
  3787.  
  3788.  
  3789.  
  3790.  
  3791.  
  3792.  
  3793.  
  3794.  
  3795.  
  3796.  
  3797.  
  3798.  
  3799.  
  3800.  
  3801.  
  3802.  
  3803.  
  3804.  
  3805.  
  3806.  
  3807.  
  3808.  
  3809.  
  3810.  
  3811.  
  3812.  
  3813.  
  3814.  
  3815.  
  3816.  
  3817.  
  3818.  
  3819.  
  3820.  
  3821.  
  3822.  
  3823.  
  3824.  
  3825.  
  3826.  
  3827.  
  3828.  
  3829.  
  3830.  
  3831.  
  3832.  
  3833.  
  3834.  
  3835.  
  3836.  
  3837.  
  3838.                                      - 53 -               Version 1.10
  3839.           
  3840.  
  3841.  
  3842.  
  3843.  
  3844.  
  3845.  
  3846.           PDLISP language manual               User-Defined Functions
  3847.           
  3848.  
  3849.  
  3850.  
  3851.  
  3852.                        This page intentionally left blank
  3853.  
  3854.           
  3855.  
  3856.  
  3857.  
  3858.  
  3859.  
  3860.  
  3861.  
  3862.  
  3863.  
  3864.  
  3865.  
  3866.  
  3867.  
  3868.  
  3869.  
  3870.  
  3871.  
  3872.  
  3873.  
  3874.  
  3875.  
  3876.  
  3877.  
  3878.  
  3879.  
  3880.  
  3881.  
  3882.  
  3883.  
  3884.  
  3885.  
  3886.  
  3887.  
  3888.  
  3889.  
  3890.  
  3891.  
  3892.  
  3893.  
  3894.  
  3895.  
  3896.  
  3897.  
  3898.  
  3899.  
  3900.  
  3901.  
  3902.  
  3903.  
  3904.                                      - 54 -               Version 1.10
  3905.           
  3906.  
  3907.  
  3908.  
  3909.  
  3910.  
  3911.  
  3912.           PDLISP language manual       Program Development in PDLISP
  3913.           
  3914.  
  3915.  
  3916.  
  3917.  
  3918.  
  3919.  
  3920.  
  3921.  
  3922.  
  3923.                                     Chapter 4
  3924.  
  3925.                          Program Development in PDLISP
  3926.  
  3927.  
  3928.  
  3929.           
  3930.  
  3931.  
  3932.  
  3933.  
  3934.           4.1 What's a Program?
  3935.  
  3936.  
  3937.             In PDLISP, a program is considered to be  a  sequence  of
  3938.           function definitions, which are  usually  available  in  the
  3939.           form  of   text-files.    From   PDLISP,   one  can  invoke
  3940.           conventional text editors using the shell escape.  The shell
  3941.           escape  feature  of PDLISP allows access to other  programs
  3942.           residing on the host operating  system (O/S), and is invoked
  3943.           by typing an exclamation point (!) after the PDLISP prompt,
  3944.           followed by a  command  which  will be sent to the host O/S.
  3945.           For example, if we were  running  under  MS-DOS (PC-DOS), we
  3946.           could invoke the excellent editor MINCE, which is  published
  3947.           by a company called Mark of the Unicorn as follows:
  3948.  
  3949.           
  3950.           /USR/LOGIN->!mince foo.bar
  3951.  
  3952.           (and MINCE would start executing). 
  3953.  
  3954.             Upon completion of the MINCE session, instead of returning
  3955.           to  the O/S, control transfers back to PDLISP. The  PDLISP
  3956.           environment should be  unchanged from the point where it was
  3957.           exited.   That  is,  all  variables,  functions,  and  their
  3958.           bindings (values) should be  intact.   At  that  point,  the
  3959.           programmer should read in the file which he has just  edited
  3960.           using one of the functions LOAD or LOADV.
  3961.  
  3962.             More  information  about  the  shell  escape  feature  and
  3963.           related functions is contained in the chapter of this manual
  3964.           entitled "Interfacing to the Operating System."
  3965.  
  3966.             For  example, suppose that a file called foo.l  exists  on
  3967.  
  3968.  
  3969.  
  3970.                                      - 55 -               Version 1.10
  3971.           
  3972.  
  3973.  
  3974.  
  3975.  
  3976.  
  3977.  
  3978.           PDLISP language manual       Program Development in PDLISP
  3979.           
  3980.  
  3981.  
  3982.  
  3983.           disk.  Then, the file can be read in as follows:
  3984.  
  3985.  
  3986.           /USR/LOGIN->(load "foo.l")
  3987.           T
  3988.  
  3989.             All of the load functions  are  functions  of  1 argument,
  3990.           which  must  be  a  string.  These functions evaluate  their
  3991.           argument,  but  since strings evaluate to themselves  (i.e.,
  3992.           they are automatically quoted), it is not necessary to QUOTE
  3993.           the argument.  These functions  all evaluate each expression
  3994.           in a file as  they  read  it  from  beginning to end.  These
  3995.           functions return as their values  T if they were successful,
  3996.           and return  NIL  if  they  do  not  succeed.  LOADV, besides
  3997.           returning their values, prints out  on  the screen the value
  3998.           of each s-expression as it is read.  The 'V' in LOADV stands
  3999.           for the word 'verbose'.
  4000.  
  4001.             As an example of the usage of the load functions, consider
  4002.           the following dialog whereby the user is loading in the file
  4003.           RUDOLF.L, which is on the distribution disk. 
  4004.  
  4005.  
  4006.           /USR/LOGIN->(load "rudolf.l")
  4007.           T           ;this is the value returned by LOAD.
  4008.           /USR/LOGIN->(loadv "rudolf.l")
  4009.           RED         ;rudolf has a red nose,
  4010.           GREEN       ;a green scarf,
  4011.           BLACK       ;black hooves,
  4012.           BROWN       ;brown fur,
  4013.           BLUE        ;blue eyes,
  4014.           BIG         ;big antlers,
  4015.           FAT         ;and a fat tummy.
  4016.           T           ;T here indicates that LOAD was successful.
  4017.  
  4018.  
  4019.  
  4020.  
  4021.  
  4022.  
  4023.  
  4024.  
  4025.  
  4026.  
  4027.  
  4028.  
  4029.  
  4030.  
  4031.  
  4032.  
  4033.  
  4034.  
  4035.  
  4036.                                      - 56 -               Version 1.10
  4037.           
  4038.  
  4039.  
  4040.  
  4041.  
  4042.  
  4043.  
  4044.           PDLISP language manual       Program Development in PDLISP
  4045.           
  4046.  
  4047.  
  4048.  
  4049.  
  4050.  
  4051.  
  4052.  
  4053.           4.2 Saving and Restoring PDLISP Sessions
  4054.  
  4055.  
  4056.             After many files  have  been  'read  in'  to  the  PDLISP
  4057.           system,  the  user  may  not wish  to  have  to  repeat  the
  4058.           process.   The SAVE and RESTORE functions enable the user to
  4059.           store the current state  of  the  machine  on  disk,  and to
  4060.           retrieve it in a later session. 
  4061.  
  4062.             For example, we could type the following to save a virtual
  4063.           image:
  4064.  
  4065.  
  4066.           /USR/LOGIN->(save "foo.img")
  4067.           T
  4068.  
  4069.             The T returned by eval indicates that the current state of
  4070.           the machine (called the "virtual image" in PDLISP) has been
  4071.           saved on  disk  with  the  file name of foo.img.  The double
  4072.           quote  marks  around  the  file name are necessary, and they
  4073.           make the file name a string in PDLISP.  The suffix, ".img",
  4074.           is a PDLISP convention which stands for the  word  "image".
  4075.           In the  remainder  of  this  document, files which have been
  4076.           saved to disk using the SAVE function will be referred to as
  4077.           "image files." 
  4078.  
  4079.             If later we wished to resume the computation at the  point
  4080.           at which it was saved, the sequence below would work:
  4081.  
  4082.  
  4083.           /USR/LOGIN->(restore "foo.img")
  4084.           T
  4085.  
  4086.           By the way, we  could  have  used  as the file name any name
  4087.           which  is legal for the host operating system.   For  PC-DOS
  4088.           (MS-DOS),   we    could   have   written   "b:foo.img",   or
  4089.           "a:\syslib\unhacks\foo.img".  For  examples  of  legal  file
  4090.           names, consult the instruction  manual  for  your  operating
  4091.           system. 
  4092.  
  4093.  
  4094.  
  4095.  
  4096.  
  4097.  
  4098.  
  4099.  
  4100.  
  4101.  
  4102.                                      - 57 -               Version 1.10
  4103.           
  4104.  
  4105.  
  4106.  
  4107.  
  4108.  
  4109.  
  4110.           PDLISP language manual       Program Development in PDLISP
  4111.           
  4112.  
  4113.  
  4114.  
  4115.  
  4116.  
  4117.  
  4118.  
  4119.           4.3 Summary of Virtual Image Commands
  4120.  
  4121.  
  4122.  
  4123.           RESTORE             CSUBR       (STR)
  4124.  
  4125.           Restores a virtual image from disk.  STR must be the name of
  4126.           a file which  contains  a virtual image which had previously
  4127.           been saved. 
  4128.  
  4129.           
  4130.  
  4131.  
  4132.           SAVE                CSUBR       (STR)
  4133.  
  4134.           Saves the current virtual  image  to  a  disk file, which is
  4135.           specifed by STR.
  4136.  
  4137.  
  4138.  
  4139.  
  4140.           4.4 Booting Up PDLISP
  4141.  
  4142.  
  4143.           The following  section is correct when PDLISP is running on
  4144.           UNIX; however, when running  on  MS-DOS a slightly different
  4145.           procedure is used.  Consult  the appendix on MS-DOS for more
  4146.           information. 
  4147.  
  4148.             PDLISP  can  be  booted  (started)  in one of two  ways. 
  4149.           PDLISP can be brought up with the command line
  4150.  
  4151.  
  4152.           PDLISP
  4153.  
  4154.           When PDLISP is brought up this way, it immediately searches
  4155.           the  current  directory of  the  disk  for  the  file  named
  4156.           "unxinit.l." If unxinit.l is found,  then  it  is  read in. 
  4157.           Otherwise, an error message is output. 
  4158.  
  4159.             PDLISP can also be brought up by typing the command line:
  4160.  
  4161.  
  4162.           PDLISP <filename>
  4163.  
  4164.             where <filename>  is the name of some image file.  In this
  4165.  
  4166.  
  4167.  
  4168.                                      - 58 -               Version 1.10
  4169.           
  4170.  
  4171.  
  4172.  
  4173.  
  4174.  
  4175.  
  4176.           PDLISP language manual       Program Development in PDLISP
  4177.           
  4178.  
  4179.  
  4180.  
  4181.           case, PDLISP does not  search  for  unxinit.l.  Instead, it
  4182.           restores the file named.  The virtual image is then restored
  4183.           to  the  exact state that it was in when the image file  was
  4184.           created.   This  is the normal way that a programmer insures
  4185.           continuity  of  the  virtual image from one session  to  the
  4186.           next. 
  4187.  
  4188.             An  image  file,  "unx.img",   may   be   present  on  the
  4189.           distribution disk.  This image  file  was  created by saving
  4190.           the virtual image after dirlib.l and other utility libraries
  4191.           had been loaded.  This image file can be restored by typing:
  4192.  
  4193.  
  4194.           PDLISP unx.img
  4195.  
  4196.  
  4197.  
  4198.  
  4199.  
  4200.  
  4201.  
  4202.  
  4203.  
  4204.  
  4205.  
  4206.  
  4207.  
  4208.  
  4209.  
  4210.  
  4211.  
  4212.  
  4213.  
  4214.  
  4215.  
  4216.  
  4217.  
  4218.  
  4219.  
  4220.  
  4221.  
  4222.  
  4223.  
  4224.  
  4225.  
  4226.  
  4227.  
  4228.  
  4229.  
  4230.  
  4231.  
  4232.  
  4233.  
  4234.                                      - 59 -               Version 1.10
  4235.           
  4236.  
  4237.  
  4238.  
  4239.  
  4240.  
  4241.  
  4242.           PDLISP language manual       Program Development in PDLISP
  4243.           
  4244.  
  4245.  
  4246.  
  4247.  
  4248.                        This page intentionally left blank
  4249.  
  4250.  
  4251.  
  4252.  
  4253.  
  4254.  
  4255.  
  4256.  
  4257.  
  4258.  
  4259.  
  4260.  
  4261.  
  4262.  
  4263.  
  4264.  
  4265.  
  4266.  
  4267.  
  4268.  
  4269.  
  4270.  
  4271.  
  4272.  
  4273.  
  4274.  
  4275.  
  4276.  
  4277.  
  4278.  
  4279.  
  4280.  
  4281.  
  4282.  
  4283.  
  4284.  
  4285.  
  4286.  
  4287.  
  4288.  
  4289.  
  4290.  
  4291.  
  4292.  
  4293.  
  4294.  
  4295.  
  4296.  
  4297.  
  4298.  
  4299.  
  4300.                                      - 60 -               Version 1.10
  4301.           
  4302.  
  4303.  
  4304.  
  4305.  
  4306.  
  4307.  
  4308.           PDLISP language manual       Program Development in PDLISP
  4309.           
  4310.  
  4311.  
  4312.  
  4313.  
  4314.                        This page intentionally left blank
  4315.  
  4316.  
  4317.  
  4318.  
  4319.  
  4320.  
  4321.  
  4322.  
  4323.  
  4324.  
  4325.  
  4326.  
  4327.  
  4328.  
  4329.  
  4330.  
  4331.  
  4332.  
  4333.  
  4334.  
  4335.  
  4336.  
  4337.  
  4338.  
  4339.  
  4340.  
  4341.  
  4342.  
  4343.  
  4344.  
  4345.  
  4346.  
  4347.  
  4348.  
  4349.  
  4350.  
  4351.  
  4352.  
  4353.  
  4354.  
  4355.  
  4356.  
  4357.  
  4358.  
  4359.  
  4360.  
  4361.  
  4362.  
  4363.  
  4364.  
  4365.  
  4366.                                      - 61 -               Version 1.10
  4367.           
  4368.  
  4369.  
  4370.  
  4371.  
  4372.  
  4373.  
  4374.           PDLISP language manual            List Processing Functions
  4375.           
  4376.  
  4377.  
  4378.  
  4379.  
  4380.  
  4381.  
  4382.  
  4383.  
  4384.  
  4385.                                     Chapter 5
  4386.  
  4387.                             List Processing Functions
  4388.  
  4389.  
  4390.  
  4391.           This   chapter   contains  descriptions   of   miscellaneous
  4392.           functions which are useful in manipulation of  s-expressions
  4393.           which are lists. 
  4394.  
  4395.  
  4396.           ADD-TO-LIST         LAMBDA      (E L)
  4397.  
  4398.           Adds element E to the list L if it is not already a member of
  4399.           L. The new list is returned. The original list is not
  4400.           altered. For example,
  4401.  
  4402.           /USR/LOGIN->(add-to-list 'd '(a b c))
  4403.           (D A B C)       ;D is CONS'ed onto the front of the list.
  4404.           /USR/LOGIN->(add-to-list 'd '(a b c d))
  4405.           (A B C D)       ;nothing happens in this case.
  4406.  
  4407.  
  4408.           CONSP               CSUBR           (X)
  4409.  
  4410.           Returns T if X is a cons cell (i.e., not atomic).
  4411.           Otherwise, returns NIL. (CONSP '()) evaluates to NIL.
  4412.           For example,
  4413.           (consp 4.5)    ==> NIL
  4414.           (consp 6)      ==> NIL
  4415.           (consp '(a b)) ==> T
  4416.           (consp 'c)     ==> NIL
  4417.  
  4418.  
  4419.           COPY-LIST           CSUBR           (X)
  4420.               Returns a list which is EQUAL to X, but not EQ to it.
  4421.           Only the top-most level of X is copied; everything
  4422.           below the top-most level is composed of the elements
  4423.           of X. This is accomplished by copying in the CDR
  4424.           direction, but not in the CAR direction. For example,
  4425.  
  4426.  
  4427.  
  4428.  
  4429.  
  4430.  
  4431.  
  4432.                                      - 62 -               Version 1.10
  4433.           
  4434.  
  4435.  
  4436.  
  4437.  
  4438.  
  4439.  
  4440.           PDLISP language manual            List Processing Functions
  4441.           
  4442.  
  4443.  
  4444.  
  4445.  
  4446.           /USR/LOGIN->(setq a '(x (y z)))    ;set A to something.
  4447.           (X (Y Z))                          ;here's the result.
  4448.           /USR/LOGIN->(setq b (copy-list a)) ;make B a copy of A.
  4449.           (X (Y Z))                          ;looks the same.
  4450.           /USR/LOGIN->(equal a b)            ;A is EQUAL to B
  4451.           T
  4452.           /USR/LOGIN->(eq a b)               ;but not EQ to it.
  4453.           NIL
  4454.           /USR/LOGIN->(rplacd (cdr b) 'w)    ;let's bend some links.
  4455.           (W)
  4456.           /USR/LOGIN->a                      ;nothing happened to A,
  4457.           (X (Y Z))
  4458.           /USR/LOGIN->b                      ;but B has changed.
  4459.           (X W)
  4460.  
  4461.               The RPLACD function which was used in the above example
  4462.           is described in the next section.
  4463.  
  4464.  
  4465.           COPY-TREE           CSUBR           (X)
  4466.               This function is similar to COPY-LIST, which is described
  4467.           above, but all cons cells in X are copied, and not just those
  4468.           at the top-most level of the list.
  4469.  
  4470.  
  4471.           CXXR, CXXXR         CSUBR           (X)
  4472.           
  4473.           Each member of this family of functions are composition
  4474.           functions of CAR and CDR. Each letter between 'C' and 'R' can
  4475.           be an 'A' or a 'D'. For example, (CADR X) would be equivalent
  4476.           to (CAR (CDR X)).
  4477.  
  4478.  
  4479.           DELETE              CSUBR           (X L)
  4480.  
  4481.           Deletes all elements of L which are EQL to X. For example,
  4482.           (delete '4 '(a b 4 c)) ==> (a b c)
  4483.  
  4484.  
  4485.           FIRSTN              LAMBDA          (N X)
  4486.  
  4487.           Returns a list consisting of the first N elements of X.
  4488.           If N is greater than the length of X, then X is returned.
  4489.           If N is less than or equal to 0, then NIL is returned.
  4490.           Source is in misc.l
  4491.  
  4492.  
  4493.  
  4494.  
  4495.  
  4496.  
  4497.  
  4498.                                      - 63 -               Version 1.10
  4499.           
  4500.  
  4501.  
  4502.  
  4503.  
  4504.  
  4505.  
  4506.           PDLISP language manual            List Processing Functions
  4507.           
  4508.  
  4509.  
  4510.  
  4511.  
  4512.           LAST                CSUBR           (X)
  4513.  
  4514.           Returns the last cons cell of a list. Note - this is NOT
  4515.           the same as the last element of a list. For example,
  4516.           (last '(a b c d e)) ==> (e), and
  4517.           (last '(a b (c . d))) => (c . d).
  4518.  
  4519.  
  4520.           LENGTH              CSUBR       (X)
  4521.  
  4522.           Returns the length of a list. If X is not a list, then returns 0.
  4523.           (length '(a b c)) ==> 3, (length '(a b (c d) e)) ==> 4
  4524.  
  4525.  
  4526.           LISTP               CSUBR       (X)
  4527.  
  4528.           Returns T if X is a cons (i.e., not atomic), or EQL to the
  4529.           empty list (which can be written as "()" or as "NIL").
  4530.           LISTP does not actually analyze X to ascertain whether
  4531.           or not it is a legal list; for example,
  4532.           (LISTP '(A B))   ==> T
  4533.           (LISTP '(A . B)) ==> T, even though (a . b) is not actually
  4534.           a list.
  4535.  
  4536.  
  4537.           MEMBER              CSUBR       (ITEM SET)
  4538.  
  4539.           Returns the largest tail of SET which has ITEM as a member.
  4540.           Only the top-most level of SET is examined. For example,
  4541.           (member 'b '(a b c d e)) ==> (b c d e)
  4542.  
  4543.  
  4544.           NTHCDR              LAMBDA      (N X)
  4545.  
  4546.           Returns the result of CDR'ing down X N times.
  4547.           For example,
  4548.  
  4549.           (nthcdr 0 '(a b c))  ==> (a b c)
  4550.           (nthcdr 1 '(a b c))  ==> (b c)
  4551.           (nthcdr 6 '(a b c))  ==> ()
  4552.           (nthcdr -1 '(a b c)) ==> (a b c)
  4553.  
  4554.           Source for this function is in misc.l.
  4555.  
  4556.  
  4557.  
  4558.  
  4559.  
  4560.  
  4561.  
  4562.  
  4563.  
  4564.                                      - 64 -               Version 1.10
  4565.           
  4566.  
  4567.  
  4568.  
  4569.  
  4570.  
  4571.  
  4572.           PDLISP language manual            List Processing Functions
  4573.           
  4574.  
  4575.  
  4576.  
  4577.  
  4578.           NULL                CSUBR       (X)
  4579.  
  4580.           Returns T if X is EQ to NIL; otherwise returns NIL.
  4581.           (null 'a)   ==> NIL
  4582.           (null '())  ==> T
  4583.           (null 'NIL) ==> T
  4584.           (null 'T)   ==> NIL
  4585.  
  4586.  
  4587.           REVERSE             CSUBR       (X)
  4588.  
  4589.           Returns a new list which is the reverse of its argument.
  4590.           The original list is not altered.
  4591.  
  4592.           (reverse '(a b c d e)) ==> (e d c b a)
  4593.           (reverse '(a (b . c))  ==> ((b . c) a)
  4594.           (reverse '())          ==> NIL
  4595.  
  4596.  
  4597.  
  4598.  
  4599.           5.1 Miscellaneous Predicates
  4600.  
  4601.  
  4602.  
  4603.           BOUNDP              CSUBR       (ASYMBOL)
  4604.  
  4605.           Returns T if its argument (which must be a symbol) is bound
  4606.           as something, otherwise returns NIL.
  4607.  
  4608.  
  4609.           TYPE                LAMBDA      (X)
  4610.  
  4611.           Returns the functional type of X, which must be a symbol.
  4612.           If X is not a symbol, then an error is generated.
  4613.  
  4614.  
  4615.           COMPILED-FUNCTION-P LAMBDA      (X)
  4616.  
  4617.           Returns T if X is a compiled function (i.e., a CSUBR,
  4618.           CNSUBR, SUBR, or NSUBR); otherwise returns NIL.
  4619.           X must be a symbol, or an error is generated.
  4620.  
  4621.  
  4622.           CNSUBRP             LAMBDA      (X)
  4623.  
  4624.           Returns T if X is a CNSUBR; otherwise returns NIL.
  4625.  
  4626.  
  4627.  
  4628.  
  4629.  
  4630.                                      - 65 -               Version 1.10
  4631.           
  4632.  
  4633.  
  4634.  
  4635.  
  4636.  
  4637.  
  4638.           PDLISP language manual            List Processing Functions
  4639.           
  4640.  
  4641.  
  4642.  
  4643.           CSUBRP              LAMBDA      (X)
  4644.  
  4645.           Returns T if X is a CSUBR; otherwise returns NIL.
  4646.  
  4647.  
  4648.           SUBRP               LAMBDA      (X)
  4649.  
  4650.           Returns T if X is a SUBR; otherwise returns NIL.
  4651.  
  4652.  
  4653.           NSUBRP              LAMBDA      (X)
  4654.  
  4655.           Returns T if X is an NSUBR; otherwise returns NIL.
  4656.  
  4657.  
  4658.           DIRP                CSUBR       (X)
  4659.  
  4660.           Returns T if X is a directory; otherwise returns NIL.
  4661.  
  4662.  
  4663.           SYMBOLP             CSUBR       (X)
  4664.  
  4665.           Returns T if X is a symbol (i.e., an atom on the object
  4666.           list), otherwise returns NIL.
  4667.           (symbolp 'a)       ==> T
  4668.           (symbolp '4)       ==> NIL
  4669.           (symbolp '(a . b)) ==> NIL
  4670.           (symbolp 't)       ==> T
  4671.  
  4672.  
  4673.           VARP                CSUBR       (X)
  4674.  
  4675.           Returns T if X has been bound as a variable (using SET or
  4676.           SETQ). Otherwise returns NIL.
  4677.  
  4678.  
  4679.  
  4680.  
  4681.  
  4682.  
  4683.  
  4684.  
  4685.  
  4686.  
  4687.  
  4688.  
  4689.  
  4690.  
  4691.  
  4692.  
  4693.  
  4694.  
  4695.  
  4696.                                      - 66 -               Version 1.10
  4697.           
  4698.  
  4699.  
  4700.  
  4701.  
  4702.  
  4703.  
  4704.           PDLISP language manual            List Processing Functions
  4705.           
  4706.  
  4707.  
  4708.  
  4709.  
  4710.  
  4711.  
  4712.  
  4713.           5.2 Surgical Functions
  4714.  
  4715.  
  4716.           Surgical functions, also called  destructive  functions, are
  4717.           functions  which permanently alter  one  or  more  of  their
  4718.           arguments.   In  the  jargon of functional programming, they
  4719.           have side effects. 
  4720.  
  4721.  
  4722.           NCONC               CSUBR       (&rest LISTS)
  4723.  
  4724.           This function alters the CDR cell of the last cons cell
  4725.           of each of its arguments (except the last one) to point
  4726.           to the next argument. The net effect of this function
  4727.           is the same as if APPEND had been used, except that
  4728.           the arguments are themselves altered, whereas APPEND
  4729.           creates an entirely new list and leaves the original
  4730.           ones intact. For example,
  4731.  
  4732.           /USR/LOGIN->(setq a '(q r s))
  4733.           (q r s)
  4734.           /USR/LOGIN->(setq b '(t u v))
  4735.           (t u v)
  4736.           /USR/LOGIN->(nconc a b)         ;apply nconc
  4737.           (q r s t u v)
  4738.           /USR/LOGIN->a                   ;a is permanently altered
  4739.           (q r s t u v)
  4740.           /USR/LOGIN->b                   ;but b is the same as before
  4741.           (t u v)
  4742.  
  4743.  
  4744.           RPLACA              CSUBR       (X Y)
  4745.  
  4746.           Stands for RePLAce CAr; the car field of X is replaced by Y.
  4747.           The previous contents of X's car field is discarded. X must
  4748.           be a non-atomic node, or an error will result. This function,
  4749.           like all "surgical functions", is rather dangerous, and
  4750.           should be avoided if at all possible.
  4751.  
  4752.  
  4753.           RPLACD              CSUBR       (X Y)
  4754.  
  4755.           Same as RPLACA, except that the cdr field is replaced.
  4756.  
  4757.  
  4758.  
  4759.  
  4760.  
  4761.  
  4762.                                      - 67 -               Version 1.10
  4763.           
  4764.  
  4765.  
  4766.  
  4767.  
  4768.  
  4769.  
  4770.           PDLISP language manual            List Processing Functions
  4771.           
  4772.  
  4773.  
  4774.  
  4775.  
  4776.  
  4777.  
  4778.  
  4779.           5.3 TCONC Structures
  4780.  
  4781.  
  4782.           
  4783.  
  4784.           A tconc structure is a type of s-expression with
  4785.           pointers to both the head and tail of a list. A
  4786.           tconc cell is just a cons cell whose car points
  4787.           to the head of some list, and whose cdr points to
  4788.           the tail (last cons) of the same list. The reason
  4789.           why tconc cells were invented is that they
  4790.           facilitate appending something to the end of a list.
  4791.  
  4792.           Source for all of these functions is in misc.l.
  4793.  
  4794.  
  4795.           MAKE-TCONC          NLAMBDA     ()
  4796.           Creates a new tconc structure and returns it. All such
  4797.           structures are initially EQUAL to (NIL . NIL).
  4798.  
  4799.  
  4800.           REMOVE-FIRST        LAMBDA      (X)
  4801.           Removes the first element from the tconc cell X, and
  4802.           returns it.
  4803.  
  4804.  
  4805.           TCONC               LAMBDA      (X Y)
  4806.           Appends an element, Y, to the front of a tconc structure, X.
  4807.  
  4808.  
  4809.           LCONC               LAMBDA      (X Y)
  4810.           Appends an element, Y, to the end of a tconc structure, X.
  4811.  
  4812.  
  4813.  
  4814.  
  4815.  
  4816.  
  4817.  
  4818.  
  4819.  
  4820.  
  4821.  
  4822.  
  4823.  
  4824.  
  4825.  
  4826.  
  4827.  
  4828.                                      - 68 -               Version 1.10
  4829.           
  4830.  
  4831.  
  4832.  
  4833.  
  4834.  
  4835.  
  4836.           PDLISP language manual            List Processing Functions
  4837.           
  4838.  
  4839.  
  4840.  
  4841.  
  4842.                        This page intentionally left blank
  4843.  
  4844.  
  4845.  
  4846.  
  4847.  
  4848.  
  4849.  
  4850.  
  4851.  
  4852.  
  4853.  
  4854.  
  4855.  
  4856.  
  4857.  
  4858.  
  4859.  
  4860.  
  4861.  
  4862.  
  4863.  
  4864.  
  4865.  
  4866.  
  4867.  
  4868.  
  4869.  
  4870.  
  4871.  
  4872.  
  4873.  
  4874.  
  4875.  
  4876.  
  4877.  
  4878.  
  4879.  
  4880.  
  4881.  
  4882.  
  4883.  
  4884.  
  4885.  
  4886.  
  4887.  
  4888.  
  4889.  
  4890.  
  4891.  
  4892.  
  4893.  
  4894.                                      - 69 -               Version 1.10
  4895.           
  4896.  
  4897.  
  4898.  
  4899.  
  4900.  
  4901.  
  4902.           PDLISP language manual            List Processing Functions
  4903.           
  4904.  
  4905.  
  4906.  
  4907.  
  4908.                        This page intentionally left blank
  4909.  
  4910.  
  4911.  
  4912.  
  4913.  
  4914.  
  4915.  
  4916.  
  4917.  
  4918.  
  4919.  
  4920.  
  4921.  
  4922.  
  4923.  
  4924.  
  4925.  
  4926.  
  4927.  
  4928.  
  4929.  
  4930.  
  4931.  
  4932.  
  4933.  
  4934.  
  4935.  
  4936.  
  4937.  
  4938.  
  4939.  
  4940.  
  4941.  
  4942.  
  4943.  
  4944.  
  4945.  
  4946.  
  4947.  
  4948.  
  4949.  
  4950.  
  4951.  
  4952.  
  4953.  
  4954.  
  4955.  
  4956.  
  4957.  
  4958.  
  4959.  
  4960.                                      - 70 -               Version 1.10
  4961.           
  4962.  
  4963.  
  4964.  
  4965.  
  4966.  
  4967.  
  4968.           PDLISP language manual          PDLISP Directory Structure
  4969.           
  4970.  
  4971.  
  4972.  
  4973.  
  4974.  
  4975.  
  4976.  
  4977.  
  4978.  
  4979.                                     Chapter 6
  4980.  
  4981.                            PDLISP Directory Structure
  4982.  
  4983.  
  4984.  
  4985.           Suppose we assigned a  variable  a  value,  and subsequently
  4986.           read  in  a file (using one of the LOAD instructions)  which
  4987.           had  its own variable of the same name.  The original  value
  4988.           of our variable would  get  "clobbered", because the part of
  4989.           the PDLISP interpreter called  the reader always interprets
  4990.           two variables  with the same name to be the same symbol.  If
  4991.           a  programmer  were  to read in a file which was written  by
  4992.           another  person,  there  would  obviously be  numerous  name
  4993.           conflicts  which  could  be difficult to resolve.  For  this
  4994.           reason,  as  well  as  for  the  improved  modularity  which
  4995.           results,  a  tree-structured directory  structure  has  been
  4996.           provided in PDLISP. This directory  structure  was inspired
  4997.           by the UNIX(tm) operating system, which was invented at  ATT
  4998.           Bell Laboratories in New Jersey.
  4999.  
  5000.             Directories impose a structure on the data  stored  by the
  5001.           PDLISP  system  as  a  whole,  which is referred to as  the
  5002.           object list.  The object  list  contains  all  symbols which
  5003.           have been defined by the user or the system. 
  5004.  
  5005.             Directories are actually just a particular type of symbol,
  5006.           much as variables are.  PDLISP sets up some directories for
  5007.           its  own  use  at  system  initialization  time.   The  most
  5008.           important of these is the  "root" directory.  All symbols in
  5009.           the system can be found by tracing a path through a sequence
  5010.           of directories, starting with  the root directory, until the
  5011.           desired symbol is reached. 
  5012.  
  5013.             Symbols are named by  sequences  of alphanumeric (and some
  5014.           other)  characters starting with letters.  When a name of  a
  5015.           symbol is specified to PDLISP, it may be  in  the form of a
  5016.           path-name. . A path-name  is  a  sequence of directory names
  5017.           which are separated by slashes ("/") which end in an  symbol
  5018.           name.   The  symbol  named  at the end of the path-name  may
  5019.           itself  be  a  directory.   If  the path-name begins with  a
  5020.           slash,  then  PDLISP  begins   its   search   in  the  root
  5021.           directory.   The  name  "/"  refers  to  the root  directory
  5022.           itself.    Thus,   the   name  "/SYS/CMD"  refers   to   the
  5023.  
  5024.  
  5025.  
  5026.                                      - 71 -               Version 1.10
  5027.           
  5028.  
  5029.  
  5030.  
  5031.  
  5032.  
  5033.  
  5034.           PDLISP language manual          PDLISP Directory Structure
  5035.           
  5036.  
  5037.  
  5038.  
  5039.           subdirectory "CMD" which is  located in the directory "SYS",
  5040.           which is in turn located in the root directory. 
  5041.  
  5042.             As an abbreviation, a path name  which does not begin with
  5043.           a  slash  causes  PDLISP to begin its search in the  user's
  5044.           current directory.   Thus,  the path-name "BLUE/GREEN" would
  5045.           cause PDLISP to search  the current directory for an symbol
  5046.           named "BLUE" (which must itself be a directory), and then in
  5047.           that directory for an symbol named "GREEN".
  5048.  
  5049.             The same symbol name may occur in more than one directory,
  5050.           but  two  symbols  are the same if and  only  if  they  have
  5051.           identical path-names.  Two distinct  symbols  with  the same
  5052.           name cannot exist in the  same  directory.  For example, the
  5053.           symbols /SYS/CMD/BLUE and /USR/LOGIN/BLUE could both coexist
  5054.           in  the  same  directory tree, but they reside in  different
  5055.           directories.  Their path-names  differ,  but  not  the  last
  5056.           segment of their path-names, which are their symbol names. 
  5057.  
  5058.           
  5059.  
  5060.  
  5061.  
  5062.  
  5063.  
  5064.  
  5065.  
  5066.  
  5067.  
  5068.  
  5069.  
  5070.  
  5071.  
  5072.  
  5073.  
  5074.  
  5075.  
  5076.  
  5077.  
  5078.  
  5079.  
  5080.  
  5081.  
  5082.  
  5083.  
  5084.  
  5085.  
  5086.  
  5087.  
  5088.  
  5089.  
  5090.  
  5091.  
  5092.                                      - 72 -               Version 1.10
  5093.           
  5094.  
  5095.  
  5096.  
  5097.  
  5098.  
  5099.  
  5100.           PDLISP language manual          PDLISP Directory Structure
  5101.           
  5102.  
  5103.  
  5104.  
  5105.  
  5106.  
  5107.  
  5108.  
  5109.           6.1 Initial PDLISP Directory Configuration
  5110.  
  5111.  
  5112.           At system initialization time,  the following object list is
  5113.           set up:
  5114.  
  5115.  
  5116.                                    / (root symbol)
  5117.                                    |
  5118.                      +-------------+-------------+
  5119.                      |                           |
  5120.                     SYS (system directory)      USR (user directory)
  5121.                      |                           |
  5122.             +--------+--------+                  |
  5123.             |                 |                  |
  5124.            CMD              CONST              LOGIN
  5125.            |                 |
  5126.            +----+----+       +-----+-----+
  5127.            |    |    |       |     |     |
  5128.           LED LCOMP LASM  (various global symbols)
  5129.  
  5130.           The root directory, "/", is the top (bottom?) of the  entire
  5131.           object list  structure.  From root, the tree is divided into
  5132.           2 main sub-directories, /SYS and /USR. /SYS is where PDLISP
  5133.           utilities  and  constants  reside.  For  example,  LED,  the
  5134.           PDLISP  structure  editor,  LCOMP, the PDLISP compiler, as
  5135.           well as  other system utilities will be loaded into /SYS/CMD
  5136.           (after  they  have  been  written, of course).  The user  is
  5137.           initially  logged  in  at  the   directory  /USR/LOGIN.  His
  5138.           application programs are assumed to be built from his  login
  5139.           directory,  although  this is not necessary.  First of  all,
  5140.           the most  important  symbol in the entire object list is the
  5141.           root symbol, which has a pathname of "/". For example, if we
  5142.           wanted to find out  the  value of the root, we could type in
  5143.           the following:
  5144.  
  5145.  
  5146.           /USR/LOGIN->/
  5147.           (sys usr)
  5148.  
  5149.           The  value of root, as with all directories, is just a  list
  5150.           of the symbols which are on it.  If  we  wished  to refer to
  5151.           the  sys  subdirectory of the root directory, we would write
  5152.           "/SYS".  /SYS/CMD would refer to the "CMD" directory,  which
  5153.           is  located  in the "sys"  directory,  which,  in  turn,  is
  5154.           located in the root ("/") directory. 
  5155.  
  5156.  
  5157.  
  5158.                                      - 73 -               Version 1.10
  5159.           
  5160.  
  5161.  
  5162.  
  5163.  
  5164.  
  5165.  
  5166.           PDLISP language manual          PDLISP Directory Structure
  5167.           
  5168.  
  5169.  
  5170.  
  5171.  
  5172.             PDLISP provides a  facility  for  customizing  the prompt
  5173.           which is  printed in the top-level loop of the interpreter. 
  5174.           In  the file dirlib.l, the prompt is  set  up  so  that  the
  5175.           interpreter prints out the directory on the top-level prompt
  5176.           line.  For example, if the user  were  in /SYS/CMD, then the
  5177.           interpreter would print out
  5178.  
  5179.  
  5180.           /SYS/CMD->
  5181.  
  5182.           as the top level prompt.  For more information about setting
  5183.           your  own  prompt  function,  consult  the  chapter on  hook
  5184.           functions. 
  5185.  
  5186.  
  5187.  
  5188.  
  5189.           6.2 Creating Directories
  5190.  
  5191.  
  5192.             In PDLISP, directories are a type of symbol.  Directories
  5193.           are  created  by the MD and MDQ functions.   MD  stands  for
  5194.           "make  directory",  and  it  creates  a  new  one.   MDQ  is
  5195.           identical, except that it quotes its argument.  For example,
  5196.           the expression (MDQ RUDOLF)  would  create  a  new directory
  5197.           called rudolf. 
  5198.  
  5199.             The functions CD and CDQ change the current directory.  CD
  5200.           stands for "change  directory".  For example, the expression
  5201.           (CD 'RUDOLF)  would  change  the current directory to be the
  5202.           directory  rudolf.   In  this  example,  rudolf  must  be  a
  5203.           directory  symbol  in the current directory, because we  did
  5204.           not specify a complete  pathname.   That is, directory names
  5205.           which  do  not  begin with /  (which  stands  for  the  root
  5206.           directory), are assumed by the reader to be  sub-directories
  5207.           of  the  current  directory.   This  saves a lot of  typing,
  5208.           because in most cases, only the 'tail' of the directory name
  5209.           has to be typed. 
  5210.  
  5211.             In  the following dialogue, a subdirectory of the  current
  5212.           directory is created, and it is made the current directory:
  5213.  
  5214.  
  5215.  
  5216.  
  5217.  
  5218.  
  5219.  
  5220.  
  5221.  
  5222.  
  5223.  
  5224.                                      - 74 -               Version 1.10
  5225.           
  5226.  
  5227.  
  5228.  
  5229.  
  5230.  
  5231.  
  5232.           PDLISP language manual          PDLISP Directory Structure
  5233.           
  5234.  
  5235.  
  5236.  
  5237.  
  5238.  
  5239.           /USR/LOGIN->(mdq rudolf)    ;make directory RUDOLF
  5240.           RUDOLF                      ;last segment of the path-name
  5241.           /USR/LOGIN->(cdq rudolf)    ;go to it
  5242.           RUDOLF                      ;value returned by CDQ
  5243.           /USR/LOGIN/RUDOLF->         ;PDLISP prompt reflects
  5244.                                       ;the new current directory.
  5245.  
  5246.           At the conclusion of the above dialogue,  the PDLISP prompt
  5247.           line  contains  '/USR/LOGIN/RUDOLF',  whereas  formerly   it
  5248.           contained the  string  '/USR/LOGIN'. This change will remain
  5249.           in  effect until the current  directory  is  changed  to  be
  5250.           something else. 
  5251.  
  5252.             At  this  point,  some terminology is in  order.   When  a
  5253.           directory is created, it is called a 'child' directory, or a
  5254.           'sub-directory.'  The directory immediately  above  it  (and
  5255.           normally there can only be one such directory) is called its
  5256.           parent. 
  5257.  
  5258.             The  same  terminology  holds  for  normal  symbols.  Each
  5259.           symbol resides in exactly one directory, and that  directory
  5260.           is called its parent. 
  5261.  
  5262.             The  commands  MCD and  MCDQ  are  similar  to  the  above
  5263.           functions, but they combine  the  MD  and MDQ functions with
  5264.           the CD  and  CDQ functions.  MCD stands for "make and change
  5265.           current  directory".   For  example, we could  compress  the
  5266.           above dialogue into the following:
  5267.  
  5268.  
  5269.           /USR/LOGIN->(mcdq rudolf)   ;make rudolf
  5270.           RUDOLF                      ;value returned from MCDQ
  5271.           /USR/LOGIN/RUDOLF->         ;PDLISP prompt is changed, too.
  5272.  
  5273.  
  5274.  
  5275.  
  5276.           6.3 The $ and $$ symbols
  5277.  
  5278.  
  5279.             Quite often, the PDLISP programmer will want  to refer to
  5280.           the  current  directory  and   the  parent  of  the  current
  5281.           directory.  Some  special  machinery  has  been provided for
  5282.           this  purpose.  Whenever PDLISP  creates  a  directory,  it
  5283.           automatically   installs  two  special   symbols   in   that
  5284.           directory.  These  symbols  are named "$" and "$$", and they
  5285.           correspond to the "." and ".." files under  UNIX  and MS-DOS
  5286.           (or PC-DOS). The $ symbol is bound to  its parent directory,
  5287.  
  5288.  
  5289.  
  5290.                                      - 75 -               Version 1.10
  5291.           
  5292.  
  5293.  
  5294.  
  5295.  
  5296.  
  5297.  
  5298.           PDLISP language manual          PDLISP Directory Structure
  5299.           
  5300.  
  5301.  
  5302.  
  5303.           and the $$ symbol is bound to the parent of its parent. 
  5304.  
  5305.             For  example,  the expression (cd $$) changes the  current
  5306.           directory  to  be the parent of the current directory.  Note
  5307.           that we used the unquoted form of the  CD function here - we
  5308.           want to go to the  value of $$, and so we want the evaluator
  5309.           to evaluate $$.
  5310.  
  5311.             A  useful  side-effect  of  the  way  that PDLISP  stores
  5312.           directory information is that the value  of a directory is a
  5313.           list  of  the  symbols  which  are  in that directory.   For
  5314.           example, the value of the root directory upon boot-up is the
  5315.           list (SYS USR ). Since we can get the value of any  variable
  5316.           simply by evaluating it, we could type:
  5317.  
  5318.  
  5319.           /USR/LOGIN->/           ;Get the value of the root directory.
  5320.           (SYS USR )              ;The value is always a list (or NIL).
  5321.           /USR/LOGIN->$           ;We can also get the name of the
  5322.           LOGIN                   ;  current directory by evaluating $
  5323.           /USR/LOGIN->(eval $)
  5324.           ($ $$ RUDOLF TEST)      ;RUDOLF and TEST are its children
  5325.           /USR/LOGIN->$$          ;Same for parent of current directory
  5326.           USR                     ;value of parent
  5327.           /USR/LOGIN->(eval $$)   ;evaluating parent of current directory
  5328.           ($ $$ LOGIN)            ;gives names of symbols in it.
  5329.  
  5330.  
  5331.  
  5332.  
  5333.           6.4 PARENT and PARENTQ functions
  5334.  
  5335.  
  5336.             The function PARENT returns  the  parent  directory of its
  5337.           argument.   PARENTQ  is an equivalent function which  quotes
  5338.           its argument.  The expression (PARENTQ $) would evaluate  to
  5339.           the parent of the current directory.  For example:
  5340.  
  5341.  
  5342.           /USR/LOGIN->(parentq $)     ;get parent of current directory.
  5343.           USR                         ;value returned.
  5344.           /USR/LOGIN->$$              ;same thing.
  5345.           USR                         ;same value returned.
  5346.  
  5347.           The  actual  results  which  you  obtain  may be  different,
  5348.           depending upon where you are on the directory  tree and what
  5349.           sub-directories you have created. 
  5350.  
  5351.  
  5352.  
  5353.  
  5354.  
  5355.  
  5356.                                      - 76 -               Version 1.10
  5357.           
  5358.  
  5359.  
  5360.  
  5361.  
  5362.  
  5363.  
  5364.           PDLISP language manual          PDLISP Directory Structure
  5365.           
  5366.  
  5367.  
  5368.  
  5369.  
  5370.  
  5371.  
  5372.  
  5373.           6.5 The Reader Search Path
  5374.  
  5375.  
  5376.             The reader is the part  of  the  interpreter  which  reads
  5377.           s-expressions in from the  console  or  a  file.  Basically,
  5378.           when the reader reads  an  symbol  name,  it  must determine
  5379.           whether the name refers to a new  object  or  to  one  which
  5380.           already  exists in the object list.  If the  object  already
  5381.           exists, then the reader  returns  a pointer to that object. 
  5382.           If  the object does not exist, then the reader constructs  a
  5383.           new object  (in the current directory) and returns a pointer
  5384.           to it. 
  5385.  
  5386.             In determining if an object exists in the object list, the
  5387.           reader selectively searches the  object  list  along what is
  5388.           called the reader search path.  This  search  path is just a
  5389.           list  of directories to be  searched  by  the  reader.   The
  5390.           search always starts first in the current directory.  If the
  5391.           symbol  cannot  be  found in that directory, then the search
  5392.           continues with the first directory in the reader search path
  5393.           and proceeds down to the end of the  list.   If  the  symbol
  5394.           still cannot be found,  then  it  is  built  in  the current
  5395.           directory. 
  5396.  
  5397.             This  search  path is user-configurable using the function
  5398.           STATUS. for example,
  5399.  
  5400.  
  5401.           /USR/LOGIN-> (STATUS reader_search_path '(/usr/lib /sys/cmd)))
  5402.  
  5403.           would set up the reader search path so that the reader first
  5404.           looks in the current directory (whatever  that may be), then
  5405.           the directory /USR/LIB,  and finally the directory /SYS/CMD.
  5406.           If  the  symbol  name  cannot  be  found  in  any  of  those
  5407.           directories, then a new symbol is  created  in  the  current
  5408.           directory.  (STATUS reader_search_path) returns  the current
  5409.           value of the reader search path. 
  5410.  
  5411.             More elaborate functions for  accessing  and  manipulating
  5412.           the reader search path are described in the function summary
  5413.           at the end of this chapter.  In particular, see ADD-TO-PATH,
  5414.           GETPATH, POPPATH, PUSHPATH, REMOVE-FROM-PATH, and SETPATH.
  5415.  
  5416.  
  5417.  
  5418.  
  5419.  
  5420.  
  5421.  
  5422.                                      - 77 -               Version 1.10
  5423.           
  5424.  
  5425.  
  5426.  
  5427.  
  5428.  
  5429.  
  5430.           PDLISP language manual          PDLISP Directory Structure
  5431.           
  5432.  
  5433.  
  5434.  
  5435.  
  5436.  
  5437.  
  5438.  
  5439.           6.6 Directory Prefixes
  5440.  
  5441.  
  5442.             PDLISP   accepts   certain   abreviations   for   certain
  5443.           directories so as to minimize typing. 
  5444.  
  5445.           
  5446.  
  5447.  
  5448.           6.6.1 The Current Directory Prefix
  5449.  
  5450.           Preceeding a symbol's  name by the underscore (_) will force
  5451.           it to be in the present directory.  This can be particularly
  5452.           useful if a long reader search path has been specified. 
  5453.  
  5454.             STATUS also  allows the user to examine and modify the the
  5455.           behavior of the system with regard to the printing of symbol
  5456.           names.  Invoking (STATUS DIRECTORY_PREFIX T) causes  PDLISP
  5457.           to  enter a mode whereby it will print out the names of  all
  5458.           symbols  which  are  in   the   current  directory  with  an
  5459.           underscore  prefix.   If  (STATUS DIRECTORY_PREFIX NIL)   is
  5460.           invoked, then no  symbol  names  will  be  printed  with  an
  5461.           underscore prefix. 
  5462.  
  5463.             Throughout the rest of this chapter, the underscore prefix
  5464.           will be printed as if  (STATUS DIRECTORY_PREFIX T)  had been
  5465.           invoked. 
  5466.  
  5467.  
  5468.           6.6.2 The Directory Suffix
  5469.  
  5470.             Whenever PDLISP prints out the name of an symbol which is
  5471.           a directory, it appends a slash (/) at the end of the name. 
  5472.           This is in order  to  facilitate identification of directory
  5473.           structure   without  having  to  invoke  a  special  utility
  5474.           function.  For example, if we had a  directory  symbol named
  5475.           "CMD", then the system would output its name as "CMD/".
  5476.  
  5477.  
  5478.  
  5479.  
  5480.  
  5481.  
  5482.  
  5483.  
  5484.  
  5485.  
  5486.  
  5487.  
  5488.                                      - 78 -               Version 1.10
  5489.           
  5490.  
  5491.  
  5492.  
  5493.  
  5494.  
  5495.  
  5496.           PDLISP language manual          PDLISP Directory Structure
  5497.           
  5498.  
  5499.  
  5500.  
  5501.  
  5502.  
  5503.  
  5504.  
  5505.           6.7 The DIR Function
  5506.  
  5507.  
  5508.             In order to view the contents  of  the  current directory,
  5509.           the  DIR  function  has   been  provided  in  the  the  file
  5510.           dirlib.l.  For example, if the current directory were empty,
  5511.           then the following dialog would occur:
  5512.  
  5513.  
  5514.           /USR/LOGIN->(dir)
  5515.           (_$ _$$)            ;symbols in current directory
  5516.  
  5517.  
  5518.  
  5519.  
  5520.           6.8 The LQ function
  5521.  
  5522.  
  5523.             LQ is  similar  to  DIR,  except  that its display is more
  5524.           elaborate.  LQ  takes one optional argument, which must be a
  5525.           directory  symbol,  and  displays a line of information  for
  5526.           each symbol in that directory.  If the directory argument is
  5527.           not present,  then  the  current  directory  is assumed as a
  5528.           default.  For example, in the following dialog, we  create a
  5529.           new directory called /USR/LOGIN/STUFF, and load some symbols
  5530.           into in from a file called  "examples.l",  which  is  on the
  5531.           distribution disk. 
  5532.  
  5533.  
  5534.  
  5535.  
  5536.  
  5537.  
  5538.  
  5539.  
  5540.  
  5541.  
  5542.  
  5543.  
  5544.  
  5545.  
  5546.  
  5547.  
  5548.  
  5549.  
  5550.  
  5551.  
  5552.  
  5553.  
  5554.                                      - 79 -               Version 1.10
  5555.           
  5556.  
  5557.  
  5558.  
  5559.  
  5560.  
  5561.  
  5562.           PDLISP language manual          PDLISP Directory Structure
  5563.           
  5564.  
  5565.  
  5566.  
  5567.  
  5568.  
  5569.           /USR/LOGIN->(mcdq stuff)
  5570.           T
  5571.           /USR/LOGIN/STUFF->(lq stuff)    ;let's look at the new directory.
  5572.           _$              -v ---          ;_$ is setq'd to this directory
  5573.           _$$             -v ---          ;_$$ is setq'd to parent directory
  5574.           T
  5575.           ;
  5576.           ;now to load some clutter
  5577.           ;
  5578.           /USR/LOGIN/STUFF->(loadv "examples.l")
  5579.           RFIB                          ;LOADV echoes the name of each
  5580.           IPOWER                        ;function as it is read.
  5581.           IFACT                         ;
  5582.  
  5583.           ...                           ;etc.
  5584.  
  5585.           T                             ;LOADV returns a value of T.
  5586.           /USR/LOGIN/STUFF->(lq)        ;let's lq it.
  5587.           _$              -v ---        ;_$ is bound as a variable
  5588.           _$$             -v ---        ;... as is _$$
  5589.           _APP            -v LAMBDA     ;_APP is a LAMBDA - function
  5590.           _COUNT          -v ---        ;_COUNT is not bound as anything.
  5591.           _EXPONENT       -v ---        ;etc.
  5592.  
  5593.           ...                           ;and so on down the list.
  5594.                                         ;until finally LQ returns
  5595.           T                             ; its own value.
  5596.           /USR/LOGIN/STUFF->            ;back to standard prompt.
  5597.  
  5598.           Of  course, the actual contents of any particular  directory
  5599.           might be different depending upon the present  configuration
  5600.           of  your  system.  For example, if you had previously loaded
  5601.           in the file "examples.l"  somewhere  else  in your directory
  5602.           tree, and that directory  was  on the reader search path for
  5603.           your  system,  then  /USR/LOGIN/STUFF  might  wind up  being
  5604.           empty, even if  you  loaded in the file a second time.  This
  5605.           might happen because the  reader  would  assume  that it had
  5606.           already read in  the  symbols  in the file, so that it would
  5607.           not construct any new  symbols.  The surest way to prevent a
  5608.           mistake like this from happening is  to  constantly look for
  5609.           the  underscore  prefix  which  the  interpreter  prints out
  5610.           before symbols which are in the current directory.   If  the
  5611.           underscore isn't there, then you can safely  assume that the
  5612.           symbol is not in your current directory. 
  5613.  
  5614.  
  5615.  
  5616.  
  5617.  
  5618.  
  5619.  
  5620.                                      - 80 -               Version 1.10
  5621.           
  5622.  
  5623.  
  5624.  
  5625.  
  5626.  
  5627.  
  5628.           PDLISP language manual          PDLISP Directory Structure
  5629.           
  5630.  
  5631.  
  5632.  
  5633.           6.9 Global and Local Symbols
  5634.  
  5635.  
  5636.             PDLISP  provides  a facility whereby symbols can be  made
  5637.           invisible to  the  system reader when the directory to which
  5638.           they belong is not the current directory.  Symbols which are
  5639.           visible to the reader outside  of  their  own  directory are
  5640.           called  global  symbols.   Symbols  which  are  not  visible
  5641.           outside of their own directory are called local symbols. 
  5642.  
  5643.             As a practical example, suppose that we  are  currently in
  5644.           the directory  /USR/LOGIN.  Furthermore,  assume  that there
  5645.           exists  in  the directory /SYS/CMD a symbol called FOO,  and
  5646.           that /SYS/CMD is on the reader  search  path  (as is usually
  5647.           the case).  If FOO were a  local  symbol,  then  we would be
  5648.           unable to access it, as illustrated below:
  5649.  
  5650.  
  5651.           /USR/LOGIN->foo             ;get foo's value
  5652.           ***> EVAL: variable FOO is unbound.
  5653.           /USR/LOGIN->(setq foo 4)    ;set foo to something
  5654.           4                           ;did we succeed ?
  5655.           ;
  5656.           ; let's look at the current directory:
  5657.           ;
  5658.           /USR/LOGIN->(lq)
  5659.           $           -v  ---
  5660.           $$          -v  ---
  5661.           FOO         -v  ---
  5662.           T
  5663.  
  5664.           Not only were we unable to get FOO's value, but we could not
  5665.           set it to a value, either.  All that we accomplished was the
  5666.           creation of a new symbol, also  called  FOO,  in the current
  5667.           directory, instead of the alteration of /SYS/CMD/FOO.
  5668.  
  5669.             None of this  should  be  mysterious once the operation of
  5670.           the reader is understood; when the  name  FOO  was  read in,
  5671.           first  the current directory (/USR/LOGIN) was scanned for  a
  5672.           symbol named FOO. Since FOO did not yet exist in /USR/LOGIN,
  5673.           each of the  directories  along  the reader search path were
  5674.           scanned.   Since  /SYS/CMD/FOO was not a global symbol,  the
  5675.           reader  did  not find it, and so a new symbol named FOO  was
  5676.           created in /USR/LOGIN. The full path-name of this new symbol
  5677.           is /USR/LOGIN/FOO.
  5678.  
  5679.             Now let's suppose that  a global symbol named /SYS/CMD/FOO
  5680.           exists.  Using LQ, we might see:
  5681.  
  5682.  
  5683.  
  5684.  
  5685.  
  5686.                                      - 81 -               Version 1.10
  5687.           
  5688.  
  5689.  
  5690.  
  5691.  
  5692.  
  5693.  
  5694.           PDLISP language manual          PDLISP Directory Structure
  5695.           
  5696.  
  5697.  
  5698.  
  5699.           /USR/LOGIN->(lq /sys/cmd)
  5700.  
  5701.           (lots of symbols)
  5702.  
  5703.           ...
  5704.  
  5705.           FOO         gv  ---
  5706.  
  5707.           ...
  5708.  
  5709.           (many more symbols)
  5710.  
  5711.           T                       ;value of LQ
  5712.  
  5713.           The 'g' in the  column  immediately  after the symbol's name
  5714.           indicates  that  FOO  is a global symbol.  We should now  be
  5715.           able to access it from within /USR/LOGIN.
  5716.  
  5717.  
  5718.           /USR/LOGIN->(setq foo 4)
  5719.           4
  5720.           /USR/LOGIN->foo         ;let's get the value of foo
  5721.           4                       ;foo bound as 4
  5722.           /USR/LOGIN->(lq)        ;is foo in the current directory?
  5723.           $           -v  ---
  5724.           $$          -v  ---
  5725.           T                       ;apparently not.
  5726.  
  5727.           All  symbols  (except   directories,  as  noted  below)  are
  5728.           ordinarily local  when  they  are created by the reader.  In
  5729.           order to make a  symbol  global,  one  must  use  the GLOBAL
  5730.           function.  Usually, this takes  the form of a statement near
  5731.           the beginning of the file in  which  the symbol is defined. 
  5732.           For example, we might write:
  5733.  
  5734.  
  5735.           (global 'foo 'bar 'baz)
  5736.  
  5737.           where FOO,  BAR,  and BAZ are symbols which are created when
  5738.           the  file  is read in by the system.  It should  be  obvious
  5739.           that  the GLOBAL function can only be used when the  symbols
  5740.           being  made global are in the current directory;  otherwise,
  5741.           of  course, the PDLISP reader will prevent  us  from  being
  5742.           able to refer to them. 
  5743.  
  5744.             As noted above, all  symbols  (except for directories) are
  5745.           by  default  local  symbols  when  they  are created by  the
  5746.           reader.  In order to  be visible outside of the directory in
  5747.           which they are created,  the  GLOBAL function must be used. 
  5748.           Otherwise, when a directory is created  with  the  MD,  MDQ,
  5749.  
  5750.  
  5751.  
  5752.                                      - 82 -               Version 1.10
  5753.           
  5754.  
  5755.  
  5756.  
  5757.  
  5758.  
  5759.  
  5760.           PDLISP language manual          PDLISP Directory Structure
  5761.           
  5762.  
  5763.  
  5764.  
  5765.           MCD,  or MCDQ functions, it is by default made into a global
  5766.           symbol;  directories  can  be   made  local  via  the  LOCAL
  5767.           function. 
  5768.  
  5769.           
  5770.  
  5771.  
  5772.  
  5773.  
  5774.           6.10 RM and RMQ
  5775.  
  5776.  
  5777.             Oftentimes,  a  programmer  will  inadvertantly  create  a
  5778.           symbol  in  the  current  directory  when  he  or   she  was
  5779.           attempting to address one  in another directory.  This might
  5780.           happen,  for  example, if the PDLISP reader could not  find
  5781.           the  named  symbol  along  the  reader  search  path.    For
  5782.           occaisions such as this,  the RM and RMQ functions have been
  5783.           provided.  RM and RMQ have as their effect  the  removal  of
  5784.           any symbols  passed  to  them  from  the  object  list.  For
  5785.           example, we could type:
  5786.  
  5787.  
  5788.           /USR/LOGIN->(RM '_RED '_BLUE '_YELLOW)
  5789.  
  5790.           and that  would have the effect of removing the symbols RED,
  5791.           BLUE,   and  YELLOW  from  the  current  directory.   As   a
  5792.           precautionary  measure,  these  functions  are incapable  of
  5793.           removing symbols which are  not  in  the current directory. 
  5794.           For  example,  suppose  that we attempted to remove a symbol
  5795.           named  GREEN  from  a directory other than the current one. 
  5796.           This would result in an error message:
  5797.  
  5798.  
  5799.           /USR/LOGIN->(RMQ GREEN)
  5800.           ***> RM or RMQ: symbol GREEN not in current directory
  5801.           NIL
  5802.  
  5803.  
  5804.  
  5805.  
  5806.  
  5807.  
  5808.  
  5809.  
  5810.  
  5811.  
  5812.  
  5813.  
  5814.  
  5815.  
  5816.  
  5817.  
  5818.                                      - 83 -               Version 1.10
  5819.           
  5820.  
  5821.  
  5822.  
  5823.  
  5824.  
  5825.  
  5826.           PDLISP language manual          PDLISP Directory Structure
  5827.           
  5828.  
  5829.  
  5830.  
  5831.  
  5832.  
  5833.  
  5834.  
  5835.           6.11 RMDIR and RMDIRQ
  5836.  
  5837.  
  5838.           For safety reasons, RM  and  RMQ  are  incapable of removing
  5839.           symbols which are directory  symbols.  For this purpose, the
  5840.           RMDIR   and   RMDIRQ   functions   have   been    provided. 
  5841.           (RMDIR SOMEDIR) will remove  a  directory named SOMEDIR from
  5842.           the  current  directory.  RMDIRQ  is  similar  in  function,
  5843.           except that it quotes its argument. 
  5844.  
  5845.  
  5846.  
  5847.  
  5848.           6.12 PD, PDQ, and POPD
  5849.  
  5850.  
  5851.           These  functions allow a  programmer  to  move  through  the
  5852.           directory  hierarchy  while  leaving   a   "thread"   behind
  5853.           himself.  Later  on, the programmer can "pop" back along the
  5854.           thread.  PD  and  PDQ  change the working directory to a new
  5855.           one, and save the current directory on a "stack." POPD  pops
  5856.           the  directory stack, restoring  the  previous  entry.   For
  5857.           example:
  5858.  
  5859.  
  5860.           /USR/LOGIN->(pdq /sys/cmd)  ;pdq quotes its argument.
  5861.           CMD/                        ;new directory returned as value.
  5862.           /SYS/CMD->(popd)            ;let's pop back along the thread.
  5863.           LOGIN/                      ;we're back in /USR/LOGIN.
  5864.           /USR/LOGIN->                ;prompt indicates new directory.
  5865.  
  5866.  
  5867.  
  5868.  
  5869.  
  5870.  
  5871.  
  5872.  
  5873.  
  5874.  
  5875.  
  5876.  
  5877.  
  5878.  
  5879.  
  5880.  
  5881.  
  5882.  
  5883.  
  5884.                                      - 84 -               Version 1.10
  5885.           
  5886.  
  5887.  
  5888.  
  5889.  
  5890.  
  5891.  
  5892.           PDLISP language manual          PDLISP Directory Structure
  5893.           
  5894.  
  5895.  
  5896.  
  5897.  
  5898.  
  5899.  
  5900.  
  5901.           6.13 Common Mistakes when Using Directories
  5902.  
  5903.  
  5904.             As with any  mousetrap,  directories can snap at the wrong
  5905.           time.  The most common error entails the creation of symbols
  5906.           in different  directories  with  duplicate print-names.  Two
  5907.           distinct  symbols cannot have identical path-names;  however
  5908.           they can have identical  print-names,  which  correspond  to
  5909.           last segment of the path name.  For example, suppose that we
  5910.           have two symbols, /USR/LOGIN/FOO/BAR and /USR/LOGIN/BAZ/BAR.
  5911.           The two symbols do not have  the  same path-names, but their
  5912.           print-names  are  both  "bar", since ordinarily this is  the
  5913.           only part of the path-name which is printed out. 
  5914.  
  5915.             Now, suppose that we  are currently in /USR/LOGIN/FOO, and
  5916.           that  we  wish  to  refer  to  /USR/LOGIN/BAZ/BAR.  If,  for
  5917.           example, we typed
  5918.  
  5919.  
  5920.           /USR/LOGIN/FOO->(setq bar 4)
  5921.           4
  5922.  
  5923.           One might imagine that we had  set  /USR/LOGIN/FOO/BAR to 4.
  5924.           In  reality,  we  may  simply  have  created  a  new symbol,
  5925.           /USR/LOGIN/FOO/BAR, and SETQ'd it  to  4.  This  might  have
  5926.           occurred for any of several reasons. 
  5927.  
  5928.  
  5929.           (1) USR/LOGIN/BAZ had not been installed on the reader's
  5930.               search path. The reader cannot refer to symbols which
  5931.               are not in the current directory or on the search path.
  5932.  
  5933.           (2) /USR/LOGIN/BAS/FOO had never been declared a global
  5934.               symbol, the GLOBAL function. Symbols which are not global
  5935.               are not visible to the reader unless they happen to reside
  5936.               in the current directory.
  5937.  
  5938.           (3) /USR/LOGIN/BAR/FOO had been created by mistake due to
  5939.               (1) or (2), above, and the user never became aware of
  5940.               its existence. Since the reader always looks first
  5941.               in the current directory, /USR/LOGIN/BAZ/FOO is
  5942.               effectively "shadowed" by /USR/LOGIN/BAR/FOO.
  5943.               The remedy in this case is to remove /USR/LOGIN/BAR/FOO
  5944.               by using the RMQ command, as follows:
  5945.  
  5946.  
  5947.  
  5948.  
  5949.  
  5950.                                      - 85 -               Version 1.10
  5951.           
  5952.  
  5953.  
  5954.  
  5955.  
  5956.  
  5957.  
  5958.           PDLISP language manual          PDLISP Directory Structure
  5959.           
  5960.  
  5961.  
  5962.  
  5963.  
  5964.           /USR/LOGIN/BAR->(rmq foo)
  5965.           T
  5966.  
  5967.  
  5968.  
  5969.  
  5970.           6.14 Functional Directories
  5971.  
  5972.  
  5973.           Functional directories  are symbols which are simultaneously
  5974.           defined as functions and  as  directories.   They are useful
  5975.           for  "hiding" local symbols inside of functions so that  the
  5976.           object list doesn't get cluttered up with junk. 
  5977.  
  5978.             For  example,  suppose  that we wish to  build  a  utility
  5979.           called "superfoo", and that we wish to put  it in /SYS/CMD/.
  5980.           We would start by creating a  new  directory and changing to
  5981.           it, as follows:
  5982.  
  5983.  
  5984.           /USR/LOGIN->(cdq /sys/cmd)      ;move over to /sys/cmd
  5985.           CMD/
  5986.           /SYS/CMD->(mdq superfoo)        ;make new directory
  5987.           SUPERFOO/
  5988.           /SYS/CMD->(cdq superfoo)        ;change to it
  5989.           SUPERFOO/
  5990.           /SYS/CMD/SUPERFOO->             ;now in superfoo
  5991.  
  5992.           At this point, we can define superfoo as  a  function  using
  5993.           the DEF$ function as follows:
  5994.  
  5995.  
  5996.           ;
  5997.           ; define $ as a lambda:
  5998.           ;
  5999.           /SYS/CMD/SUPERFOO->(def$ (lambda (x y) (+ x y)))
  6000.           SUPERFOO/
  6001.  
  6002.           If  we  were to examine the current directory at this  point
  6003.           using LQ, we  would  find X and Y interned as local symbols,
  6004.           as follows:
  6005.  
  6006.  
  6007.           /SYS/CMD/SUPERFOO->(lq)
  6008.           $                       -- LAMBDA
  6009.           $$                      -- LAMBDA
  6010.           X                       -- ---
  6011.           Y                       -- ---
  6012.  
  6013.  
  6014.  
  6015.  
  6016.                                      - 86 -               Version 1.10
  6017.           
  6018.  
  6019.  
  6020.  
  6021.  
  6022.  
  6023.  
  6024.           PDLISP language manual          PDLISP Directory Structure
  6025.           
  6026.  
  6027.  
  6028.  
  6029.             When working  with functional directories, one should keep
  6030.           in mind that $ is not  the  current  directory itself; it is
  6031.           only a variable which is bound to the current directory.  We
  6032.           could have obtained the same result in the  above example by
  6033.           saying:
  6034.  
  6035.  
  6036.           /SYS/CMD/SUPERFOO->(def (eval $) (lambda (x y) (+ x y)))
  6037.  
  6038.           The call to EVAL inside the call to DEF is necessary because
  6039.           DEF does not evaluate its arguments, and we  want  the value
  6040.           of $, not $ itself. 
  6041.  
  6042.           
  6043.  
  6044.  
  6045.  
  6046.  
  6047.           6.15 Summary of Directory Management Functions
  6048.  
  6049.  
  6050.           These functions deal with the PDLISP directory structure. 
  6051.  
  6052.  
  6053.           ADD-TO-PATH         LAMBDA      (NEWDIR)
  6054.  
  6055.               If NEWDIR is not already on the reader's search path,
  6056.           then this function adds it. Otherwise, nothing happens.
  6057.           In either case, the new reader search path is returned.
  6058.  
  6059.  
  6060.           CD                  CSUBR       (NEWDIR)
  6061.  
  6062.               Stands for "Change Directory." The current directory is
  6063.           changed to the value of NEWDIR. NEWDIR must evaluate to a
  6064.           symbol, or an error results.
  6065.  
  6066.  
  6067.           CDQ                 NLAMBDA     (NEWDIR)
  6068.  
  6069.               Similar to CD, except that it quotes (i.e., does not
  6070.           evaluate) its argument.
  6071.  
  6072.  
  6073.           DEF$                CNSUBR      (Y)
  6074.           
  6075.           Sets the function definition cell of the current directory
  6076.           to Y, which is not evaluated. This function is equivalent to
  6077.           saying (DEF $ Y), where $ is the current directory during the
  6078.           evaluation of this function.  Use of this function makes the
  6079.  
  6080.  
  6081.  
  6082.                                      - 87 -               Version 1.10
  6083.           
  6084.  
  6085.  
  6086.  
  6087.  
  6088.  
  6089.  
  6090.           PDLISP language manual          PDLISP Directory Structure
  6091.           
  6092.  
  6093.  
  6094.  
  6095.           current directory a functional directory, which is a
  6096.           short-hand way of saying that it is defined as both a
  6097.           function and as a directory. The function is defined using
  6098.           the symbol's function definition cell, and the directory
  6099.           value is defined using its value cell. The value returned
  6100.           by this function is the current directory.
  6101.  
  6102.  
  6103.           DIR                 LAMBDA      (&optional SOMEDIR)
  6104.  
  6105.           This is a primitive directory listing function. DIR returns
  6106.           the value of SOMEDIR, which must be a directory. This value
  6107.           is a list of all of the symbols (user-defined atoms) which
  6108.           reside in the directory. If SOMEDIR is absent, then the value
  6109.           of the present directory is returned.
  6110.  
  6111.  
  6112.           DIRQ                NLAMBDA     (&optional SOMEDIR)
  6113.  
  6114.           Identical to DIR, except that SOMEDIR is quoted.
  6115.  
  6116.  
  6117.           GETPATH             LAMBDA         ()
  6118.  
  6119.                GETPATH returns the current value of the reader search
  6120.           path. For example,
  6121.  
  6122.           /USR/LOGIN->(getpath)
  6123.           (CMD/ CONST/)
  6124.  
  6125.                The slashes after CMD and CONST, of course, indicate
  6126.           that they are directories.
  6127.  
  6128.  
  6129.           GLOBAL              CSUBR       (X)
  6130.  
  6131.           Makes X, which must be a user-defined symbol, a global
  6132.           symbol. Global symbols can be found by the reader even if
  6133.           they are not in the current directory, as long as they are in
  6134.           a directory which lies along the reader search path.
  6135.  
  6136.  
  6137.           GLOBALP             CSUBR       (X)
  6138.  
  6139.           Returns T if X is a global symbol; otherwise returns NIL.
  6140.  
  6141.  
  6142.           LOCAL               CSUBR       (X)
  6143.  
  6144.           Makes X, which must be a symbol (user-defined atom), a local
  6145.  
  6146.  
  6147.  
  6148.                                      - 88 -               Version 1.10
  6149.           
  6150.  
  6151.  
  6152.  
  6153.  
  6154.  
  6155.  
  6156.           PDLISP language manual          PDLISP Directory Structure
  6157.           
  6158.  
  6159.  
  6160.  
  6161.           symbol. Local symbols are only visible to the PDLISP reader
  6162.           if they  reside in the current directory; otherwise, the
  6163.           symbol is invisible, even if it resides in a directory on the
  6164.           reader search path. See SETASP, GLOBAL, LOCALP, GLOBALP.
  6165.  
  6166.  
  6167.           LOCALP              CSUBR       (X)
  6168.  
  6169.           Returns T if X is a private symbol; otherwise returns NIL.
  6170.           See LOCAL, GLOBAL, GLOBALP.
  6171.  
  6172.  
  6173.           LQ                  NLAMBDA     (&OPTIONAL DIRECTORY)
  6174.  
  6175.  
  6176.               Prints out a listing of the symbols in DIRECTORY, with a
  6177.           line of information about each one. DIRECTORY is optional,
  6178.           and defaults to the current directory. The information is
  6179.           printed out in 3 columns, as follows:
  6180.  
  6181.               Column 1 is the name of the symbol. If the underscore
  6182.           prefix  is set, as is the case with the distributed system,
  6183.           then all of the symbols are printed out with a leading
  6184.           underscore.
  6185.  
  6186.               Column 2 pertains to the variable or directory binding of
  6187.           the symbol. If the symbol is a global symbol, then the letter
  6188.           "g" is output. Otherwise, a dash ("-") is output. Immediately
  6189.           following, if the symbol is bound as a variable, then the
  6190.           letter "v" is output. If the symbol is bound as a directory,
  6191.           then the letter "d" are output. Otherwise, a dash is output.
  6192.  
  6193.               Column 3 pertains to the functional binding of
  6194.           the symbol. If the symbol is bound as a function, then
  6195.           the type (or "discipline") of the function declaration
  6196.           is shown. The possible values are: CSUBR, CNSUBR, SUBR,
  6197.           NSUBR, LAMBDA, NLAMBDA, and MACRO. For an explanation
  6198.           of each type, consult the beginning of this section.
  6199.  
  6200.               As an example, suppose that we typed in the following:
  6201.  
  6202.           /USR/LOGIN->(lq /sys/cmd)
  6203.  
  6204.           $               -v ---
  6205.           $$              -v ---
  6206.           %               g- CSUBR
  6207.           *               g- CSUBR
  6208.           *BACKQUOTE1     g- LAMBDA
  6209.           ...
  6210.  
  6211.  
  6212.  
  6213.  
  6214.                                      - 89 -               Version 1.10
  6215.           
  6216.  
  6217.  
  6218.  
  6219.  
  6220.  
  6221.  
  6222.           PDLISP language manual          PDLISP Directory Structure
  6223.           
  6224.  
  6225.  
  6226.  
  6227.           (many more functions and variables)
  6228.  
  6229.           ...
  6230.  
  6231.           T                   ; until finally lq returns T as its value.
  6232.  
  6233.           MCD                 CSUBR       (X)
  6234.  
  6235.           Stands for "Make and Change Directory."  This function is
  6236.           equivalent to (CD (MD X)).
  6237.  
  6238.  
  6239.           MCDQ                CSUBR       (X)
  6240.  
  6241.           Same as MCD, except that it does not evaluate its argument.
  6242.           This function is equivalent to (CD (MDQ X)).
  6243.  
  6244.  
  6245.           MD                  CSUBR       (X)
  6246.  
  6247.           Stands for "Make Directory." The symbol X is created if it
  6248.           did not already exist at read-time, and it is made into a
  6249.           directory if it is not already defined as a variable,
  6250.           function, or something else. No error occurs if X is
  6251.           already defined as a directory. This function returns X if
  6252.           successful, NIL otherwise.
  6253.  
  6254.  
  6255.           MDQ                 CNSUBR      (X)
  6256.  
  6257.           Same as MD, except that the argument is not evaluated.
  6258.  
  6259.  
  6260.           PARENT              CSUBR       (ASYMBOL)
  6261.  
  6262.           Returns the parent directory of ASYMBOL. The parent directory
  6263.           of / (root) is /.
  6264.  
  6265.  
  6266.           PATHLST             CSUBR       (ASYMBOL)
  6267.  
  6268.           Returns a list representing the path-name of ASYMBOL.
  6269.           Each symbol in the list is a directory symbol along the
  6270.           path of the symbol from the root.
  6271.  
  6272.  
  6273.           PATHNME             CSUBR       (ASYMBOL)
  6274.  
  6275.           This function digs out the path-name of ASYMBOL and
  6276.           returns it as a list. For example, if we were currently
  6277.  
  6278.  
  6279.  
  6280.                                      - 90 -               Version 1.10
  6281.           
  6282.  
  6283.  
  6284.  
  6285.  
  6286.  
  6287.  
  6288.           PDLISP language manual          PDLISP Directory Structure
  6289.           
  6290.  
  6291.  
  6292.  
  6293.           in the directory /FOO/BAR, and we wished to get the
  6294.           path-name of /FOO/BAR/BAZ, then we could type:
  6295.  
  6296.           /FOO/BAR->(pathnme 'baz)
  6297.           (FOO BAR BAZ)
  6298.  
  6299.  
  6300.           PATHSTR             CSUBR       (ASYMBOL)
  6301.  
  6302.           This function is similar to PATHNME, above, except that
  6303.           the path-name of ASYMBOL is returned as a string.
  6304.  
  6305.  
  6306.           PD                  LAMBDA      (ASYMBOL)
  6307.  
  6308.           Changes the current directory to be ASYMBOL, and saves
  6309.           the old directory on a stack. The previous directory can
  6310.           be restored by POPD.
  6311.  
  6312.  
  6313.           PDQ                 NLAMBDA     (ASYMBOL)
  6314.  
  6315.           Same as PD, except that its argument is not evaluated.
  6316.           Source is in dirlib.l.
  6317.  
  6318.  
  6319.           POPD                LAMBDA      ()
  6320.  
  6321.           Pops the directory stack. The current directory is changed
  6322.           to whatever was on the top of the directory stack. See PD
  6323.           and PDQ. Source is in dirlib.l.
  6324.  
  6325.  
  6326.           POPPATH             NLAMBDA     ()
  6327.  
  6328.           Pops a directory off the front of the reader-search-path.
  6329.           Source is in dirlib.l. See PUSHPATH.
  6330.  
  6331.  
  6332.           PUSHPATH            LAMBDA      (DIRECTORY)
  6333.  
  6334.           Pushes a directory onto the front of the reader-search-path.
  6335.           The argument must be a directory, or an error is generated.
  6336.           Source is in dirlib.l. See POPPATH.
  6337.  
  6338.  
  6339.           RM                  CSUBR       (X)
  6340.  
  6341.           Stands for ReMove object; the specified object is removed from
  6342.           the PDLISP object list, and if nothing else in the system
  6343.  
  6344.  
  6345.  
  6346.                                      - 91 -               Version 1.10
  6347.           
  6348.  
  6349.  
  6350.  
  6351.  
  6352.  
  6353.  
  6354.           PDLISP language manual          PDLISP Directory Structure
  6355.           
  6356.  
  6357.  
  6358.  
  6359.           points to it, it will be recycled as fresh storage.
  6360.  
  6361.  
  6362.           RMDIR               LAMBDA      (X)
  6363.  
  6364.           Stands for ReMove Directory; the specified directory symbol, X,
  6365.           is removed from the PDLISP object list. If X is present on
  6366.           the reader's search path, it will be deleted from same.
  6367.  
  6368.  
  6369.           RMDIRQ              NLAMBDA     (X)
  6370.  
  6371.           Similar to RMDIR, but quotes its argument.
  6372.  
  6373.  
  6374.           RMQ                 CNSUBR      (X)
  6375.  
  6376.           Similar to RM, but quotes (i.e., does not evaluate) its argument.
  6377.  
  6378.  
  6379.           SETPATH             LAMBDA         (X)
  6380.  
  6381.                SETPATH sets the reader search path to X, and returns the
  6382.           new value. For example,
  6383.  
  6384.           /USR/LOGIN->(setpath '(/usr/fred /sys/cmd /sys/const))
  6385.           (FRED/ CMD/ CONST/)
  6386.           SRMDIR              CSUBR       (X)
  6387.  
  6388.           Stands for System RMDIR; this primitive is called by RMDIR.
  6389.           In general, this function should be avoided in favor of RMDIR
  6390.           or RMDIRQ, since it does not check if the directory to be
  6391.           removed is present on the reader's search path.
  6392.  
  6393.  
  6394.  
  6395.  
  6396.  
  6397.  
  6398.  
  6399.  
  6400.  
  6401.  
  6402.  
  6403.  
  6404.  
  6405.  
  6406.  
  6407.  
  6408.  
  6409.  
  6410.  
  6411.  
  6412.                                      - 92 -               Version 1.10
  6413.           
  6414.  
  6415.  
  6416.  
  6417.  
  6418.  
  6419.  
  6420.           PDLISP language manual          PDLISP Directory Structure
  6421.           
  6422.  
  6423.  
  6424.  
  6425.  
  6426.                        This page intentionally left blank
  6427.  
  6428.  
  6429.  
  6430.  
  6431.  
  6432.  
  6433.  
  6434.  
  6435.  
  6436.  
  6437.  
  6438.  
  6439.  
  6440.  
  6441.  
  6442.  
  6443.  
  6444.  
  6445.  
  6446.  
  6447.  
  6448.  
  6449.  
  6450.  
  6451.  
  6452.  
  6453.  
  6454.  
  6455.  
  6456.  
  6457.  
  6458.  
  6459.  
  6460.  
  6461.  
  6462.  
  6463.  
  6464.  
  6465.  
  6466.  
  6467.  
  6468.  
  6469.  
  6470.  
  6471.  
  6472.  
  6473.  
  6474.  
  6475.  
  6476.  
  6477.  
  6478.                                      - 93 -               Version 1.10
  6479.           
  6480.  
  6481.  
  6482.  
  6483.  
  6484.  
  6485.  
  6486.           PDLISP language manual          PDLISP Directory Structure
  6487.           
  6488.  
  6489.  
  6490.  
  6491.  
  6492.                        This page intentionally left blank
  6493.  
  6494.  
  6495.  
  6496.  
  6497.  
  6498.  
  6499.  
  6500.  
  6501.  
  6502.  
  6503.  
  6504.  
  6505.  
  6506.  
  6507.  
  6508.  
  6509.  
  6510.  
  6511.  
  6512.  
  6513.  
  6514.  
  6515.  
  6516.  
  6517.  
  6518.  
  6519.  
  6520.  
  6521.  
  6522.  
  6523.  
  6524.  
  6525.  
  6526.  
  6527.  
  6528.  
  6529.  
  6530.  
  6531.  
  6532.  
  6533.  
  6534.  
  6535.  
  6536.  
  6537.  
  6538.  
  6539.  
  6540.  
  6541.  
  6542.  
  6543.  
  6544.                                      - 94 -               Version 1.10
  6545.           
  6546.  
  6547.  
  6548.  
  6549.  
  6550.  
  6551.  
  6552.           PDLISP language manual          PDLISP Directory Structure
  6553.           
  6554.  
  6555.  
  6556.  
  6557.  
  6558.                        This page intentionally left blank
  6559.  
  6560.  
  6561.  
  6562.  
  6563.  
  6564.  
  6565.  
  6566.  
  6567.  
  6568.  
  6569.  
  6570.  
  6571.  
  6572.  
  6573.  
  6574.  
  6575.  
  6576.  
  6577.  
  6578.  
  6579.  
  6580.  
  6581.  
  6582.  
  6583.  
  6584.  
  6585.  
  6586.  
  6587.  
  6588.  
  6589.  
  6590.  
  6591.  
  6592.  
  6593.  
  6594.  
  6595.  
  6596.  
  6597.  
  6598.  
  6599.  
  6600.  
  6601.  
  6602.  
  6603.  
  6604.  
  6605.  
  6606.  
  6607.  
  6608.  
  6609.  
  6610.                                      - 95 -               Version 1.10
  6611.           
  6612.  
  6613.  
  6614.  
  6615.  
  6616.  
  6617.  
  6618.           PDLISP language manual                   Control Constructs
  6619.           
  6620.  
  6621.  
  6622.  
  6623.  
  6624.  
  6625.  
  6626.  
  6627.  
  6628.  
  6629.                                     Chapter 7
  6630.  
  6631.                                Control Constructs
  6632.  
  6633.  
  6634.  
  6635.           This chapter contains a  description  of functions which are
  6636.           useful in directing the "control flow" of LISP programs. 
  6637.  
  6638.  
  6639.  
  6640.  
  6641.  
  6642.           7.1 Explicit Evaluation
  6643.  
  6644.  
  6645.  
  6646.               Functions are provided for explicit evaluation in
  6647.           order to allow manual control of the evaluation process.
  6648.           For example, if FOO were a special form which evaluated
  6649.           its arguments in some idiosyncratic way, we might wish
  6650.           to explicitly evaluate them using one of these functions
  6651.           before FOO was applied.
  6652.  
  6653.           APPLY           CSUBR       (FN ARGLIST)
  6654.  
  6655.           Returns the result of the application of FN to the list
  6656.           of arguments, ARGLIST. FN can be any function which is
  6657.           not defined as a MACRO. ARGLIST must be a list (or NIL).
  6658.  
  6659.           for example:
  6660.           /USR/LOGIN->(setq fred '+)
  6661.           +
  6662.           /USR/LOGIN->(apply fred '(1 2))
  6663.           3
  6664.           /USR/LOGIN->(apply 'cons '((+ 2 3) 4))
  6665.           ((+ 2 3) . 4)           ;note that the result is not (5 . 4)
  6666.  
  6667.           APPLY arranges things so that the individual arguments
  6668.           in ARGLIST are not evaluated before FN is applied, even
  6669.           if FN is a CSUBR or LAMBDA, which ordinarily evaluate
  6670.           their arguments. See FUNCALL, EVAL, and QUOTE.
  6671.  
  6672.  
  6673.  
  6674.  
  6675.  
  6676.                                      - 96 -               Version 1.10
  6677.           
  6678.  
  6679.  
  6680.  
  6681.  
  6682.  
  6683.  
  6684.           PDLISP language manual                   Control Constructs
  6685.           
  6686.  
  6687.  
  6688.  
  6689.           EVAL                CSUBR       (FORM)
  6690.  
  6691.           Allows explicit evaluation of a form. (EVAL FORM) returns
  6692.           the evaluation of FORM.
  6693.  
  6694.           
  6695.  
  6696.  
  6697.  
  6698.  
  6699.           7.2 Conditional Evaluation
  6700.  
  6701.  
  6702.             Conditionals  are  special  forms which perform  the  same
  6703.           function as the  "if-then"  or  "if-then-else"  statement in
  6704.           other languages.  The simplest of these is the IF construct,
  6705.           and the most general is COND.
  6706.  
  6707.  
  6708.           IF                CNSUBR      (TEST IF-CASE &OPTIONAL ELSE-CASE)
  6709.  
  6710.           IF performs the following  sequence  of  operations:  First,
  6711.           TEST is evaluated.  If it evaluates to a non-NIL value, then
  6712.           IF-CASE is evaluated, and  the  result is returned.  If TEST
  6713.           evaluated to a NIL value, then if an ELSE-CASE parameter was
  6714.           supplied,  it  is  evaluated  and  the result is  returned. 
  6715.           Otherwise, a value of NIL is returned by this function. 
  6716.  
  6717.           
  6718.  
  6719.  
  6720.           COND              CNSUBR      (&REST CLAUSES)
  6721.  
  6722.           COND  is the traditional conditional function supplied  with
  6723.           LISP implementations.  A call to COND contains a sequence of
  6724.           clauses, each of which consists of  a test followed by none,
  6725.           one,  or more consequents. That is, each clause  is  of  the
  6726.           form:
  6727.  
  6728.  
  6729.           (TEST CONSEQUENT-1 CONSEQUENT-2 ... CONSEQUENT-N)
  6730.  
  6731.           As an example of a COND form, we could have:
  6732.  
  6733.  
  6734.           (cond   (a b c)     ;a clause with multiple consequents
  6735.                   (d)         ;a clause with no consequents
  6736.                   (t e))      ;fall-through case
  6737.  
  6738.           COND evaluates the TEST part of each of its clauses in order
  6739.  
  6740.  
  6741.  
  6742.                                      - 97 -               Version 1.10
  6743.           
  6744.  
  6745.  
  6746.  
  6747.  
  6748.  
  6749.  
  6750.           PDLISP language manual                   Control Constructs
  6751.           
  6752.  
  6753.  
  6754.  
  6755.           until it encounters one which does not evaluate to NIL. COND
  6756.           then evaluates each consequent  of  that clause, and returns
  6757.           the value of the last one.  For example, suppose that in the
  6758.           code fragment above, that  A  did not evaluate to NIL. Then,
  6759.           COND would evaluate B and C,  in  that  order,  and  finally
  6760.           return  the  value  of  C.  The  other clauses would not  be
  6761.           evaluated. 
  6762.  
  6763.             In the case that a TEST  evaluates to a non-NIL value, and
  6764.           the  clause contains no consequents, COND returns the  value
  6765.           of TEST (which must, by definition, be non-NIL). 
  6766.  
  6767.             If no  TEST  evaluates  to  a  non-NIL value, and the COND
  6768.           "runs  off the end" of its clause list, then a value of  NIL
  6769.           is  returned.   As  a  matter  of programming style,  it  is
  6770.           probably a good idea to make the TEST of the last clause the
  6771.           constant T. In  this  way,  one  can  be  sure that the COND
  6772.           explicitly returns a value. 
  6773.  
  6774.             The PDLISP COND is Common LISP compatible. 
  6775.  
  6776.           
  6777.  
  6778.  
  6779.  
  6780.  
  6781.           7.3 DO and DO*
  6782.  
  6783.  
  6784.  
  6785.           DO              MACRO       (INIT TEST &REST BODY)
  6786.           
  6787.  
  6788.           Iterative control construct.  The syntax is  a subset of the
  6789.           Common LISP syntax.  A  DO contains 3 parts, INIT, TEST, and
  6790.           a BODY.
  6791.  
  6792.             INIT is the initialization component, which consists of  a
  6793.           list  of  pairs of local variables and their  initialization
  6794.           values.  Each variable is  bound to its initialization value
  6795.           upon  entering  the  DO, and is restored to its entry  value
  6796.           upon  exiting  the  DO.  If a local  variable  is  specified
  6797.           without an initialization value,  then  it is initialized to
  6798.           NIL. If there are no local variables, then INIT must  be NIL
  6799.           or (). Initialization of  local  variables  takes  place  in
  6800.           parallel,   so    that    each   variable   is   initialized
  6801.           independently. 
  6802.  
  6803.             The  first  part  of  TEST,  which must be a list, is  the
  6804.           termination test for  the DO. After the termination test can
  6805.  
  6806.  
  6807.  
  6808.                                      - 98 -               Version 1.10
  6809.           
  6810.  
  6811.  
  6812.  
  6813.  
  6814.  
  6815.  
  6816.           PDLISP language manual                   Control Constructs
  6817.           
  6818.  
  6819.  
  6820.  
  6821.           be any number of  additional  forms.  Each time that the top
  6822.           of the loop is entered, the termination test  is evaluated. 
  6823.           If the termination test evaluates to T, then the rest of the
  6824.           forms in TEST are evaluated, and the value of the  last  one
  6825.           is returned as the value of the DO.
  6826.  
  6827.             BODY   is   a  sequence  of  forms  which  are   evaluated
  6828.           sequentially.  After each form  is  evaluated,  its value is
  6829.           discarded, so the only reason to include anything here would
  6830.           be for the side effects which might occur. 
  6831.  
  6832.             As an example of the use of a DO,  consider  the  function
  6833.           NTHCDR, which  is  defined  in  the  file,  "misc.l"  on the
  6834.           distribution disk.  NTHCDR is an implementation of the Franz
  6835.           LISP function by the same name.  The job of NTHCDR is to CDR
  6836.           down a list (called  'E'  here)  N  times.  So, (NTHCDR 3 E)
  6837.           would stand for (CDR (CDR (CDR E))).
  6838.  
  6839.  
  6840.           (defun nthcdr (n e)
  6841.               (do ((i 0))             ;initialize i to 0.
  6842.                   ((eql i n) e)       ;termination test.
  6843.           ;
  6844.           ; body of DO starts here.
  6845.           ;
  6846.                   (setq i (+ i 1))    ;increment i.
  6847.                   (setq e (cdr e))))  ;cdr down e.
  6848.  
  6849.               The actual DO, of course, is nested inside of a function
  6850.           definition in this case. The INIT part of the DO consists of
  6851.           the form ((i 0)). Here, i is our counter variable. If we had
  6852.           needed more than one variable here, we could have written this
  6853.           part as, say, ((i 0) (j 2) (k 1)).
  6854.  
  6855.               The TEST part of the DO consists of the expression
  6856.           ((eql i n) e). Each time that the evaluator makes a pass
  6857.           through the DO, the expression (eql i n) is evaluated.
  6858.           If it evaluated to T, then the value of the expression e
  6859.           is returned.
  6860.  
  6861.               The body of the DO consists of the rest of the function
  6862.           definition, namely, (setq i (+ i 1)) and (setq e (cdr e)).
  6863.           These forms are each evaluated once each time through the
  6864.           DO, until the termination test returns T.
  6865.  
  6866.               If the PDLISP DO were to be fully compatible with the
  6867.           Common Lisp standard, then the init part would consist of
  6868.           ((vbl_1 init_value_1 step_1) (vbl_2 init_value_2 step_2) ... ).
  6869.           I will be extending the DO macro in a future release so
  6870.           that it implements all of the Common LISP standard.
  6871.  
  6872.  
  6873.  
  6874.                                      - 99 -               Version 1.10
  6875.           
  6876.  
  6877.  
  6878.  
  6879.  
  6880.  
  6881.  
  6882.           PDLISP language manual                   Control Constructs
  6883.           
  6884.  
  6885.  
  6886.  
  6887.  
  6888.  
  6889.           DO*                 MACRO       (INIT TEST &REST BODY)
  6890.           
  6891.  
  6892.           DO* works just like DO, except that the local variables  are
  6893.           initialized  sequentially, instead  of  in  parallel  as  DO
  6894.           does.  So, DO* is  useful if there is a desirable dependency
  6895.           between  local  variables in the  initialized  varible  list
  6896.           (INIT). The remarks on  Common  Lisp compatibility which are
  6897.           noted above under the DO macro also apply here. 
  6898.  
  6899.           
  6900.  
  6901.  
  6902.  
  6903.  
  6904.           7.4 Mapping Functions
  6905.  
  6906.  
  6907.  
  6908.           MAPCAR              CSUBR       (FN LIST1 &rest LISTS)
  6909.  
  6910.           MAPC                LAMBDA      (FN LIST1 &rest LISTS)
  6911.  
  6912.           MAPCAN              CSUBR       (FN LIST1 &rest LISTS)
  6913.  
  6914.           MAPCON              CSUBR       (FN LIST1 &rest LISTS)
  6915.  
  6916.           MAPLIST             CSUBR       (FN LIST1 &rest LISTS)
  6917.  
  6918.           MAPL                LAMBDA      (FN LIST1 &rest LISTS)
  6919.  
  6920.           Mapping is  a form of iteration, which is a bit of technical
  6921.           jargon meaning "to repeat."  The mapping functions described
  6922.           in this section are useful when  the  same function is to be
  6923.           applied repeatedly on lists of things.  For example, suppose
  6924.           that we wished to  add  1  to  each  element  of  a  list of
  6925.           numbers.  We could do the job with MAPCAR as follows:
  6926.  
  6927.  
  6928.           /USR/LOGIN->(MAPCAR 'ADD1       ;function to be applied
  6929.                               '(1 3 5))   ;arguments to the function
  6930.           (2 4 6)                         ;voila!
  6931.  
  6932.           MAPCAR  can also be used to apply functions which take  more
  6933.           than  1 argument.  However, if such is the case, then  there
  6934.           must be exactly as many argument lists in the call to MAPCAR
  6935.           as the function specifies in its formal parameter list.  For
  6936.           example, we could add two lists of arguments, as follows:
  6937.  
  6938.  
  6939.  
  6940.                                      - 100 -              Version 1.10
  6941.           
  6942.  
  6943.  
  6944.  
  6945.  
  6946.  
  6947.  
  6948.           PDLISP language manual                   Control Constructs
  6949.           
  6950.  
  6951.  
  6952.  
  6953.  
  6954.  
  6955.           /USR/LOGIN->(mapcar '+ '(1 3 5) '(2 4 6))
  6956.           (3 7 11)                                  ;list of sums
  6957.  
  6958.           In the above example, 2 argument lists were supplied, but  +
  6959.           can  take any  number  of  arguments.   So,  we  could  have
  6960.           supplied 3, 4, or more argument  lists,  and  they would all
  6961.           have been fed to +. There is no  limit  in  PDLISP  to  the
  6962.           number of argument lists which can be supplied to MAPCAR  or
  6963.           to any other mapping function. 
  6964.  
  6965.             MAPC  and  MAPL  are   similar   to  MAPCAR  and  MAPLIST,
  6966.           respectively,  except  that  they do  not  accumulate  their
  6967.           arguments.  These functions return as their values the first
  6968.           list argument passed, and are used when the mapping is being
  6969.           done primarily for the side effects which may occur. 
  6970.  
  6971.             MAPCAN   and   MAPCON   are  like  MAPCAR   and   MAPLIST,
  6972.           repectively,  except that they accumulate  their  result  by
  6973.           using NCONC instead of CONS. That is,
  6974.  
  6975.  
  6976.           (MAPCAN FN X1 ... XN) <==> (APPLY 'NCONC (MAPCAR FN X1 ... XN))
  6977.  
  6978.           (MAPCON FN X1 ... XN) <==> (APPLY 'NCONC (MAPLIST FN X1 ... XN))
  6979.  
  6980.           One should keep in mind, however, that MAPCAN and MAPCON are
  6981.           destructive  functions,  because  they  use NCONC. Also,  an
  6982.           error  will  be  generated unless  FN  consistently  returns
  6983.           lists, because NCONC  will  choke on arguments which are not
  6984.           lists. 
  6985.  
  6986.             The function which is supplied to  a mapping function must
  6987.           be something which could be given to APPLY; in particular it
  6988.           cannot be a MACRO. However, there are no  restrictions as to
  6989.           its formal parameter list - it could  have &OPTIONAL, &REST,
  6990.           and/or &AUX parameters. 
  6991.  
  6992.           
  6993.  
  6994.  
  6995.  
  6996.  
  6997.           7.5 PROG and Friends
  6998.  
  6999.  
  7000.  
  7001.           PROG                MACRO       (VBL_LIST &REST BODY)
  7002.  
  7003.  
  7004.  
  7005.  
  7006.                                      - 101 -              Version 1.10
  7007.           
  7008.  
  7009.  
  7010.  
  7011.  
  7012.  
  7013.  
  7014.           PDLISP language manual                   Control Constructs
  7015.           
  7016.  
  7017.  
  7018.  
  7019.               PROG is variously described as a crutch or as a
  7020.           mainstay, depending upon one's vintage. Its original
  7021.           intent was to "sugar coat" the language so that LISP
  7022.           programmers could program in an imperative style if they
  7023.           so chose. However, as the school of "functional
  7024.           programming" has matured, more people are using DO,
  7025.           mapping functions, and special purpose MACROs in
  7026.           preference to it. With the advent of Common Lisp, PROG,
  7027.           which was once thought to be rightly implemented as a
  7028.           system primitive, is now usually implemented as a MACRO
  7029.           itself with no special privileges.
  7030.  
  7031.               The twist that Common Lisp has provided concerning
  7032.           PROG is that it has been broken down into 3 simpler
  7033.           operations: the binding of local variables, the use
  7034.           of the RETURN statement, and the use of the GO statement.
  7035.           These 3 operations have been distilled into independent
  7036.           constructs, namely, LET, BLOCK, and TAGBODY.
  7037.  
  7038.  
  7039.           TAGBODY             CSUBR       (&REST BODY)
  7040.           
  7041.               TAGBODY is the primitive form which executes
  7042.           imperative s-expression forms. A tag body consists
  7043.           of a sequence of elements. Each element of the tag
  7044.           body may be a symbol, in which case it is called a
  7045.           tag, or a list, in which case it is called a
  7046.           statement.
  7047.  
  7048.               TAGBODY proceeds through the tag body from left
  7049.           to right. Tags are skipped over; they are useful only
  7050.           as targets for calls to the GO function. Statements
  7051.           are evaluated as they are encountered, and the value
  7052.           produced by each is discarded.
  7053.  
  7054.               If the end of the tag body is reached, then TAGBODY
  7055.           returns a value of NIL. Otherwise, if an s-expression of
  7056.           the form (GO SOME_TAG) is encountered, then control resumes
  7057.           at the part of the body which immediately follows SOME_TAG.
  7058.  
  7059.  
  7060.  
  7061.  
  7062.  
  7063.  
  7064.  
  7065.  
  7066.  
  7067.  
  7068.  
  7069.  
  7070.  
  7071.  
  7072.                                      - 102 -              Version 1.10
  7073.           
  7074.  
  7075.  
  7076.  
  7077.  
  7078.  
  7079.  
  7080.           PDLISP language manual                   Control Constructs
  7081.           
  7082.  
  7083.  
  7084.  
  7085.  
  7086.           BLOCK               CNSUBR      (NAME &REST BODY)
  7087.  
  7088.               BLOCK executes each form in BODY from left to right,
  7089.           and returns the value of the last form. However, if
  7090.           a RETURN is encountered, then the value specified by
  7091.           the RETURN is taken to be the value to be returned
  7092.           by the BLOCK, and control proceeds as if the BLOCK
  7093.           had run to completion. BLOCK is similar to PROGN, except
  7094.           that PROGN is invisible as far as RETURN is concerned;
  7095.           RETURN only has meaning with respect to a BLOCK.
  7096.  
  7097.               The PDLISP BLOCK construct is actually a subset of the
  7098.           full Common Lisp standard, and will be upgraded in a later
  7099.           release. In particular, the Common standard specifies that
  7100.           the scope of a BLOCK construct be determined lexically, but
  7101.           all of the lexical binding machinery was not working in the
  7102.           first release. Also, Common specifies that blocks can be
  7103.           named, but the RETURN-FROM function has not yet been
  7104.           implemented in PDLISP; consequently named BLOCKs should be
  7105.           avoided at the present time. This should not create an
  7106.           immediate problem, because all of the macros provided with
  7107.           PDLISP which expand into BLOCKs do so into BLOCKs named
  7108.           NIL, which works with RETURN. See Steele [1984] for more
  7109.           information.
  7110.  
  7111.  
  7112.           LET                 CNSUBR      (INIT_LIST &REST BODY)
  7113.           LET*                CNSUBR      (INIT_LIST &REST BODY)
  7114.  
  7115.               These constructs are provided in order to control
  7116.           lambda-binding transactions. In the following descriptions,
  7117.           INIT_LIST is a list of variable-value pairs, and BODY
  7118.           is a list of s-expressions to be evaluated.
  7119.           In particular, the usage of LET is:
  7120.  
  7121.           (LET  ((VARIABLE_1 VALUE_1)
  7122.                  (VARIABLE_2 VALUE_2)
  7123.  
  7124.                  ...
  7125.  
  7126.                  (VARIABLE_N VALUE_N))
  7127.           BODY)
  7128.  
  7129.  
  7130.  
  7131.  
  7132.  
  7133.  
  7134.  
  7135.  
  7136.  
  7137.  
  7138.                                      - 103 -              Version 1.10
  7139.           
  7140.  
  7141.  
  7142.  
  7143.  
  7144.  
  7145.  
  7146.           PDLISP language manual                   Control Constructs
  7147.           
  7148.  
  7149.  
  7150.  
  7151.  
  7152.               In evaluating a LET, PDLISP follows the following
  7153.           sequence of operations:
  7154.  
  7155.           (1) the forms VALUE_1, VALUE_2, and so on through VALUE_N
  7156.               are evaluated, and the corresponding values are saved.
  7157.  
  7158.           (2) all of the variables are bound simultaneously to
  7159.               their respective values.
  7160.  
  7161.           (3) the expressions comprising BODY are evaluated in sequence,
  7162.               and the value returned by the LET is that of the last
  7163.               expression in BODY; in effect, BODY is evaluated as
  7164.               an implicit PROGN, which is described below.
  7165.  
  7166.               The evaluation of a LET* is identical to that of a LET,
  7167.           except that the variables are bound to their respective
  7168.           values sequentially, instead of in parallel. This permits
  7169.           the value of a initialized variable to depend upon previous
  7170.           ones in INIT_LIST.
  7171.  
  7172.               INIT_LIST can contain uninitialized variables, as well.
  7173.           For example, if instead of the variable-value pair (FOO BLUE),
  7174.           INIT_LIST contained simply FOO, then FOO would be initialized
  7175.           to the default value of NIL. In general, however, this decreases
  7176.           the clarity of the code, because then one has to look inside
  7177.           of BODY to see if the variable is SETQ'd before its value
  7178.           is referenced.
  7179.  
  7180.               A PROG consists of two parts, a list of (possibly)
  7181.           initialized variables, and a body of s-expressions to
  7182.           be executed. In my description of the PROG syntax,
  7183.           I have identified these two parts, as VBL_LIST and
  7184.           BODY. BODY is a &REST parameter to indicate that
  7185.           the first parameter to PROG is interpreted to be VBL_LIST,
  7186.           and that the rest of the argument list is interpreted
  7187.           as BODY. BODY is just interpreted as a tag body in the
  7188.           description of TAGBODY, above.
  7189.  
  7190.               Now, let's see how PROG puts all of this together.
  7191.           Consider the following function, which computes N to the
  7192.           Mth power; never mind for now that the function could be
  7193.           more elegantly coded in another style:
  7194.  
  7195.  
  7196.  
  7197.  
  7198.  
  7199.  
  7200.  
  7201.  
  7202.  
  7203.  
  7204.                                      - 104 -              Version 1.10
  7205.           
  7206.  
  7207.  
  7208.  
  7209.  
  7210.  
  7211.  
  7212.           PDLISP language manual                   Control Constructs
  7213.           
  7214.  
  7215.  
  7216.  
  7217.  
  7218.           ;
  7219.           ; ipower - iteratively coded n ^ mth power routine
  7220.           ; m and m must both be integers.
  7221.           ;
  7222.           (defun ipower (m n)
  7223.               (prog ((result 1) (exponent n))
  7224.           ;
  7225.           ; In the VBL_LIST, above,
  7226.           ; result is initialized to 1
  7227.           ; and exponent is initialized to n
  7228.           ;
  7229.           ; now for the BODY:
  7230.           ;
  7231.             ploop (cond ((zerop exponent) (return result)))   ;test
  7232.                   (setq result (* m result))                  ;reset
  7233.                   (setq exponent (- exponent 1))              ;reset
  7234.                   (go ploop)))                               ;repeat
  7235.  
  7236.               Let's examine the control flow of IPOWER.
  7237.           First, two local variables are declared and initialized.
  7238.           Namely, RESULT, which is a temporary variable which
  7239.           accumulates the value to be returned from this function,
  7240.           is initialized to 1, and EXPONENT is initialized to N.
  7241.  
  7242.               After initialization, the main body, which happens
  7243.           to be a loop, is executed. First, a COND statement checks
  7244.           to see if EXPONENT has reached 0. If it has, then RESULT
  7245.           is immediately returned. Otherwise, control flow "falls
  7246.           through" the COND, and the iterative section is entered.
  7247.           RESULT is multiplied by M another time, EXPONENT is
  7248.           decremented, and control is transferred back to the test
  7249.           at the top of the loop. Notice that in the degenerate
  7250.           case that the parameter N is 0, the test at the top
  7251.           of the loop immediately goes off, and the main section
  7252.           of the loop is never executed.
  7253.  
  7254.  
  7255.  
  7256.  
  7257.  
  7258.  
  7259.  
  7260.  
  7261.  
  7262.  
  7263.  
  7264.  
  7265.  
  7266.  
  7267.  
  7268.  
  7269.  
  7270.                                      - 105 -              Version 1.10
  7271.           
  7272.  
  7273.  
  7274.  
  7275.  
  7276.  
  7277.  
  7278.           PDLISP language manual                   Control Constructs
  7279.           
  7280.  
  7281.  
  7282.  
  7283.  
  7284.               When the PROG macro for IPOWER is expanded, something
  7285.           like the code below is actually produced:
  7286.  
  7287.           (ipower (lambda (m n)
  7288.               (block 'nil                ;a BLOCK
  7289.                   (let ((result 1)       ;with a name of NIL
  7290.                         (exponent n))    ;surrounds a LET
  7291.                       (tagbody           ;all wrapped around a TAGBODY
  7292.           ;
  7293.           ; BODY of the tag body is below:
  7294.           ;
  7295.           ploop           (cond ((zerop exponent) (return result)))
  7296.                           (setq result (* m result))
  7297.                           (setq exponent (- exponent 1))
  7298.                           (go ploop))))))
  7299.  
  7300.           For the curious, the actual definition of the PROG macro  is
  7301.           in MISC.L. Incidently, the  above  example  could  have been
  7302.           quite neatly coded as a DO. I suggest that you attempt to do
  7303.           so.  The answer is  in  the  file  EXAMPLES.L, and is called
  7304.           DO_IPOWER.
  7305.  
  7306.           
  7307.  
  7308.  
  7309.           PROG*               MACRO       (VBL_LIST &REST BODY)
  7310.  
  7311.           PROG* works just like PROG, except that the local variables
  7312.           in VBL_LIST are initialized sequentially, instead of in
  7313.           parallel, so that dependencies between local variables
  7314.           can be processed. PROG* has the same relationship to PROG as
  7315.           LET* has to LET. So, we could write:
  7316.  
  7317.           (prog* ((x t) (y (cdr x)))
  7318.               (return y))
  7319.  
  7320.           and the result would be the CDR of X.
  7321.  
  7322.  
  7323.  
  7324.  
  7325.  
  7326.  
  7327.  
  7328.  
  7329.  
  7330.  
  7331.  
  7332.  
  7333.  
  7334.  
  7335.  
  7336.                                      - 106 -              Version 1.10
  7337.           
  7338.  
  7339.  
  7340.  
  7341.  
  7342.  
  7343.  
  7344.           PDLISP language manual                   Control Constructs
  7345.           
  7346.  
  7347.  
  7348.  
  7349.  
  7350.  
  7351.  
  7352.  
  7353.           7.6 PROGN and PROG1
  7354.  
  7355.  
  7356.  
  7357.           PROGN               CNSUBR      (&REST SEQUENCE)
  7358.  
  7359.           Evaluates a sequence of s-expressions, and returns the value
  7360.           of the last one. For example,
  7361.  
  7362.           (progn
  7363.               (setq a 4)
  7364.               (setq b 5)
  7365.               (+ a b))
  7366.  
  7367.           would evaluate to 9. In addition, A would be EQL to 4,
  7368.           and B would be EQL to 5.
  7369.  
  7370.           PROG1               CNSUBR      (&REST SEQUENCE)
  7371.  
  7372.           Similar to PROGN, except that it returns the value of the
  7373.           first s-expression in the sequence.
  7374.  
  7375.  
  7376.  
  7377.  
  7378.           7.7 Implicit PROGN
  7379.  
  7380.  
  7381.           Many PDLISP/Common LISP special forms such as COND evaluate
  7382.           sequences  of  s-expressions as if they were  clauses  of  a
  7383.           PROGN. For example, we could write a COND as follows:
  7384.  
  7385.  
  7386.           (cond
  7387.               ((atom a) (princ "found an atom") t)
  7388.               (t (princ "no dice")))
  7389.  
  7390.           Function  definitions  can  also  be  implicit  PROGN's,  as
  7391.           follows:
  7392.  
  7393.  
  7394.           (defun foo (x y)
  7395.               (setq a (+ x y))
  7396.               (setq b (* x y))
  7397.               y)
  7398.  
  7399.  
  7400.  
  7401.  
  7402.                                      - 107 -              Version 1.10
  7403.           
  7404.  
  7405.  
  7406.  
  7407.  
  7408.  
  7409.  
  7410.           PDLISP language manual                   Control Constructs
  7411.           
  7412.  
  7413.  
  7414.  
  7415.           Clever  hackers  may notice that the usage  of  an  explicit
  7416.           PROGN when an implicit  one would suffice wastes a node when
  7417.           the expression is being interpreted.  However, no such waste
  7418.           occurs  when  the   expression   is  compiled,  because  all
  7419.           s-expressions   which   are  compiled   are   removed   from
  7420.           s-expression space.  Consequently, I recommend that PROGN be
  7421.           used explicitly whenever it  augments  the readability of an
  7422.           expression. 
  7423.  
  7424.           
  7425.  
  7426.  
  7427.  
  7428.  
  7429.           7.8 LOOP
  7430.  
  7431.  
  7432.  
  7433.           LOOP            MACRO       (&REST FORM)
  7434.  
  7435.           LOOP provides a simple and clean way to perform  iteration. 
  7436.           FORM  is  repeatedly  evaluated  as an implicit PROGN.  This
  7437.           computation  continues   indefinitely.    LOOP  is  actually
  7438.           implemented as a MACRO  which wraps a BLOCK with the name of
  7439.           NIL around the PROGN. The only way for the LOOP to be exited
  7440.           is by way of a RETURN  to the surrounding BLOCK. Programmers
  7441.           should  not  confuse  the  PDLISP/Common  LISP  LOOP   with
  7442.           constructs of  the  same  name  in  other dialects; they are
  7443.           generally MACROs which perform  the same general purposes as
  7444.           the PDLISP/Common DO.
  7445.  
  7446.  
  7447.  
  7448.  
  7449.  
  7450.  
  7451.  
  7452.  
  7453.  
  7454.  
  7455.  
  7456.  
  7457.  
  7458.  
  7459.  
  7460.  
  7461.  
  7462.  
  7463.  
  7464.  
  7465.  
  7466.  
  7467.  
  7468.                                      - 108 -              Version 1.10
  7469.           
  7470.  
  7471.  
  7472.  
  7473.  
  7474.  
  7475.  
  7476.           PDLISP language manual                   Control Constructs
  7477.           
  7478.  
  7479.  
  7480.  
  7481.  
  7482.  
  7483.  
  7484.  
  7485.           7.9 CATCH and THROW
  7486.  
  7487.  
  7488.  
  7489.           CATCH           CNSUBR      (TAG &REST FORM)
  7490.  
  7491.           This is a superset of the Common LISP CATCH function.
  7492.           TAG is normally a symbol or a list of symbols. FORM can
  7493.           be any form, or a list of forms (CATCH evaluates FORM
  7494.           as an implicit PROGN). CATCH employs the following sequence
  7495.           of operation:
  7496.  
  7497.           (1) TAG is evaluated.
  7498.  
  7499.           (2) FORM is evaluated.
  7500.  
  7501.           (3) If FORM evaluated normally, then its value is returned.
  7502.  
  7503.           (4) If, however, a call to THROW occurred during the evaluation
  7504.               of FORM, then the tag of the THROW is compared with the tag
  7505.               of the CATCH. The value passed to THROW is returned by
  7506.               CATCH if one of the following situations holds:
  7507.                   (a) TAG is a symbol, and the tag of the THROW is EQ
  7508.                       to it,
  7509.                   (b) TAG is a list, and the tag of the THROW is EQ
  7510.                       to a member of it,
  7511.               or  (c) TAG is NIL.
  7512.  
  7513.           (5) If a call to THROW occurred during the evaluation of
  7514.               of FORM, but the tag which was thrown did not come under
  7515.               one of the cases listed in (4), above, then an error
  7516.               may have occurred, or there may have been another call to
  7517.               CATCH involved.
  7518.  
  7519.               PDLISP follows the Common LISP standard as far as the
  7520.           syntax of CATCH and THROW go. Programmers hopping between
  7521.           different LISP dialects should keep in mind that system
  7522.           implementors have a diabolical tendency to swap TAG and FORM
  7523.           in their syntax.
  7524.  
  7525.           THROW           CNSUBR      (TAG X)
  7526.  
  7527.           X is returned through the closest dynamically enclosing CATCH
  7528.           which has the tag TAG. See CATCH.
  7529.  
  7530.  
  7531.  
  7532.  
  7533.  
  7534.                                      - 109 -              Version 1.10
  7535.           
  7536.  
  7537.  
  7538.  
  7539.  
  7540.  
  7541.  
  7542.           PDLISP language manual                   Control Constructs
  7543.           
  7544.  
  7545.  
  7546.  
  7547.  
  7548.  
  7549.  
  7550.  
  7551.           7.10 Error Handling in PDLISP
  7552.  
  7553.  
  7554.           When an error  occurs in PDLISP, the evaluator observes the
  7555.           following procedure:
  7556.  
  7557.  
  7558.           (1) The control stack is searched to see if there is an
  7559.               enclosing instance of ERRSET. If there is, then control
  7560.               is transferred to it, and a value of NIL is returned
  7561.               from the ERRSET.
  7562.  
  7563.           (2) If there is no such ERRSET, then the system break hook
  7564.               is examined. If the system break hook, which can be
  7565.               examined and set using the STATUS function, is non-NIL,
  7566.               then control is transferred to it.
  7567.  
  7568.           (3) Otherwise, the internal break handler is entered, and
  7569.               a prompt such as "<1>" is output. The internal break
  7570.               handler is just a "read-eval-print" loop, except that
  7571.               the state of the computation is frozen at the point at
  7572.               at which the error occurred. This allows the user to
  7573.               examine and modify variables and function definitions
  7574.               at will. The loop is exited by typing the form (RETURN X),
  7575.               where X is some form. This form will be returned by the
  7576.               evaluator as the value of the computation which was frozen.
  7577.               It is also possibleto return directly to the top-level
  7578.               driver loop by entering the form (RESET).
  7579.  
  7580.             Normally,  an  ERRSET  is  not  used in development  under
  7581.           PDLISP. This allows invocation of the break handler when an
  7582.           error occurs.  Otherwise, when  an  application  (such as an
  7583.           editor) is written, it is enclosed inside of  an  ERRSET  so
  7584.           that the user  of  the  application is insulated from errors
  7585.           when  they  occur.   In  fact,  this  can  be  taken as  the
  7586.           practical definition of an application in PDLISP.
  7587.  
  7588.  
  7589.  
  7590.  
  7591.  
  7592.  
  7593.  
  7594.  
  7595.  
  7596.  
  7597.  
  7598.  
  7599.  
  7600.                                      - 110 -              Version 1.10
  7601.           
  7602.  
  7603.  
  7604.  
  7605.  
  7606.  
  7607.  
  7608.           PDLISP language manual                   Control Constructs
  7609.           
  7610.  
  7611.  
  7612.  
  7613.           It is  possible  to  "trick"  the  system  and  simulate  an
  7614.           internal error which will be treated as if it were generated
  7615.           by  the interpreter itself.  This can be accomplished  using
  7616.           the ERR function.  This  function  takes one argument, which
  7617.           is  usually  a  string  which  should be printed out at  the
  7618.           console when the error occurs.  For example, we could define
  7619.           a function foo as:
  7620.  
  7621.  
  7622.           (defun foo (x)
  7623.               (cond ((not (fboundp x))
  7624.                      (err "***> FOO: arg not bound as a function.")))
  7625.               (t (frotz (bar 'baz))))
  7626.  
  7627.           Whether or not the error message is printed is controlled by
  7628.           the global variable *PRINT_ERR_MESSAGES* which is created in
  7629.           the file "error.l". The initial value of this variable is T,
  7630.           which causes all messages generated  by  instances of ERR to
  7631.           be printed. 
  7632.  
  7633.  
  7634.           ERR                 LAMBDA      (X)
  7635.  
  7636.           This function causes a "simulated error", which will be
  7637.           intercepted by the interpreter. If there is an enclosing
  7638.           instance of ERRSET, then control is transferred to it.
  7639.           Otherwise, normal error-handling procedures are followed. In
  7640.           actuality, this function is defined as in the file "error.l".
  7641.           See the text for more info.
  7642.  
  7643.  
  7644.           ERRSET              LAMBDA      (X)
  7645.  
  7646.           This function normally returns a list of one element, which
  7647.           is the result of the evaluation of X. If an error occurs
  7648.           during the evaluation of X, then evaluation will terminate
  7649.           and a value of NIL is returned. If a "simulated error" occurs
  7650.           during the evaluation of X, which can only occur through a
  7651.           call to ERR, then this function returns as its value the form
  7652.           which was passed to ERR. This function is defined in the file
  7653.           "error.l".
  7654.  
  7655.  
  7656.  
  7657.  
  7658.  
  7659.  
  7660.  
  7661.  
  7662.  
  7663.  
  7664.  
  7665.  
  7666.                                      - 111 -              Version 1.10
  7667.           
  7668.  
  7669.  
  7670.  
  7671.  
  7672.  
  7673.  
  7674.           PDLISP language manual                   Control Constructs
  7675.           
  7676.  
  7677.  
  7678.  
  7679.  
  7680.                        This page intentionally left blank
  7681.  
  7682.  
  7683.  
  7684.  
  7685.  
  7686.  
  7687.  
  7688.  
  7689.  
  7690.  
  7691.  
  7692.  
  7693.  
  7694.  
  7695.  
  7696.  
  7697.  
  7698.  
  7699.  
  7700.  
  7701.  
  7702.  
  7703.  
  7704.  
  7705.  
  7706.  
  7707.  
  7708.  
  7709.  
  7710.  
  7711.  
  7712.  
  7713.  
  7714.  
  7715.  
  7716.  
  7717.  
  7718.  
  7719.  
  7720.  
  7721.  
  7722.  
  7723.  
  7724.  
  7725.  
  7726.  
  7727.  
  7728.  
  7729.  
  7730.  
  7731.  
  7732.                                      - 112 -              Version 1.10
  7733.           
  7734.  
  7735.  
  7736.  
  7737.  
  7738.  
  7739.  
  7740.           PDLISP language manual                   Control Constructs
  7741.           
  7742.  
  7743.  
  7744.  
  7745.  
  7746.                        This page intentionally left blank
  7747.  
  7748.  
  7749.  
  7750.  
  7751.  
  7752.  
  7753.  
  7754.  
  7755.  
  7756.  
  7757.  
  7758.  
  7759.  
  7760.  
  7761.  
  7762.  
  7763.  
  7764.  
  7765.  
  7766.  
  7767.  
  7768.  
  7769.  
  7770.  
  7771.  
  7772.  
  7773.  
  7774.  
  7775.  
  7776.  
  7777.  
  7778.  
  7779.  
  7780.  
  7781.  
  7782.  
  7783.  
  7784.  
  7785.  
  7786.  
  7787.  
  7788.  
  7789.  
  7790.  
  7791.  
  7792.  
  7793.  
  7794.  
  7795.  
  7796.  
  7797.  
  7798.                                      - 113 -              Version 1.10
  7799.           
  7800.  
  7801.  
  7802.  
  7803.  
  7804.  
  7805.  
  7806.           PDLISP language manual                       Property Lists
  7807.           
  7808.  
  7809.  
  7810.  
  7811.  
  7812.  
  7813.  
  7814.  
  7815.  
  7816.  
  7817.                                     Chapter 8
  7818.  
  7819.                                  Property Lists
  7820.  
  7821.  
  7822.  
  7823.           Since prehistoric times, LISP  implementations have provided
  7824.           property   lists,   or   plists   for  short,  to  associate
  7825.           miscellaneous information with  symbols.  A property list is
  7826.           a list of ordered pairs of indicators and values. All of the
  7827.           functions  in  the  property list management system use  the
  7828.           indicator as a key for search purposes. 
  7829.  
  7830.             In  PDLISP,  property  lists are implemented as lists  of
  7831.           dotted  pairs, where each dotted pair is an  indicator-value
  7832.           pair.   However,  this  implementation   will   probably  be
  7833.           rewritten    in   a   future   release   for   Common   LISP
  7834.           compatibility. 
  7835.  
  7836.           
  7837.  
  7838.  
  7839.  
  7840.  
  7841.           8.1 GET, PUTPROP, and REMPROP
  7842.  
  7843.  
  7844.           The  three basic functions for manipulating  property  lists
  7845.           are  GET,  PUTPROP,  and  REMPROP.  GET retrieves the  value
  7846.           associated  with  an  indicator on a property list;  PUTPROP
  7847.           stores a value under an indicator; and  REMPROP  removes  an
  7848.           indicator-value pair from a property list. 
  7849.  
  7850.           
  7851.  
  7852.  
  7853.           GET                 CSUBR       (SYMBOL INDICATOR)
  7854.  
  7855.           GET returns the current value associated with INDICATOR
  7856.           on the property list of SYMBOL.
  7857.  
  7858.  
  7859.  
  7860.  
  7861.  
  7862.  
  7863.  
  7864.                                      - 114 -              Version 1.10
  7865.           
  7866.  
  7867.  
  7868.  
  7869.  
  7870.  
  7871.  
  7872.           PDLISP language manual                       Property Lists
  7873.           
  7874.  
  7875.  
  7876.  
  7877.  
  7878.           PUTPROP             CSUBR       (SYMBOL VALUE PROPERTY)
  7879.  
  7880.           Puts the pair (PROPERTY, VALUE) on the property list of
  7881.           SYMBOL. Any previous association between PROPERTY and VALUE
  7882.           under SYMBOL is destroyed. PROPERTY and VALUE can be
  7883.           arbitrary s-expressions, as PDLISP uses EQUAL to detect
  7884.           equality when searching property lists.
  7885.  
  7886.  
  7887.           REMPROP             CSUBR       (SYMBOL PROPERTY)
  7888.  
  7889.           Removes a property-value pair from the property list of
  7890.           SYMBOL. A subsequent (GET SYMBOL PROPERTY) will return NIL.
  7891.           All occurences of PROPERTY on SYMBOL's property list are
  7892.           removed, since there could exist multiple PROPERTY-VALUE
  7893.           pairs if PUSHPROP had been used.
  7894.  
  7895.  
  7896.  
  7897.  
  7898.  
  7899.           8.2 SYMBOL-PLIST and SETPLIST
  7900.  
  7901.  
  7902.  
  7903.           SYMBOL-PLIST        CSUBR       (SYMBOL)
  7904.  
  7905.           Returns the beginning of the property list for SYMBOL.
  7906.  
  7907.  
  7908.           SETPLIST            CSUBR       (SYMBOL VALUE)
  7909.  
  7910.           Sets the property list for SYMBOL to value. This function
  7911.           returns T if no error occurred, NIL otherwise.
  7912.  
  7913.  
  7914.  
  7915.  
  7916.  
  7917.  
  7918.  
  7919.  
  7920.  
  7921.  
  7922.  
  7923.  
  7924.  
  7925.  
  7926.  
  7927.  
  7928.  
  7929.  
  7930.                                      - 115 -              Version 1.10
  7931.           
  7932.  
  7933.  
  7934.  
  7935.  
  7936.  
  7937.  
  7938.           PDLISP language manual                       Property Lists
  7939.           
  7940.  
  7941.  
  7942.  
  7943.  
  7944.  
  7945.  
  7946.  
  7947.           8.3 PUSHPROP and POPPROP
  7948.  
  7949.  
  7950.  
  7951.               The following functions may go away in the next release
  7952.           if I cannot implement a Common LISP - style property list
  7953.           system with them being present:
  7954.  
  7955.  
  7956.           PUSHPROP            CSUBR       (SYMBOL VALUE PROPERTY)
  7957.  
  7958.           Similar to PUTPROP, except that the property list for SYMBOL
  7959.           is considered to be a stack. Any (PROPERTY, VALUE) pair which
  7960.           was previously on the property list of SYMBOL will be left
  7961.           intact, and can be recovered by a subsequent POPPROP.
  7962.  
  7963.  
  7964.           POPPROP             CSUBR       (SYMBOL PROPERTY)
  7965.  
  7966.           Undoes a PUSHPROP. If there is more than one PROPERTY-VALUE
  7967.           pair on the property list of SYMBOL, then the one which
  7968.           was most recently pushed (using PUSHPROP) is removed.
  7969.           The next one on the property list becomes visible to GET.
  7970.  
  7971.  
  7972.  
  7973.  
  7974.  
  7975.  
  7976.  
  7977.  
  7978.  
  7979.  
  7980.  
  7981.  
  7982.  
  7983.  
  7984.  
  7985.  
  7986.  
  7987.  
  7988.  
  7989.  
  7990.  
  7991.  
  7992.  
  7993.  
  7994.  
  7995.  
  7996.                                      - 116 -              Version 1.10
  7997.           
  7998.  
  7999.  
  8000.  
  8001.  
  8002.  
  8003.  
  8004.           PDLISP language manual                       Property Lists
  8005.           
  8006.  
  8007.  
  8008.  
  8009.  
  8010.                        This page intentionally left blank
  8011.  
  8012.  
  8013.  
  8014.  
  8015.  
  8016.  
  8017.  
  8018.  
  8019.  
  8020.  
  8021.  
  8022.  
  8023.  
  8024.  
  8025.  
  8026.  
  8027.  
  8028.  
  8029.  
  8030.  
  8031.  
  8032.  
  8033.  
  8034.  
  8035.  
  8036.  
  8037.  
  8038.  
  8039.  
  8040.  
  8041.  
  8042.  
  8043.  
  8044.  
  8045.  
  8046.  
  8047.  
  8048.  
  8049.  
  8050.  
  8051.  
  8052.  
  8053.  
  8054.  
  8055.  
  8056.  
  8057.  
  8058.  
  8059.  
  8060.  
  8061.  
  8062.                                      - 117 -              Version 1.10
  8063.           
  8064.  
  8065.  
  8066.  
  8067.  
  8068.  
  8069.  
  8070.           PDLISP language manual                       Property Lists
  8071.           
  8072.  
  8073.  
  8074.  
  8075.  
  8076.                        This page intentionally left blank
  8077.  
  8078.  
  8079.  
  8080.  
  8081.  
  8082.  
  8083.  
  8084.  
  8085.  
  8086.  
  8087.  
  8088.  
  8089.  
  8090.  
  8091.  
  8092.  
  8093.  
  8094.  
  8095.  
  8096.  
  8097.  
  8098.  
  8099.  
  8100.  
  8101.  
  8102.  
  8103.  
  8104.  
  8105.  
  8106.  
  8107.  
  8108.  
  8109.  
  8110.  
  8111.  
  8112.  
  8113.  
  8114.  
  8115.  
  8116.  
  8117.  
  8118.  
  8119.  
  8120.  
  8121.  
  8122.  
  8123.  
  8124.  
  8125.  
  8126.  
  8127.  
  8128.                                      - 118 -              Version 1.10
  8129.           
  8130.  
  8131.  
  8132.  
  8133.  
  8134.  
  8135.  
  8136.           PDLISP language manual                     Input and Output
  8137.           
  8138.  
  8139.  
  8140.  
  8141.  
  8142.  
  8143.  
  8144.  
  8145.  
  8146.  
  8147.                                     Chapter 9
  8148.  
  8149.                                 Input and Output
  8150.  
  8151.  
  8152.  
  8153.           The follow functions are  presently  provided  for I/O. They
  8154.           will be expanded in future releases. 
  8155.  
  8156.  
  8157.           LOAD                CSUBR       (STR)
  8158.  
  8159.           Causes PDLISP to silently read input from a file with
  8160.           a file system name of STR. As each s-expression is read,
  8161.           it is evaluated. Returns a value of T if no error occurred,
  8162.           otherwise NIL.
  8163.  
  8164.  
  8165.           LOADV               CSUBR       (STR)
  8166.  
  8167.           Instructs PDLISP to read input from a file. The "V"
  8168.           in the function name indicates "verbosity", and the
  8169.           result of the evaluation of each s-expression is printed
  8170.           out on the terminal as the file is read in. Returns
  8171.           a value of T if no error occurred, otherwise NIL.
  8172.  
  8173.  
  8174.           PP                  CSUBR       (X &OPTIONAL HANDLE)
  8175.                                       or  ()  (rev 1.0)
  8176.  
  8177.           Pretty-prints an s-expression. The source for this
  8178.           function is in fmtio.l, should anyone wish to modify it.
  8179.  
  8180.  
  8181.           PPDEF               CSUBR       (X &OPTIONAL HANDLE)
  8182.                                       or  ()  (rev 1.0)
  8183.  
  8184.           Pretty-prints the functional definition of a symbol,
  8185.           if one exists.
  8186.  
  8187.  
  8188.  
  8189.  
  8190.  
  8191.  
  8192.  
  8193.  
  8194.                                      - 119 -              Version 1.10
  8195.           
  8196.  
  8197.  
  8198.  
  8199.  
  8200.  
  8201.  
  8202.           PDLISP language manual                     Input and Output
  8203.           
  8204.  
  8205.  
  8206.  
  8207.  
  8208.           PRINC               CSUBR       (X &OPTIONAL HANDLE)
  8209.                                       or  ()  (rev 1.0)
  8210.  
  8211.               Prints an expression on the output stream.
  8212.           The expression is printed verbatim; i.e., any strings
  8213.           are output with quote marks surrounding them.
  8214.  
  8215.  
  8216.           PRINT               CSUBR       (X &OPTIONAL HANDLE)
  8217.                                       or  ()  (rev 1.0)
  8218.  
  8219.               Prints an expression on the output stream.
  8220.           Any strings in the expression are printed without
  8221.           surrounding quote marks.
  8222.  
  8223.  
  8224.           PTOSTR              CSUBR       (X &OPTIONAL MODE)
  8225.  
  8226.           Prints an s-expression to a string, which is returned.
  8227.           If MODE = T, then the output is done using PRINC;
  8228.           otherwise, PRINT is used.
  8229.  
  8230.  
  8231.           READ                CSUBR       (&OPTIONAL HANDLE)
  8232.                                       or  ()  (rev 1.0)
  8233.  
  8234.           Reads an s-expression from the standard input,
  8235.           or a stream if HANDLE is specified.
  8236.  
  8237.  
  8238.           TERPRI              CSUBR       (&OPTIONAL HANDLE)
  8239.                                       or  ()  (rev 1.0)
  8240.  
  8241.           Stands for "terminate the print line". The optional
  8242.           parameter is a file handle. If it is present, output
  8243.           is sent to the named stream; otherwise, output is sent
  8244.           to the standard output.
  8245.  
  8246.  
  8247.           UNPRINT             CSUBR       (X &OPTIONAL HANDLE)
  8248.                                       or  ()  (rev 1.0)
  8249.  
  8250.           Same as PRINT, except that the pretty-printer is bypassed,
  8251.           regardless of whether or not the pretty-printer hook has
  8252.           been set. See PRINT, STATUS, PP_HOOK.
  8253.  
  8254.  
  8255.  
  8256.  
  8257.  
  8258.  
  8259.  
  8260.                                      - 120 -              Version 1.10
  8261.           
  8262.  
  8263.  
  8264.  
  8265.  
  8266.  
  8267.  
  8268.           PDLISP language manual                     Input and Output
  8269.           
  8270.  
  8271.  
  8272.  
  8273.  
  8274.  
  8275.  
  8276.  
  8277.           9.1 Console I/O
  8278.  
  8279.  
  8280.           This section will be available with release 2.0.
  8281.  
  8282.  
  8283.  
  8284.  
  8285.  
  8286.  
  8287.  
  8288.  
  8289.  
  8290.  
  8291.  
  8292.  
  8293.  
  8294.  
  8295.  
  8296.  
  8297.  
  8298.  
  8299.  
  8300.  
  8301.  
  8302.  
  8303.  
  8304.  
  8305.  
  8306.  
  8307.  
  8308.  
  8309.  
  8310.  
  8311.  
  8312.  
  8313.  
  8314.  
  8315.  
  8316.  
  8317.  
  8318.  
  8319.  
  8320.  
  8321.  
  8322.  
  8323.  
  8324.  
  8325.  
  8326.                                      - 121 -              Version 1.10
  8327.           
  8328.  
  8329.  
  8330.  
  8331.  
  8332.  
  8333.  
  8334.           PDLISP language manual                     Input and Output
  8335.           
  8336.  
  8337.  
  8338.  
  8339.  
  8340.                        This page intentionally left blank
  8341.  
  8342.  
  8343.  
  8344.  
  8345.  
  8346.  
  8347.  
  8348.  
  8349.  
  8350.  
  8351.  
  8352.  
  8353.  
  8354.  
  8355.  
  8356.  
  8357.  
  8358.  
  8359.  
  8360.  
  8361.  
  8362.  
  8363.  
  8364.  
  8365.  
  8366.  
  8367.  
  8368.  
  8369.  
  8370.  
  8371.  
  8372.  
  8373.  
  8374.  
  8375.  
  8376.  
  8377.  
  8378.  
  8379.  
  8380.  
  8381.  
  8382.  
  8383.  
  8384.  
  8385.  
  8386.  
  8387.  
  8388.  
  8389.  
  8390.  
  8391.  
  8392.                                      - 122 -              Version 1.10
  8393.           
  8394.  
  8395.  
  8396.  
  8397.  
  8398.  
  8399.  
  8400.           PDLISP language manual                     Input and Output
  8401.           
  8402.  
  8403.  
  8404.  
  8405.  
  8406.                        This page intentionally left blank
  8407.  
  8408.  
  8409.  
  8410.  
  8411.  
  8412.  
  8413.  
  8414.  
  8415.  
  8416.  
  8417.  
  8418.  
  8419.  
  8420.  
  8421.  
  8422.  
  8423.  
  8424.  
  8425.  
  8426.  
  8427.  
  8428.  
  8429.  
  8430.  
  8431.  
  8432.  
  8433.  
  8434.  
  8435.  
  8436.  
  8437.  
  8438.  
  8439.  
  8440.  
  8441.  
  8442.  
  8443.  
  8444.  
  8445.  
  8446.  
  8447.  
  8448.  
  8449.  
  8450.  
  8451.  
  8452.  
  8453.  
  8454.  
  8455.  
  8456.  
  8457.  
  8458.                                      - 123 -              Version 1.10
  8459.           
  8460.  
  8461.  
  8462.  
  8463.  
  8464.  
  8465.  
  8466.           PDLISP language manual                     Input and Output
  8467.           
  8468.  
  8469.  
  8470.  
  8471.  
  8472.  
  8473.  
  8474.  
  8475.           9.2 File I/O
  8476.  
  8477.  
  8478.           This section will be included with release 2.0, and will  be
  8479.           available as an update.  See /SYS/NEWS for more info. 
  8480.  
  8481.  
  8482.  
  8483.  
  8484.  
  8485.  
  8486.  
  8487.  
  8488.  
  8489.  
  8490.  
  8491.  
  8492.  
  8493.  
  8494.  
  8495.  
  8496.  
  8497.  
  8498.  
  8499.  
  8500.  
  8501.  
  8502.  
  8503.  
  8504.  
  8505.  
  8506.  
  8507.  
  8508.  
  8509.  
  8510.  
  8511.  
  8512.  
  8513.  
  8514.  
  8515.  
  8516.  
  8517.  
  8518.  
  8519.  
  8520.  
  8521.  
  8522.  
  8523.  
  8524.                                      - 124 -              Version 1.10
  8525.           
  8526.  
  8527.  
  8528.  
  8529.  
  8530.  
  8531.  
  8532.           PDLISP language manual                     Input and Output
  8533.           
  8534.  
  8535.  
  8536.  
  8537.  
  8538.                        This page intentionally left blank
  8539.  
  8540.  
  8541.  
  8542.  
  8543.  
  8544.  
  8545.  
  8546.  
  8547.  
  8548.  
  8549.  
  8550.  
  8551.  
  8552.  
  8553.  
  8554.  
  8555.  
  8556.  
  8557.  
  8558.  
  8559.  
  8560.  
  8561.  
  8562.  
  8563.  
  8564.  
  8565.  
  8566.  
  8567.  
  8568.  
  8569.  
  8570.  
  8571.  
  8572.  
  8573.  
  8574.  
  8575.  
  8576.  
  8577.  
  8578.  
  8579.  
  8580.  
  8581.  
  8582.  
  8583.  
  8584.  
  8585.  
  8586.  
  8587.  
  8588.  
  8589.  
  8590.                                      - 125 -              Version 1.10
  8591.           
  8592.  
  8593.  
  8594.  
  8595.  
  8596.  
  8597.  
  8598.           PDLISP language manual                     Input and Output
  8599.           
  8600.  
  8601.  
  8602.  
  8603.  
  8604.                        This page intentionally left blank
  8605.  
  8606.  
  8607.  
  8608.  
  8609.  
  8610.  
  8611.  
  8612.  
  8613.  
  8614.  
  8615.  
  8616.  
  8617.  
  8618.  
  8619.  
  8620.  
  8621.  
  8622.  
  8623.  
  8624.  
  8625.  
  8626.  
  8627.  
  8628.  
  8629.  
  8630.  
  8631.  
  8632.  
  8633.  
  8634.  
  8635.  
  8636.  
  8637.  
  8638.  
  8639.  
  8640.  
  8641.  
  8642.  
  8643.  
  8644.  
  8645.  
  8646.  
  8647.  
  8648.  
  8649.  
  8650.  
  8651.  
  8652.  
  8653.  
  8654.  
  8655.  
  8656.                                      - 126 -              Version 1.10
  8657.           
  8658.  
  8659.  
  8660.  
  8661.  
  8662.  
  8663.  
  8664.           PDLISP language manual                     Input and Output
  8665.           
  8666.  
  8667.  
  8668.  
  8669.  
  8670.           
  8671.  
  8672.  
  8673.  
  8674.  
  8675.           9.3 The PDLISP Reader
  8676.  
  8677.  
  8678.           This section will be available as an update. 
  8679.  
  8680.  
  8681.  
  8682.  
  8683.  
  8684.  
  8685.  
  8686.  
  8687.  
  8688.  
  8689.  
  8690.  
  8691.  
  8692.  
  8693.  
  8694.  
  8695.  
  8696.  
  8697.  
  8698.  
  8699.  
  8700.  
  8701.  
  8702.  
  8703.  
  8704.  
  8705.  
  8706.  
  8707.  
  8708.  
  8709.  
  8710.  
  8711.  
  8712.  
  8713.  
  8714.  
  8715.  
  8716.  
  8717.  
  8718.  
  8719.  
  8720.  
  8721.  
  8722.                                      - 127 -              Version 1.10
  8723.           
  8724.  
  8725.  
  8726.  
  8727.  
  8728.  
  8729.  
  8730.           PDLISP language manual                     Input and Output
  8731.           
  8732.  
  8733.  
  8734.  
  8735.  
  8736.                        This page intentionally left blank
  8737.  
  8738.  
  8739.  
  8740.  
  8741.  
  8742.  
  8743.  
  8744.  
  8745.  
  8746.  
  8747.  
  8748.  
  8749.  
  8750.  
  8751.  
  8752.  
  8753.  
  8754.  
  8755.  
  8756.  
  8757.  
  8758.  
  8759.  
  8760.  
  8761.  
  8762.  
  8763.  
  8764.  
  8765.  
  8766.  
  8767.  
  8768.  
  8769.  
  8770.  
  8771.  
  8772.  
  8773.  
  8774.  
  8775.  
  8776.  
  8777.  
  8778.  
  8779.  
  8780.  
  8781.  
  8782.  
  8783.  
  8784.  
  8785.  
  8786.  
  8787.  
  8788.                                      - 128 -              Version 1.10
  8789.           
  8790.  
  8791.  
  8792.  
  8793.  
  8794.  
  8795.  
  8796.           PDLISP language manual                     Input and Output
  8797.           
  8798.  
  8799.  
  8800.  
  8801.  
  8802.                        This page intentionally left blank
  8803.  
  8804.  
  8805.  
  8806.  
  8807.  
  8808.  
  8809.  
  8810.  
  8811.  
  8812.  
  8813.  
  8814.  
  8815.  
  8816.  
  8817.  
  8818.  
  8819.  
  8820.  
  8821.  
  8822.  
  8823.  
  8824.  
  8825.  
  8826.  
  8827.  
  8828.  
  8829.  
  8830.  
  8831.  
  8832.  
  8833.  
  8834.  
  8835.  
  8836.  
  8837.  
  8838.  
  8839.  
  8840.  
  8841.  
  8842.  
  8843.  
  8844.  
  8845.  
  8846.  
  8847.  
  8848.  
  8849.  
  8850.  
  8851.  
  8852.  
  8853.  
  8854.                                      - 129 -              Version 1.10
  8855.           
  8856.  
  8857.  
  8858.  
  8859.  
  8860.  
  8861.  
  8862.           PDLISP language manual                     Input and Output
  8863.           
  8864.  
  8865.  
  8866.  
  8867.  
  8868.                        This page intentionally left blank
  8869.  
  8870.  
  8871.  
  8872.  
  8873.  
  8874.  
  8875.  
  8876.  
  8877.  
  8878.  
  8879.  
  8880.  
  8881.  
  8882.  
  8883.  
  8884.  
  8885.  
  8886.  
  8887.  
  8888.  
  8889.  
  8890.  
  8891.  
  8892.  
  8893.  
  8894.  
  8895.  
  8896.  
  8897.  
  8898.  
  8899.  
  8900.  
  8901.  
  8902.  
  8903.  
  8904.  
  8905.  
  8906.  
  8907.  
  8908.  
  8909.  
  8910.  
  8911.  
  8912.  
  8913.  
  8914.  
  8915.  
  8916.  
  8917.  
  8918.  
  8919.  
  8920.                                      - 130 -              Version 1.10
  8921.           
  8922.  
  8923.  
  8924.  
  8925.  
  8926.  
  8927.  
  8928.           PDLISP language manual                     Input and Output
  8929.           
  8930.  
  8931.  
  8932.  
  8933.  
  8934.                        This page intentionally left blank
  8935.  
  8936.  
  8937.  
  8938.  
  8939.  
  8940.  
  8941.  
  8942.  
  8943.  
  8944.  
  8945.  
  8946.  
  8947.  
  8948.  
  8949.  
  8950.  
  8951.  
  8952.  
  8953.  
  8954.  
  8955.  
  8956.  
  8957.  
  8958.  
  8959.  
  8960.  
  8961.  
  8962.  
  8963.  
  8964.  
  8965.  
  8966.  
  8967.  
  8968.  
  8969.  
  8970.  
  8971.  
  8972.  
  8973.  
  8974.  
  8975.  
  8976.  
  8977.  
  8978.  
  8979.  
  8980.  
  8981.  
  8982.  
  8983.  
  8984.  
  8985.  
  8986.                                      - 131 -              Version 1.10
  8987.           
  8988.  
  8989.  
  8990.  
  8991.  
  8992.  
  8993.  
  8994.           PDLISP language manual                     Input and Output
  8995.           
  8996.  
  8997.  
  8998.  
  8999.  
  9000.           
  9001.  
  9002.  
  9003.  
  9004.  
  9005.           9.4 Floating Point Formats
  9006.  
  9007.  
  9008.           The  floating  point  output  format  is controlled via  the
  9009.           "floating point format hook".  Setting  the  floating  point
  9010.           format hook is covered in the chapter on the STATUS function
  9011.           and system hooks. 
  9012.  
  9013.           
  9014.  
  9015.  
  9016.  
  9017.  
  9018.  
  9019.  
  9020.  
  9021.  
  9022.  
  9023.  
  9024.  
  9025.  
  9026.  
  9027.  
  9028.  
  9029.  
  9030.  
  9031.  
  9032.  
  9033.  
  9034.  
  9035.  
  9036.  
  9037.  
  9038.  
  9039.  
  9040.  
  9041.  
  9042.  
  9043.  
  9044.  
  9045.  
  9046.  
  9047.  
  9048.  
  9049.  
  9050.  
  9051.  
  9052.                                      - 132 -              Version 1.10
  9053.           
  9054.  
  9055.  
  9056.  
  9057.  
  9058.  
  9059.  
  9060.           PDLISP language manual                     Input and Output
  9061.           
  9062.  
  9063.  
  9064.  
  9065.  
  9066.                        This page intentionally left blank
  9067.  
  9068.  
  9069.  
  9070.  
  9071.  
  9072.  
  9073.  
  9074.  
  9075.  
  9076.  
  9077.  
  9078.  
  9079.  
  9080.  
  9081.  
  9082.  
  9083.  
  9084.  
  9085.  
  9086.  
  9087.  
  9088.  
  9089.  
  9090.  
  9091.  
  9092.  
  9093.  
  9094.  
  9095.  
  9096.  
  9097.  
  9098.  
  9099.  
  9100.  
  9101.  
  9102.  
  9103.  
  9104.  
  9105.  
  9106.  
  9107.  
  9108.  
  9109.  
  9110.  
  9111.  
  9112.  
  9113.  
  9114.  
  9115.  
  9116.  
  9117.  
  9118.                                      - 133 -              Version 1.10
  9119.           
  9120.  
  9121.  
  9122.  
  9123.  
  9124.  
  9125.  
  9126.           PDLISP language manual                     Input and Output
  9127.           
  9128.  
  9129.  
  9130.  
  9131.  
  9132.                        This page intentionally left blank
  9133.  
  9134.  
  9135.  
  9136.  
  9137.  
  9138.  
  9139.  
  9140.  
  9141.  
  9142.  
  9143.  
  9144.  
  9145.  
  9146.  
  9147.  
  9148.  
  9149.  
  9150.  
  9151.  
  9152.  
  9153.  
  9154.  
  9155.  
  9156.  
  9157.  
  9158.  
  9159.  
  9160.  
  9161.  
  9162.  
  9163.  
  9164.  
  9165.  
  9166.  
  9167.  
  9168.  
  9169.  
  9170.  
  9171.  
  9172.  
  9173.  
  9174.  
  9175.  
  9176.  
  9177.  
  9178.  
  9179.  
  9180.  
  9181.  
  9182.  
  9183.  
  9184.                                      - 134 -              Version 1.10
  9185.           
  9186.  
  9187.  
  9188.