home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / snobol / aisnobol / report2.doc < prev    next >
Text File  |  1987-10-18  |  148KB  |  5,677 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.                                      APPENDIX F
  9.  
  10.             This is an alphabetical listing of all the SNOLISPIST
  11.           functions, with detailed descriptions, examples, and references.
  12.  
  13.             Core functions are marked with an asterisk (*).
  14.  
  15.             The following abbreviations are used to indicate the datatype
  16.           of arguments to the functions:
  17.  
  18.             S       'STRING'
  19.  
  20.             L       'CONS' (i.e., list)
  21.  
  22.             N       'NUMERIC' ('REAL', 'DREAL', or 'INTEGER')
  23.  
  24.             NAME    'NAME'
  25.  
  26.             A       'ARRAY'
  27.  
  28.             X       any
  29.  
  30.  
  31.  
  32.  
  33.  
  34.           +-----------------------------+
  35.           | ABS(N)                      |
  36.           +-----------------------------+
  37.  
  38.             Returns -N if N is negative; otherwise N.
  39.  
  40.             General Categories: Arithmetic function
  41.  
  42.             Example: ABS( -9.345567) returns 9.345567
  43.  
  44.             Comments: N may be integer, real, or double precision.  String
  45.                to numeric conversion, if necessary, is handled
  46.                automatically.
  47.  
  48.             References:
  49.                Charniak et al. (1980), 301.
  50.                MTS LISP Manual, 26.
  51.                Shapiro (1979), 148.
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.        AI Programming in SNOBOL4       - 87 -                    August, 1982
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.           +-----------------------------+
  74.           | ACOS(N)                     |
  75.           +-----------------------------+
  76.  
  77.             Returns the inverse cosine of N, -1 <= N <= 1.  The result is
  78.                in radians.
  79.  
  80.             General Categories: Arithmetic function
  81.  
  82.             Example: ACOS(-DIV(1,6)) returns 1.7382444060158.
  83.  
  84.             References:
  85.                Gimpel (1976), 336.
  86.  
  87.  
  88.  
  89.  
  90.  
  91.           +-----------------------------+
  92.           | ADD(N1,N2)                  |
  93.           +-----------------------------+
  94.  
  95.             Returns N1 + N2.
  96.  
  97.             General Categories: Arithmetic function
  98.  
  99.             Example: ADD(3.7,19.4) returns 23.1.
  100.  
  101.              Comments: Any combination of numeric datatypes is legal.
  102.                "Mixed mode" errors are not a problem.  Note that ADD is
  103.                strictly binary.  See PLUS for a similar function which
  104.                takes a list argument.
  105.  
  106.             References:
  107.                MTS LISP Manual, 26.
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.        AI Programming in SNOBOL4       - 88 -                    August, 1982
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.           +-----------------------------+
  140.           | ADD1(N)                     |
  141.           +-----------------------------+
  142.  
  143.             Returns N + 1.
  144.  
  145.             General Categories: Arithmetic function
  146.  
  147.             Example: ADD1(17) returns 18.
  148.  
  149.             Comments: The value of the argument N is not changed.
  150.  
  151.             References:
  152.                Charniak et al. (1980), 301.
  153.                MTS LISP Manual, 26.
  154.                Shapiro (1979), 148.
  155.  
  156.  
  157.  
  158.  
  159.  
  160.           +-----------------------------+
  161.           | ADDPROP(NAME,X,S)           |
  162.           +-----------------------------+
  163.  
  164.             Returns the (entire) altered property list of NAME.
  165.  
  166.             General Categories: List composition
  167.                List search
  168.                Property-list function
  169.  
  170.             Side Effects: May alter the property list of NAME.
  171.  
  172.             Example: ADDPROP( .DOG, 4, 'LEGS') will search the property
  173.                list of .DOG for the indicator 'LEGS'.  If 'LEGS' is not
  174.                found, then ('LEGS' ~ 4 ~ NIL) will be CONSed onto the
  175.                property list.  If 'LEGS' is found, then its associated list
  176.                of values is searched for 4.  If 4 is found, nothing
  177.                happens.  Otherwise, 4 is added to the list of values (all
  178.                the other values remain).
  179.                  If X is NIL, and if S is already an indicator on the
  180.                property list, then nothing changes.  If X is NIL and S is
  181.                not an indicator, then (S ~ NIL) is added to the property
  182.                list.
  183.  
  184.             References:
  185.                Charniak et al. (1980), 302.
  186.                MTS LISP Manual, 25.
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.        AI Programming in SNOBOL4       - 89 -                    August, 1982
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.           +-----------------------------+
  206.           | APPEND(L)                   |
  207.           +-----------------------------+
  208.  
  209.             Returns a list consisting of the top-level elements of CAR(L),
  210.                followed by the top-level elements of CADR(L), followed by
  211.                the top-level elements of CADDR(L), etc.
  212.  
  213.             General Categories: List composition
  214.  
  215.             Example:  Suppose L1 = #'(A B)',
  216.                               L2 = #'(C D E)', and
  217.                               L3 = #'"(F G (H I))'.
  218.                       Then APPEND(L1 ~ L2 ~ L3 ~ NIL) returns
  219.                      ('A' ~ 'B' ~ 'C' ~ 'D' ~ 'E' ~ 'F' ~ 'G' ~ ('H' ~
  220.                       'I' ~ NIL) ~ NIL).
  221.  
  222.             Comments: APPEND takes one argument, which must be a list of
  223.                lists, ending with NIL.
  224.  
  225.             References: Charniak et al. (1980), 302.
  226.                MTS LISP Manual, 20 (CONC, not APPEND!).
  227.                Schank & Riesbeck (1981), 54.
  228.                Shapiro (1979), 148.
  229.  
  230.  
  231.  
  232.  
  233.  
  234.           +-----------------------------+
  235.           | ASIN(N)                     |
  236.           +-----------------------------+
  237.  
  238.             Returns the inverse sine of N, -1 <= N <= 1.  The result is in
  239.                radians.
  240.  
  241.             General Categories: Arithmetic function
  242.  
  243.             Example: ASIN(DIV(1,SQRT(2)) returns 0.78539816339773.
  244.  
  245.             References: Gimpel (1976), 334.
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262.        AI Programming in SNOBOL4       - 90 -                    August, 1982
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.           +-----------------------------+
  272.           | ASSOC(X,L)                  |
  273.           +-----------------------------+
  274.  
  275.             Returns the tail of L, beginning with the first top-level
  276.                element whose CAR is EQUAL to X.  If no such element of L is
  277.                found, ASSOC returns NIL.
  278.  
  279.             General Categories: List decomposition
  280.                List search
  281.  
  282.             Example:  Suppose L = #'((1 A) (2 B) (3 C) (4 D))'.
  283.                       Then ASSOC(3,L) returns #'((3 C) (4 D))'.
  284.  
  285.             Comments: Note that EQUAL is used, not EQU.
  286.  
  287.             References: Charniak et al. (1980), 302.
  288.                MTS LISP Manual, 19.
  289.                Schank & Riesbeck (1981), 55.
  290.                Shapiro (1979), 149.
  291.  
  292.  
  293.  
  294.  
  295.  
  296.           +-----------------------------+
  297.           | ASSOCL(L1,L2)               |
  298.           +-----------------------------+
  299.  
  300.             Returns the tail of L2, beginning with the first element whose
  301.                CAR is a MEMBER of L1.  If no element of L1 produces a match
  302.                in L2, ASSOCL returns NIL.
  303.  
  304.             General Categories: List decomposition
  305.                List search
  306.  
  307.             Example: Suppose L1 = #'(9 3 4 1 2)' and
  308.                              L2 = #'((1 A) (2 B) (3 C) (4 D))'.
  309.                      Then ASSOCL(L1,L2) returns all of L2.
  310.  
  311.  
  312.  
  313.  
  314.  
  315.  
  316.  
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.  
  328.        AI Programming in SNOBOL4       - 91 -                    August, 1982
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336.  
  337.           +-----------------------------+
  338.           | ATAN(N)                     |
  339.           +-----------------------------+
  340.  
  341.             Returns the inverse tangent of N.  The result is in radians.
  342.  
  343.             General Categories: Arithmetic function
  344.  
  345.             Example: ATAN(2) returns 1.1071487177935.
  346.  
  347.             References: Gimpel (1976), 334.
  348.  
  349.  
  350.  
  351.  
  352.  
  353.           +-----------------------------+
  354.           | *ATOM(X)                    |
  355.           +-----------------------------+
  356.  
  357.             Returns the null string.  It succeeds if X does not have the
  358.                datatype 'CONS', and fails otherwise.
  359.  
  360.             General Categories: Predicate
  361.  
  362.             Example: ATOM('A' ~ 17 ~ NIL) fails.
  363.  
  364.             Comments: ATOM succeeds for all built-in SPITBOL datatypes, as
  365.                well as for all programmer-defined datatypes except 'CONS'.
  366.  
  367.             References: Charniak et al. (1980), 302.
  368.                MTS LISP Manual, 17.
  369.                Schank & Riesbeck (1981), 55.
  370.                Shapiro (1979), 149.
  371.  
  372.  
  373.  
  374.  
  375.  
  376.           +-----------------------------+
  377.           | ATOMP(X)                    |
  378.           +-----------------------------+
  379.  
  380.             Returns T if X does not have the datatype 'CONS', and NIL
  381.                otherwise.
  382.  
  383.             General Categories: Predicate
  384.  
  385.             Example: ATOMP("A17NIL') returns T.
  386.  
  387.             Comments: See ATOM.
  388.  
  389.             References: See ATOM.
  390.  
  391.  
  392.  
  393.  
  394.        AI Programming in SNOBOL4       - 92 -                    August, 1982
  395.  
  396.  
  397.  
  398.  
  399.  
  400.  
  401.  
  402.  
  403.           +-----------------------------+
  404.           | CAL(A)                      |
  405.           +-----------------------------+
  406.  
  407.             Returns a list of the elements of the array A.  The array must
  408.                be one-dimensional.
  409.  
  410.             General Categories: List composition
  411.  
  412.             Example: If A<1> = 1, A<2> = "2", A<3> = "THREE", A<4> =
  413.                "four", and A<5> = 5, then CAL(A) returns
  414.                (1 ~ "2" ~ "THREE" ~ "four" ~ 5 ~ NIL).
  415.  
  416.  
  417.  
  418.  
  419.  
  420.           +-----------------------------+
  421.           | *CAR(L)                     |
  422.           +-----------------------------+
  423.  
  424.             Returns the first top-level element of the list L.  It can also
  425.                be used on the left-hand side of an assignment statement to
  426.                change the CAR of L (cf. RPLACA).
  427.  
  428.             General Categories: Alters existing CONS cell(s)
  429.                List composition
  430.                List decomposition
  431.  
  432.             Side Effects: If used on the left-hand side of an assignment
  433.                statement, CAR can have bad side-effects, e.g., creating
  434.                circular lists: CAR(L) = L.  Any function which alters
  435.                existing CONS cells can cause similar problems.  Such
  436.                functions can also cause unintended changes in the values of
  437.                identifiers which are not referenced directly in the
  438.                assignment statement.  These functions should be used
  439.                carefully (see references).
  440.  
  441.             Example: If L = #'((8 A B) (10807 W) (60) (T (H)))', then
  442.                CAR(L) = (8 ~ 'A' ~ 'B' ~ NIL).
  443.  
  444.             Comments: Note that CAR(L) = X has a different effect in
  445.                SNOLISPIST than (SET (CAR L) X) would have in LISP.
  446.  
  447.             References: Charniak et al. (1980), 9, 10, 19-21, 302.
  448.                MTS LISP Manual, 12-14, 18-19, 22-23.
  449.                Schank & Riesbeck (1981), 55.
  450.                Shapiro (1979), 149-150.
  451.  
  452.  
  453.  
  454.  
  455.  
  456.  
  457.  
  458.  
  459.  
  460.        AI Programming in SNOBOL4       - 93 -                    August, 1982
  461.  
  462.  
  463.  
  464.  
  465.  
  466.  
  467.  
  468.  
  469.           +-----------------------------+
  470.           | *CDR(L)                     |
  471.           +-----------------------------+
  472.  
  473.             Returns the tail of L, i.e., L with its first top-level element
  474.                deleted.  CDR can also be used on the left- hand side of an
  475.                assignment statement: CDR(L) = X has the same effect as
  476.                RPLACD(L,X).  (See CAR.)
  477.  
  478.             General Categories: Alters existing CONS cell(s)
  479.                List composition
  480.                List decomposition
  481.  
  482.             Side Effects: See CAR.
  483.  
  484.             Example: If L = ('P' ~ 'Q' ~ NIL), then CDR(L) returns ('Q' ~
  485.                NIL).  Note that if L is a "normal" list, then CDR always
  486.                returns a list, not an atom.
  487.  
  488.             Comments: See CAR.
  489.  
  490.             References: See CAR.
  491.  
  492.  
  493.  
  494.  
  495.  
  496.           +-----------------------------+
  497.           | CAAR(L) through CDDDDR(L)   |
  498.           +-----------------------------+
  499.  
  500.             Return the result of the composition of from two to four CARs
  501.                and CDRs.  All combinations of two to four A's and D's are
  502.                legal.  CADR(L) returns CAR(CDR(L)), CADAR(L) returns
  503.                CAR(CDR(CAR(L))), and so on.
  504.  
  505.             General Categories: List decomposition
  506.  
  507.             Example: If L = #'(A (B C D) 5 4 ((3 (2 1))))', then CADR(L)
  508.                returns ('B' ~ 'C' ~ 'D' ~ NIL).
  509.  
  510.             References: Charniak et al. (1980), 19-23, 302.
  511.                MTS LISP Manual, 19.
  512.                Schank & Riesbeck (1981), 45-49, 55.
  513.                Shapiro (1979), 149-150.
  514.  
  515.  
  516.  
  517.  
  518.  
  519.  
  520.  
  521.  
  522.  
  523.  
  524.  
  525.  
  526.        AI Programming in SNOBOL4       - 94 -                    August, 1982
  527.  
  528.  
  529.  
  530.  
  531.  
  532.  
  533.  
  534.  
  535.           +-----------------------------+
  536.           | CEIL(N)                     |
  537.           +-----------------------------+
  538.  
  539.             Returns the smallest integer not smaller than N.  N may be any
  540.                integer or floating point number.
  541.  
  542.             General Categories: Arithmetic function
  543.  
  544.             Example: CEIL(8.8) returns 9.
  545.  
  546.             References: Gimpel (1976), 327.
  547.  
  548.  
  549.  
  550.  
  551.  
  552.           +-----------------------------+
  553.           | CLA(L)                      |
  554.           +-----------------------------+
  555.  
  556.             Returns the elements of the list L converted to a one-
  557.                dimensional array.
  558.  
  559.             General categories: Datatype conversion
  560.  
  561.             Example: If L = ('E' ~ 'D' ~ 'C' ~ 'B' ~ 'A' ~ NIL), then
  562.                CLA(L) returns an array of five elements: 'E', 'D', 'C',
  563.                'B', and 'A'.
  564.  
  565.  
  566.  
  567.  
  568.  
  569.           +-----------------------------+
  570.           | CLOG(N)                     |
  571.           +-----------------------------+
  572.  
  573.             Returns log(N) (base 10).  N may be any positive integer or
  574.                floating point number.
  575.  
  576.             General Categories: Arithmetic function
  577.  
  578.             Example: CLOG(97) returns 1.9867717387128.
  579.  
  580.             References: Gimpel (1976), 335-336.
  581.  
  582.  
  583.  
  584.  
  585.  
  586.  
  587.  
  588.  
  589.  
  590.  
  591.  
  592.        AI Programming in SNOBOL4       - 95 -                    August, 1982
  593.  
  594.  
  595.  
  596.  
  597.  
  598.  
  599.  
  600.  
  601.           +-----------------------------+
  602.           | *CONCAT(L,S1,S2)            |
  603.           +-----------------------------+
  604.  
  605.             Returns a single string consisting of the concatenation of the
  606.                elements of L.  S1, if present, will be inserted after each
  607.                element except the last.   (S1 might be a blank or a comma.)
  608.                S2, if present, will be placed before and after each
  609.                element.   (S2 might be a quotation mark.)
  610.  
  611.             General Categories: Datatype conversion
  612.  
  613.             Example: Let L = 'PAY' ~ 'YOUR' ~ 'DUES' ~ NIL.  CONCAT(L,'
  614.                ','"') will return '"PAY" "YOUR" "DUES"' as a single string.
  615.                (The double quotes are part of the string.)
  616.  
  617.             Comments: This function was originally written as a utility
  618.                function for UNREAD.  It has also proved useful in the
  619.                construction of expressions at run-time.
  620.  
  621.  
  622.  
  623.  
  624.  
  625.           +-----------------------------+
  626.           | *CONS(X,Y)                  |
  627.           +-----------------------------+
  628.  
  629.             Returns a new CONS cell c such that CAR(c) = X and
  630.                CDR(c) = Y.
  631.  
  632.             General Categories: List composition
  633.  
  634.             Example: CONS('A',CONS('B',CONS('C',NIL))) returns the list
  635.                ('A' ~ 'B' ~ 'C' ~ NIL).
  636.  
  637.             References: Charniak et al.(1980), 11, 19, 22-24, 302-303.
  638.                MTS LISP Manual, 12-14, 20.
  639.                Schank & Riesbeck (1981), 55.
  640.                Shapiro (1979), 150.
  641.  
  642.  
  643.  
  644.  
  645.  
  646.  
  647.  
  648.  
  649.  
  650.  
  651.  
  652.  
  653.  
  654.  
  655.  
  656.  
  657.  
  658.        AI Programming in SNOBOL4       - 96 -                    August, 1982
  659.  
  660.  
  661.  
  662.  
  663.  
  664.  
  665.  
  666.  
  667.           +-----------------------------+
  668.           | COS(N)                      |
  669.           +-----------------------------+
  670.  
  671.             Returns the cosine of N radians.  N may be any integer or
  672.                floating point number.
  673.  
  674.             General Categories: Arithmetic function
  675.  
  676.             Example: COS(-P...I. / 6) returns 0.86602540378456.
  677.  
  678.             References: Gimpel (1976), 332-333.
  679.  
  680.  
  681.  
  682.  
  683.  
  684.           +-----------------------------+
  685.           | DEFPROP(NAME,X,S)           |
  686.           +-----------------------------+
  687.  
  688.             Returns the modified property list of NAME.
  689.  
  690.             General Categories: Alters existing CONS cell(s)
  691.                Property-list function
  692.  
  693.             Side Effects: X is put on the property list of NAME under the
  694.                indicator S.  DEFPROP operates in a manner similar to PUT:
  695.                Previous values of the indicator S are erased.
  696.                   If X is NIL, then S is placed on the property list as an
  697.                indicator with no associated values.
  698.  
  699.             Example: DEFPROP( .DOG, 4, 'LEGS') makes sure that
  700.                ('LEGS' ~ 4 ~ NIL) is on the property list of DOG.
  701.  
  702.             References: Shapiro (1979), 150.
  703.  
  704.  
  705.  
  706.  
  707.  
  708.           +-----------------------------+
  709.           | DEG(N)                      |
  710.           +-----------------------------+
  711.  
  712.             Returns the number of degrees in N radians.
  713.  
  714.             General Categories: Arithmetic function
  715.  
  716.             Example: DEG(P...I. / 4) returns 45.000000000013.
  717.  
  718.  
  719.  
  720.  
  721.  
  722.  
  723.  
  724.        AI Programming in SNOBOL4       - 97 -                    August, 1982
  725.  
  726.  
  727.  
  728.  
  729.  
  730.  
  731.  
  732.  
  733.           +-----------------------------+
  734.           | DFLOAT(N)                   |
  735.           +-----------------------------+
  736.  
  737.             Returns N converted to datatype 'DREAL', if possible; otherwise
  738.                it fails.
  739.  
  740.             General Categories: Arithmetic function
  741.                Datatype conversion
  742.  
  743.             Example: DFLOAT(8) returns 8.D00, a 7-byte floating-point
  744.                number.
  745.  
  746.             Comments: SPITBOL supports double precision floating- point
  747.                numbers, an extension of SNOBOL4.
  748.  
  749.             +-----------------------------+
  750.                | DIFFERENCE(L)     |
  751.                +-----------------------------+
  752.  
  753.             Returns the first element of L minus the sum of the rest.
  754.  
  755.             General Categories: Arithmetic function
  756.  
  757.             Example: DIFFERENCE(3 ~ 4 ~ 5 ~ 6 ~ -12 ~ NIL) returns 0, since
  758.                3 - 4 - 5 - 6 - (-12) = 0.
  759.  
  760.             Comments: The argument to DIFFERENCE must be a list of numbers;
  761.                the list must end with NIL.  Cf. SUB, which is strictly
  762.                binary.
  763.  
  764.             References: Charniak et al. (1980), 303.
  765.                Schank & Riesbeck (1981), 55-56.
  766.                Shapiro (1979), 150.
  767.  
  768.  
  769.  
  770.  
  771.  
  772.           +-----------------------------+
  773.           | DIV(N1,N2)                  |
  774.           +-----------------------------+
  775.  
  776.             Returns N1 / N2 in double precision.
  777.  
  778.             General Categories: Arithmetic function
  779.  
  780.             Example: DIV(7,8) returns .875.
  781.  
  782.             Comments: Datatype conversion (to DREAL) is handled
  783.                automatically, so that DIV(7,8) is .875, not 0.
  784.  
  785.             References: MTS LISP Manual, 26.
  786.  
  787.  
  788.  
  789.  
  790.        AI Programming in SNOBOL4       - 98 -                    August, 1982
  791.  
  792.  
  793.  
  794.  
  795.  
  796.  
  797.  
  798.  
  799.           +-----------------------------+
  800.           | EQP(X,Y)                    |
  801.           +-----------------------------+
  802.  
  803.             Returns T if EQU(X,Y) succeeds; NIL otherwise.
  804.  
  805.             General Categories: Predicate
  806.  
  807.             Example: See EQU.
  808.  
  809.             Comments: See EQU.
  810.  
  811.             References: See EQU.
  812.  
  813.  
  814.  
  815.  
  816.  
  817.           +-----------------------------+
  818.           | EQU(X,Y)                    |
  819.           +-----------------------------+
  820.  
  821.             Returns the null string.  It succeeds if X and Y are equal
  822.                numbers (as judged by the SPITBOL EQ function), or if they
  823.                are lexically equal strings (as judged by the SPITBOL LEQ
  824.                function), or if they are identical (as judged by the
  825.                SPITBOL IDENT function); fails otherwise.
  826.  
  827.             General Categories: Predicate
  828.  
  829.             Examples: All these succeed: EQU(8,'8'), EQU('8',8.0),
  830.                EQU('A',CAR('A' ~ NIL)), EQU('CAT',REVERSE('TAC')),
  831.                EQU(NIL,CDDR('S' ~ 'F' ~ NIL)).
  832.  
  833.             Comments: This predicate is similar to the LISP EQ predicate
  834.                (EQ is a built-in numeric predicate in SPITBOL; hence the
  835.                name-change).  Cf. EQP, EQUAL, and EQUALP.
  836.  
  837.             References.: Charniak et al. (1980), 304.
  838.                MTS LISP Manual, 17.
  839.                Shapiro (1979), 151.
  840.  
  841.  
  842.  
  843.  
  844.  
  845.  
  846.  
  847.  
  848.  
  849.  
  850.  
  851.  
  852.  
  853.  
  854.  
  855.  
  856.        AI Programming in SNOBOL4       - 99 -                    August, 1982
  857.  
  858.  
  859.  
  860.  
  861.  
  862.  
  863.  
  864.  
  865.           +-----------------------------+
  866.           | EQUAL(X,Y)                  |
  867.           +-----------------------------+
  868.  
  869.             Returns the null string.  It succeeds if EQU(X,Y) succeeds, or
  870.                if X and Y are lists which would PRINT as lexically equal
  871.                (LEQ) strings; otherwise, it fails.
  872.  
  873.             General Categories: Predicate
  874.  
  875.             Example: See EQU.  In addition, the following succeeds, while
  876.                the analogous EQU expression would fail:
  877.                EQUAL(7 ~ 8 ~ NIL, 7 ~ 8 ~ NIL).
  878.  
  879.             Comments: EQU and EQUAL behave identically except when their
  880.                arguments are programmer-defined datatypes, such as 'CONS'.
  881.                EQU can succeed, given two list-valued arguments, if the two
  882.                happen to point to precisely the same list.  In general,
  883.                however, they won't, even if their respective values look
  884.                exactly the same.  This is because SPITBOL, like LISP, will
  885.                not store duplicate copies of identical strings, but will
  886.                store duplicate copies of identical-looking lists.
  887.  
  888.             References: Charniak et al. (1980), 23-24, 304.
  889.                MTS LISP Manual, 17.
  890.                Schank & Riesbeck (1981), 56.
  891.                Shapiro (1979), 151.
  892.  
  893.  
  894.  
  895.  
  896.  
  897.           +-----------------------------+
  898.           | EQUALP(X,Y)                 |
  899.           +-----------------------------+
  900.  
  901.             Returns T if EQUAL(X,Y) succeeds; NIL otherwise.
  902.  
  903.             General Categories: Predicate
  904.  
  905.             Example: See EQUAL.
  906.  
  907.             Comments: See EQUAL.
  908.  
  909.             References: See EQUAL.
  910.  
  911.  
  912.  
  913.  
  914.  
  915.  
  916.  
  917.  
  918.  
  919.  
  920.  
  921.  
  922.        AI Programming in SNOBOL4      - 100 -                    August, 1982
  923.  
  924.  
  925.  
  926.  
  927.  
  928.  
  929.  
  930.  
  931.           +-----------------------------+
  932.           | EVALCODE(S)                 |
  933.           +-----------------------------+
  934.  
  935.             Returns the value of S, interpreted and evaluated as a SNOBOL4
  936.                (SPITBOL) expression.  If the evaluation of the expression
  937.                fails, EVALCODE fails.
  938.  
  939.             General Categories.: Depends on S
  940.  
  941.             Side Effects: Depends on S.
  942.  
  943.             Example: EVALCODE('DUPL(" ",12)') returns a string of 12
  944.                blanks.
  945.  
  946.             Comments: EVALCODE is mainly useful for evaluating expressions
  947.                which are constructed during program execution. The
  948.                references below are to the LISP EVAL function, which has a
  949.                similar purpose.
  950.  
  951.             References: Charniak et al. (1980), 304.
  952.                MTS LISP Manual, 27.
  953.                Schank & Riesbeck (1981), 56.
  954.                Shapiro (1979), 151.
  955.  
  956.  
  957.  
  958.  
  959.  
  960.           +-----------------------------+
  961.           | EVERY(NAME,L)               |
  962.           +-----------------------------+
  963.  
  964.             Returns T if the function named NAME returns a non-NIL value
  965.                for every argument on the list L; otherwise, NIL.
  966.  
  967.             General Categories: List composition
  968.                Mapping function
  969.  
  970.             Example: EVERY( .NUMBERP, 6 ~ '7' ~ -8.888 ~ 'TWO' ~ NIL)
  971.                returns NIL because NUMBERP('TWO') returns NIL.
  972.  
  973.             References: Charniak et al. (1980), 304.
  974.  
  975.  
  976.  
  977.  
  978.  
  979.  
  980.  
  981.  
  982.  
  983.  
  984.  
  985.  
  986.  
  987.  
  988.        AI Programming in SNOBOL4      - 101 -                    August, 1982
  989.  
  990.  
  991.  
  992.  
  993.  
  994.  
  995.  
  996.  
  997.           +-----------------------------+
  998.           | EVLIS(L)                    |
  999.           +-----------------------------+
  1000.  
  1001.             Returns a list of the values of the identifiers whose names are
  1002.                the elements of L.
  1003.  
  1004.             General Categories: List composition
  1005.                Mapping function
  1006.  
  1007.             Example: If A = 1.657, B = 'UNION', C = '?', and
  1008.                L = .A ~ .B ~ .C ~ NIL, then EVLIS(L) returns
  1009.                (1.657 ~ 'UNION' ~ '?' ~ NIL).
  1010.  
  1011.             Comments: The elements of L may be strings or names. They
  1012.                should not be deferred (unevaluated) expressions.
  1013.  
  1014.             References: MTS LISP Manual, 20.
  1015.                Shapiro (1979), 151.
  1016.  
  1017.  
  1018.  
  1019.  
  1020.  
  1021.           +-----------------------------+
  1022.           | EXCLUDE(L1,L2)              |
  1023.           +-----------------------------+
  1024.  
  1025.             Returns the top-level elements of L1, excluding any which are
  1026.                EQUAL to any element of L2.  No duplicate elements will
  1027.                appear in the result (cf. INTERSECT and UNION).
  1028.  
  1029.             General Categories: List composition
  1030.                List decomposition
  1031.                List search
  1032.  
  1033.             Example: If L1 = (8 ~ 'A' ~ '7' ~ 'D' ~ NIL) and
  1034.                      L2 = (7 ~ '8' ~ NIL), then EXCLUDE(L1,L2) returns
  1035.                      ('A' ~ 'D' ~ NIL).
  1036.  
  1037.             Comments: This version of EXCLUDE is in the INTERSECT- UNION
  1038.                family; hence the elimination of duplicates in the result.
  1039.  
  1040.             References: MTS LISP Manual, 21.
  1041.  
  1042.  
  1043.  
  1044.  
  1045.  
  1046.  
  1047.  
  1048.  
  1049.  
  1050.  
  1051.  
  1052.  
  1053.  
  1054.        AI Programming in SNOBOL4      - 102 -                    August, 1982
  1055.  
  1056.  
  1057.  
  1058.  
  1059.  
  1060.  
  1061.  
  1062.  
  1063.           +-----------------------------+
  1064.           | EXP(N)                      |
  1065.           +-----------------------------+
  1066.  
  1067.             Returns e**N, where e is the base of the natural logarithms and
  1068.                N is any integer or floating point number.  The value of e,
  1069.                in double precision, is stored as the value of NAT...BASE.
  1070.                in SNOLISPIST.
  1071.  
  1072.             General Categories: Arithmetic function
  1073.  
  1074.             Example: EXP(P...I.) returns 23.140692632773.
  1075.  
  1076.             References: Gimpel (1976), 336-337.
  1077.  
  1078.  
  1079.  
  1080.  
  1081.  
  1082.           +-----------------------------+
  1083.           | EXPLODE(X)                  |
  1084.           +-----------------------------+
  1085.  
  1086.             Returns a list of the single characters in UNREAD(X).
  1087.  
  1088.             General Categories: Datatype conversion
  1089.                List composition
  1090.  
  1091.             Example: EXPLODE('DOG' ~ 'ARF' ~ NIL) returns
  1092.                ( '(' ~ 'D' ~ 'O' ~ 'G' ~ ' ' ~
  1093.                'A' ~ 'R' ~ 'F' ~ ')' ~ NIL ).
  1094.  
  1095.             References: Charniak et al. (1980), 304.
  1096.                MTS LISP Manual, 22.
  1097.                Schank & Riesbeck (1981), 56.
  1098.                Shapiro (1979), 151.
  1099.  
  1100.  
  1101.  
  1102.  
  1103.  
  1104.  
  1105.  
  1106.  
  1107.  
  1108.  
  1109.  
  1110.  
  1111.  
  1112.  
  1113.  
  1114.  
  1115.  
  1116.  
  1117.  
  1118.  
  1119.  
  1120.        AI Programming in SNOBOL4      - 103 -                    August, 1982
  1121.  
  1122.  
  1123.  
  1124.  
  1125.  
  1126.  
  1127.  
  1128.  
  1129.           +-----------------------------+
  1130.           | *FAIL.IF.NIL(L)             |
  1131.           +-----------------------------+
  1132.  
  1133.             Returns L if L is non-NIL.  If L is NIL, then the function call
  1134.                fails.  The unary operator / is OPSYNed to this function:
  1135.                /L is equivalent to FAIL.IF.NIL(L).
  1136.  
  1137.             The argument L must be a list (datatype CONS) or a fatal error
  1138.                will result.
  1139.  
  1140.             General Categories: Predicate
  1141.  
  1142.             Example: The statement
  1143.                         Y = /GETPROP( .DOG, 'LEGS')
  1144.                sets Y to whatever value is stored on the property list of
  1145.                DOG under the indicator 'LEGS'.  If no such value exists,
  1146.                GETPROP returns NIL, /GETPROP fails, and the value of Y
  1147.                remains unchanged.
  1148.  
  1149.             Comments: This function helps interface the T/NIL mode of LISP-
  1150.                type predicates with the succeed/fail mode of SNOBOL4
  1151.                predicates.
  1152.  
  1153.  
  1154.  
  1155.  
  1156.  
  1157.           +-----------------------------+
  1158.           | FAIL.IF.NIL.ELSE.SUCCEED(L) |
  1159.           +-----------------------------+
  1160.  
  1161.             Returns the null string.  It succeeds if /L succeeds, and fails
  1162.                if /L fails.  The unary operator % is OPSYNed to this
  1163.                function: %L is equivalent to
  1164.                          FAIL.IF.NIL.ELSE.SUCCEED(L).
  1165.                The argument L must be a list (datatype CONS) or a fatal
  1166.                error will result.
  1167.  
  1168.             General Categories: Predicate
  1169.  
  1170.             Example: The statement
  1171.                        Y = %FIND(P,LST) CONS(P,Y)
  1172.                will add P to the list Y if P is a substructure of LST; if
  1173.                not, FIND returns NIL, %FIND fails, and Y remains unchanged.
  1174.  
  1175.             Note that /FIND would not work here: If FIND found P, it would
  1176.                return a non-NIL value.  /FIND would pass along the same
  1177.                value.  The right-hand side of the assignment statement
  1178.                would be interpreted as a concatenation expression, and a
  1179.                fatal error would result, because one or both of the
  1180.                arguments would be lists, not strings.  Because SPITBOL
  1181.                gives special attention to the null string, %FIND does not
  1182.                cause the same error.
  1183.  
  1184.  
  1185.  
  1186.        AI Programming in SNOBOL4      - 104 -                    August, 1982
  1187.  
  1188.  
  1189.  
  1190.  
  1191.  
  1192.  
  1193.  
  1194.  
  1195.           +-----------------------------+
  1196.           | FIND(X,L)                   |
  1197.           +-----------------------------+
  1198.  
  1199.             Returns the first substructure of L which is EQUAL to X.  The
  1200.                search is left-branching, depth-first.  If X is not EQUAL to
  1201.                any substructure of L, then FIND returns NIL.
  1202.  
  1203.             General Categories: List decomposition
  1204.                List search
  1205.  
  1206.             Example: If X = ('A' ~ NIL) and
  1207.                L = (1 ~ (2 ~ ('A' ~ NIL)) ~ 3 ~ NIL), then FIND(X,L)
  1208.                returns ('A' ~ NIL).
  1209.  
  1210.             Comments: This version of FIND is not exactly the same as the
  1211.                MTS LISP version.
  1212.  
  1213.             References: MTS LISP Manual, 19.
  1214.  
  1215.  
  1216.  
  1217.  
  1218.  
  1219.           +-----------------------------+
  1220.           | FIX(N)                      |
  1221.           +-----------------------------+
  1222.  
  1223.             Returns N converted to datatype 'INTEGER' if possible;
  1224.                otherwise, it fails.
  1225.  
  1226.             General Categories: Arithmetic function
  1227.                Datatype conversion
  1228.  
  1229.             Example: FIX(9.995) returns 9
  1230.  
  1231.             Comments: Real to integer conversion is possible only if the
  1232.                real number is between -2147483648 and 2147483647. Reals in
  1233.                this range are converted to integers by truncating their
  1234.                fractional parts.
  1235.  
  1236.             References: MTS LISP Manual, 26.
  1237.                Shapiro (1979), 151.
  1238.  
  1239.  
  1240.  
  1241.  
  1242.  
  1243.  
  1244.  
  1245.  
  1246.  
  1247.  
  1248.  
  1249.  
  1250.  
  1251.  
  1252.        AI Programming in SNOBOL4      - 105 -                    August, 1982
  1253.  
  1254.  
  1255.  
  1256.  
  1257.  
  1258.  
  1259.  
  1260.  
  1261.           +-----------------------------+
  1262.           | FLOAT(N)                    |
  1263.           +-----------------------------+
  1264.  
  1265.             Returns N converted to datatype REAL.
  1266.  
  1267.             General Categories: Arithmetic function
  1268.                Datatype conversion
  1269.  
  1270.             Example: FLOAT(-9) returns -9.0, a 4-byte floating-point
  1271.                number.
  1272.  
  1273.             References: MTS LISP Manual, 26.
  1274.                Shapiro (1979), 151.
  1275.  
  1276.  
  1277.  
  1278.  
  1279.  
  1280.           +-----------------------------+
  1281.           | FLOOR(N)                    |
  1282.           +-----------------------------+
  1283.  
  1284.             Returns the largest integer which is no larger than N.  N may
  1285.                be any integer or floating point number.
  1286.  
  1287.             General Categories: Arithmetic function
  1288.  
  1289.             Example: FLOOR(-9.1) returns -10.
  1290.  
  1291.             References: Gimpel (1976), 327.
  1292.  
  1293.  
  1294.  
  1295.  
  1296.  
  1297.  
  1298.  
  1299.  
  1300.  
  1301.  
  1302.  
  1303.  
  1304.  
  1305.  
  1306.  
  1307.  
  1308.  
  1309.  
  1310.  
  1311.  
  1312.  
  1313.  
  1314.  
  1315.  
  1316.  
  1317.  
  1318.        AI Programming in SNOBOL4      - 106 -                    August, 1982
  1319.  
  1320.  
  1321.  
  1322.  
  1323.  
  1324.  
  1325.  
  1326.  
  1327.           +-----------------------------+
  1328.           | GENSYM()                    |
  1329.           +-----------------------------+
  1330.  
  1331.             Returns a string created by concatenating 'GSYM' with the
  1332.                current value of &STCOUNT, the number of statements executed
  1333.                so far.  This is usually intended for use as the name of an
  1334.                identifier.  NEWSYM is a synonym for GENSYM.
  1335.  
  1336.             General Categories: Definitional function
  1337.  
  1338.             Example: $GENSYM() = LIST('O',NIL) has the effect of GSYM28347
  1339.                = LIST('O',NIL), assuming that 28347 happens to be the
  1340.                number of statements executed at the time GENSYM() is
  1341.                called.
  1342.  
  1343.             References: Charniak et al. (1980), 77-78, 306.
  1344.                MTS LISP Manual, 21-22.
  1345.                Shapiro (1979), 152.
  1346.  
  1347.  
  1348.  
  1349.  
  1350.  
  1351.           +-----------------------------+
  1352.           | GET(NAME,X)                 |
  1353.           +-----------------------------+
  1354.  
  1355.             Returns the value (always a list) associated with the indicator
  1356.                X on the property list of the identifier named NAME.  If no
  1357.                such value exists, GET returns NIL.
  1358.  
  1359.             General Categories: List decomposition
  1360.                List search
  1361.                Property-list function
  1362.  
  1363.             Example: If ('LEGS' ~ 4 ~ NIL) is an element of the property
  1364.                list of DOG, then GET( .DOG, 'LEGS') returns (4 ~ NIL).
  1365.  
  1366.             References: Charniak et al. (1980), 18, 304.
  1367.                MTS LISP Manual, 24.
  1368.                Schank & Riesbeck (1981), 57.
  1369.                Shapiro (1979), 152.
  1370.  
  1371.  
  1372.  
  1373.  
  1374.  
  1375.  
  1376.  
  1377.  
  1378.  
  1379.  
  1380.  
  1381.  
  1382.  
  1383.  
  1384.        AI Programming in SNOBOL4      - 107 -                    August, 1982
  1385.  
  1386.  
  1387.  
  1388.  
  1389.  
  1390.  
  1391.  
  1392.  
  1393.           +-----------------------------+
  1394.           | GETL(NAME,L)                |
  1395.           +-----------------------------+
  1396.  
  1397.             Returns the tail of the property list of the identifier named
  1398.                NAME, beginning with the first element whose CAR is a MEMBER
  1399.                of L.
  1400.  
  1401.             General Categories: List decomposition
  1402.                List search
  1403.                Property-list function
  1404.  
  1405.             Example: Suppose DOG has the following property-list:
  1406.                (('NOSE' ~ 'WET' ~ NIL) ~
  1407.                ('LEGS' ~ 4 ~ NIL) ~
  1408.                ('TEETH' ~ 'SHARP' ~ NIL) ~ NIL).  Then
  1409.                GETL( .DOG, 'WINGS' ~ 'TEETH' ~ 'NOSE' ~ NIL) will return
  1410.                the entire property list.
  1411.  
  1412.             References: Charniak et al. (1980), 305.
  1413.  
  1414.  
  1415.  
  1416.  
  1417.  
  1418.           +-----------------------------+
  1419.           | GETPROP(NAME,S)             |
  1420.           +-----------------------------+
  1421.  
  1422.             Returns the first value stored under the indicator S on the
  1423.                property list of the identifier named NAME.
  1424.  
  1425.             General Categories.: Alters existing CONS cell(s)
  1426.                List decomposition
  1427.                List search
  1428.                Property-list function
  1429.  
  1430.             Side Effects: The value returned is deleted from its place on
  1431.                the property list.
  1432.  
  1433.             Example: If ('LEGS' ~ 5 ~ 4 ~ 3 ~ 2 ~ 1 ~ NIL) is an element of
  1434.                the property list of DOG, then five successive evaluations
  1435.                of GETPROP(.DOG,'LEGS') will return 5, 4, 3, 2, and 1.  The
  1436.                sixth such call will return NIL.
  1437.  
  1438.             Comments: GETPROP is intended to be used with PUTPROP in the
  1439.                manipulation of push-down stacks of property list values.
  1440.  
  1441.             References:  MTS LISP Manual, 24-25.
  1442.  
  1443.  
  1444.  
  1445.  
  1446.  
  1447.  
  1448.  
  1449.  
  1450.        AI Programming in SNOBOL4      - 108 -                    August, 1982
  1451.  
  1452.  
  1453.  
  1454.  
  1455.  
  1456.  
  1457.  
  1458.  
  1459.           +-----------------------------+
  1460.           | GREATER(L)                  |
  1461.           +-----------------------------+
  1462.  
  1463.             Returns the null string.  It succeeds if the numbers in the
  1464.                list L are in strictly decreasing order; otherwise, it
  1465.                fails.
  1466.  
  1467.             General Categories: Arithmetic function
  1468.                Predicate
  1469.  
  1470.             Example: GREATER(8 ~ 5 ~ 3 ~ -7 ~ 0 ~ NIL) fails.
  1471.  
  1472.             References: MTS LISP Manual, 25.
  1473.                Shapiro (1979), 152.
  1474.  
  1475.  
  1476.  
  1477.  
  1478.  
  1479.           +-----------------------------+
  1480.           | GREATERP(L)                 |
  1481.           +-----------------------------+
  1482.  
  1483.             Returns T if GREATER(L) succeeds; NIL otherwise.
  1484.  
  1485.             General Categories: Arithmetic function
  1486.                Predicate
  1487.  
  1488.             Example: GREATERP(8.53211 ~ 5 ~ 3 ~ 2 ~ 1 ~ -1 ~ NIL) returns
  1489.                T.
  1490.  
  1491.             References: See GREATER.
  1492.  
  1493.  
  1494.  
  1495.  
  1496.  
  1497.  
  1498.  
  1499.  
  1500.  
  1501.  
  1502.  
  1503.  
  1504.  
  1505.  
  1506.  
  1507.  
  1508.  
  1509.  
  1510.  
  1511.  
  1512.  
  1513.  
  1514.  
  1515.  
  1516.        AI Programming in SNOBOL4      - 109 -                    August, 1982
  1517.  
  1518.  
  1519.  
  1520.  
  1521.  
  1522.  
  1523.  
  1524.  
  1525.           +-----------------------------+
  1526.           | *IN(NAME)                   |
  1527.           +-----------------------------+
  1528.  
  1529.             Returns the next logical record (as a string) from the file
  1530.                which is associated with the identifier "INPUT.".  (Note
  1531.                that the name of this identifier ends with a period!)
  1532.  
  1533.             General Categories: Input
  1534.  
  1535.             Side Effects: If NAME is not null, then the string returned by
  1536.                IN also becomes the value of the identifier named NAME.
  1537.  
  1538.             Example: TEMP = IN( .SAVE) reads the next input record, assigns
  1539.                it as the value of TEMP, and also assigns it as the value of
  1540.                SAVE.
  1541.  
  1542.             Comments: No attempt is made in SNOLISPIST to simulate LISP
  1543.                input functions.  All input is string input, and datatype
  1544.                conversion (e.g., to list) must be handled by the
  1545.                programmer.  (See READ.)
  1546.  
  1547.  
  1548.  
  1549.  
  1550.  
  1551.           +-----------------------------+
  1552.           | INSERT(X,L)                 |
  1553.           +-----------------------------+
  1554.  
  1555.             Returns L if X is EQUAL to an element of L; otherwise, it
  1556.                returns CONS(X,L).
  1557.  
  1558.             General Categories: List composition
  1559.                List search
  1560.  
  1561.             Example: INSERT(1, ('UN' ~ '1' ~ (8 ~ 'GNU') ~ NIL)) returns
  1562.                its second argument unchanged.
  1563.  
  1564.             References: Shapiro (1979), 152.
  1565.  
  1566.  
  1567.  
  1568.  
  1569.  
  1570.  
  1571.  
  1572.  
  1573.  
  1574.  
  1575.  
  1576.  
  1577.  
  1578.  
  1579.  
  1580.  
  1581.  
  1582.        AI Programming in SNOBOL4      - 110 -                    August, 1982
  1583.  
  1584.  
  1585.  
  1586.  
  1587.  
  1588.  
  1589.  
  1590.  
  1591.           +-----------------------------+
  1592.           | INTERSECT(L1,L2)            |
  1593.           +-----------------------------+
  1594.  
  1595.             Returns the list of elements common to L1 and L2, without
  1596.                duplicates.
  1597.  
  1598.             General Categories: List composition
  1599.                List decomposition
  1600.                List search
  1601.  
  1602.             Example: INTERSECT(('A' ~ 'B' ~ NIL), ('B' ~ 'CAT' ~ NIL))
  1603.                returns ('B' ~ NIL).
  1604.  
  1605.             References: MTS LISP Manual, 21.
  1606.  
  1607.  
  1608.  
  1609.  
  1610.  
  1611.           +-----------------------------+
  1612.           | LAST(L)                     |
  1613.           +-----------------------------+
  1614.  
  1615.             Returns the last non-NIL cell of L (always a list); or NIL if
  1616.                no such cell exists.
  1617.  
  1618.             General Categories: List decomposition
  1619.                List search
  1620.  
  1621.             Example: LAST('A' ~ ('COMPLEX' ~ 'ELEMENT' ~ NIL) ~ NIL)
  1622.                returns ('COMPLEX' ~ 'ELEMENT' ~ NIL) ~ NIL.
  1623.  
  1624.             Comments: LAST returns the last non-NIL CONS-cell of L, not a
  1625.                copy of that cell.  Thus, changes to LAST(L), by means of
  1626.                RPLACA, RPLACD, etc., produce changes in the value of L.
  1627.                Also note that LAST(L) does not return the last element of L
  1628.                (cf. RAC): LAST('A' ~ 'B' ~ NIL) returns ('B' ~ NIL), not
  1629.                'B'.
  1630.  
  1631.             References: Charniak et al. (1980), 305.
  1632.                Schank & Riesbeck (1981), 57.
  1633.  
  1634.  
  1635.  
  1636.  
  1637.  
  1638.  
  1639.  
  1640.  
  1641.  
  1642.  
  1643.  
  1644.  
  1645.  
  1646.  
  1647.  
  1648.        AI Programming in SNOBOL4      - 111 -                    August, 1982
  1649.  
  1650.  
  1651.  
  1652.  
  1653.  
  1654.  
  1655.  
  1656.  
  1657.           +-----------------------------+
  1658.           | LCOPY(L)                    |
  1659.           +-----------------------------+
  1660.  
  1661.             Returns a copy of the list L, i.e., a structure which is EQUAL
  1662.                to L but not EQU to L.
  1663.  
  1664.             General Categories: List composition
  1665.  
  1666.             Example: For any list L,
  1667.                EQU( !L, !LCOPY(L)) succeeds;
  1668.                EQU( L, LCOPY(L)) fails; and
  1669.                EQUAL( L, LCOPY(L)) succeeds.
  1670.  
  1671.             Comments: COPY is a built-in function in SPITBOL; hence the
  1672.                name change.
  1673.  
  1674.             References: MTS LISP Manual, 20.
  1675.  
  1676.  
  1677.  
  1678.  
  1679.  
  1680.           +-----------------------------+
  1681.           | LENGTH(X)                   |
  1682.           +-----------------------------+
  1683.  
  1684.             Returns the number of top-level elements of X, if X is a list.
  1685.                If X is an atom, LENGTH returns the number of characters in
  1686.                its string representation; if X has no string
  1687.                representation, LENGTH fails.
  1688.  
  1689.             General Categories: List search
  1690.  
  1691.             Example: LENGTH('UNION' ~ 'SUIT' ~ 'MAKER' ~ NIL) returns 3.
  1692.  
  1693.             References: Charniak et al. (1980), 305.
  1694.                MTS LISP Manual, 25.
  1695.                Schank & Riesbeck (1981), 57.
  1696.                Shapiro (1979), 152.
  1697.  
  1698.  
  1699.  
  1700.  
  1701.  
  1702.  
  1703.  
  1704.  
  1705.  
  1706.  
  1707.  
  1708.  
  1709.  
  1710.  
  1711.  
  1712.  
  1713.  
  1714.        AI Programming in SNOBOL4      - 112 -                    August, 1982
  1715.  
  1716.  
  1717.  
  1718.  
  1719.  
  1720.  
  1721.  
  1722.  
  1723.           +-----------------------------+
  1724.           | LESS(L)                     |
  1725.           +-----------------------------+
  1726.  
  1727.             Returns the null string.  It succeeds if the numbers in the
  1728.                list L are in strictly increasing order; otherwise, it
  1729.                fails.
  1730.  
  1731.             General Categories: Arithmetic function
  1732.                Predicate
  1733.  
  1734.             Example: LESS(1 ~ 2 ~ 3 ~ 5 ~ 8 ~ 13 ~ NIL) succeeds.
  1735.  
  1736.             References: MTS LISP Manual, 25.
  1737.                Shapiro (1979), 153.
  1738.  
  1739.  
  1740.  
  1741.  
  1742.  
  1743.           +-----------------------------+
  1744.           | LESSP(L)                    |
  1745.           +-----------------------------+
  1746.  
  1747.             Returns T if LESS(L) succeeds; NIL otherwise.
  1748.  
  1749.             General Categories: Arithmetic function
  1750.                Predicate
  1751.  
  1752.             Example: LESSP(1 ~ 1 ~ 9.112 ~ 9112 ~ NIL) returns NIL.
  1753.  
  1754.             References: See LESS.
  1755.  
  1756.  
  1757.  
  1758.  
  1759.  
  1760.  
  1761.  
  1762.  
  1763.  
  1764.  
  1765.  
  1766.  
  1767.  
  1768.  
  1769.  
  1770.  
  1771.  
  1772.  
  1773.  
  1774.  
  1775.  
  1776.  
  1777.  
  1778.  
  1779.  
  1780.        AI Programming in SNOBOL4      - 113 -                    August, 1982
  1781.  
  1782.  
  1783.  
  1784.  
  1785.  
  1786.  
  1787.  
  1788.  
  1789.           +-----------------------------+
  1790.           | *LIST(X,Y)                  |
  1791.           +-----------------------------+
  1792.  
  1793.             Returns CONS(X,Y), i.e., a list C such that CAR(C) = X and
  1794.                CDR(C) = Y.  The binary operator ~ is OPSYNed to the LIST
  1795.                function: 'A' ~ 'B' is equivalent to LIST('A','B').
  1796.  
  1797.             General Categories: List composition
  1798.  
  1799.             Example:
  1800.                SNOLISPIST:
  1801.                     A ~ (B ~ C) ~ (D ~ (E ~ F)) ~ NIL
  1802.                LISP:
  1803.                     (A (B C) (D (E F)))
  1804.  
  1805.             Comments: The ~ operator is the highest precedence binary
  1806.                operator in SPITBOL, and it is right-associative. Thus, (A ~
  1807.                B ~ C ~ NIL) is equivalent to CONS(A,CONS(B,CONS(C,NIL))),
  1808.                i.e., to LISP's (A B C).
  1809.  
  1810.             Note that LIST is strictly binary in SNOLISPIST, but the ~
  1811.                operator allows the chaining of an indefinite number of
  1812.                arguments.
  1813.  
  1814.             References: Charniak et al. (1980), 305.
  1815.                MTS LISP Manual, 20.
  1816.                Schank & Riesbeck (1981), 57.
  1817.                Shapiro (1979), 153.
  1818.  
  1819.  
  1820.  
  1821.  
  1822.  
  1823.           +-----------------------------+
  1824.           | LOG(N1,N2)                  |
  1825.           +-----------------------------+
  1826.  
  1827.             Returns log(N1) (base N2); N1 > 0, N2 > 0, N2 <> 1.  If N2 is
  1828.                omitted, e is assumed (i.e., the natural logarithm of N1 is
  1829.                returned).
  1830.  
  1831.             General Categories: Arithmetic function
  1832.  
  1833.             Example: LOG(0.167, 2) returns -2.5820800292618.
  1834.  
  1835.             References: Gimpel (1976), 335-336.
  1836.  
  1837.  
  1838.  
  1839.  
  1840.  
  1841.  
  1842.  
  1843.  
  1844.  
  1845.  
  1846.        AI Programming in SNOBOL4      - 114 -                    August, 1982
  1847.  
  1848.  
  1849.  
  1850.  
  1851.  
  1852.  
  1853.  
  1854.  
  1855.           +-----------------------------+
  1856.           | LREVERSE(L)                 |
  1857.           +-----------------------------+
  1858.  
  1859.             Returns the top-level elements of L in reverse order.
  1860.  
  1861.             General Categories: List composition
  1862.                List decomposition
  1863.  
  1864.             Example: LREVERSE(11 ~ 9 ~ 8 ~ 4 ~ NIL) returns
  1865.                (4 ~ 8 ~ 9 ~ 11 ~ NIL).
  1866.  
  1867.             Comments: REVERSE is a built-in function in SPITBOL.  (It
  1868.                reverses the characters in a string.)
  1869.  
  1870.             References: Charniak et al. (1980), 15, 308.
  1871.                MTS LISP Manual, 20.
  1872.                Schank & Riesbeck (1981), 59.
  1873.                Shapiro (1979), 155.
  1874.  
  1875.  
  1876.  
  1877.  
  1878.  
  1879.           +-----------------------------+
  1880.           | LTRACE(N,L)                 |
  1881.           +-----------------------------+
  1882.  
  1883.             Returns the null string.
  1884.  
  1885.             General Categories: Output
  1886.  
  1887.             Side Effects: This function permits tracing of functions which
  1888.                have list arguments and/or which return list values.  A call
  1889.                to LTRACE(N,L) turns on N-level tracing for every function
  1890.                whose name is on the list L.  If N is omitted, then N = 3 is
  1891.                assumed.
  1892.                
  1893.                0-level tracing indicates that tracing is to be turned off
  1894.                for all functions whose names are on the list L.
  1895.                
  1896.                1-level tracing indicates that the values of the arguments
  1897.                passed to the traced function and the value returned from
  1898.                the traced function are to be reported every time the
  1899.                function is called or returned from.  The trace messages go
  1900.                to the user's terminal.
  1901.                
  1902.                2-level tracing includes the information requested by 1-
  1903.                level tracing; in addition, the values of all local
  1904.                variables and arguments are reported every time the traced
  1905.                function returns.
  1906.                
  1907.  
  1908.  
  1909.  
  1910.  
  1911.  
  1912.        AI Programming in SNOBOL4      - 115 -                    August, 1982
  1913.  
  1914.  
  1915.  
  1916.  
  1917.  
  1918.  
  1919.  
  1920.  
  1921.                3-level tracing includes the information requested by 2-
  1922.                level tracing; in addition, the program will pause every
  1923.                time the traced function is called or returned from.  At
  1924.                this time, any SPITBOL or SNOLISPIST expression may be
  1925.                entered.  This expression will be immediately evaluated.
  1926.                Such an expression could be used to turn off or alter the
  1927.                level of tracing of one or more functions; to initiate
  1928.                tracing of one or more additional functions; to print the
  1929.                value of a variable; to alter the value of a variable; or to
  1930.                do anything else that can be accomplished with one
  1931.                expression.  A simple line-feed (null line) will cause the
  1932.                program to continue.
  1933.                
  1934.                Certain functions cannot be traced.  These include all the
  1935.                SPITBOL built-in functions, as well as the following
  1936.                SNOLISPIST functions:
  1937.                
  1938.                LTRACE, POP, any LAMBDA, PRT.VIA.OUTPUT, ATOM, CAR, CDR,
  1939.                TDUMP, PRINT.IN.FIELD, UNREAD, NULL, UNCONS, IN, CONCAT,
  1940.                MAPCAR, LIST, and PRINT.
  1941.  
  1942.             Example: LTRACE(1, .FUNCT1 ~ .APPEND ~ .XYZ ~ NIL) turns on 1-
  1943.                level tracing for the functions FUNCT1, APPEND, and XYZ.
  1944.                Here, FUNCT1 and XYZ are presumably user-defined, while
  1945.                APPEND is a SNOLISPIST function.
  1946.  
  1947.             Comments: Requests to trace untraceable functions are simply
  1948.                ignored.
  1949.                
  1950.                LTRACE is under the control of the SNOBOL4 keyword $TRACE.
  1951.                This keyword must be set to a positive integer or tracing
  1952.                will be inhibited.
  1953.  
  1954.             References: MTS LISP Manual, 63-64.
  1955.  
  1956.  
  1957.  
  1958.  
  1959.  
  1960.  
  1961.  
  1962.  
  1963.  
  1964.  
  1965.  
  1966.  
  1967.  
  1968.  
  1969.  
  1970.  
  1971.  
  1972.  
  1973.  
  1974.  
  1975.  
  1976.  
  1977.  
  1978.        AI Programming in SNOBOL4      - 116 -                    August, 1982
  1979.  
  1980.  
  1981.  
  1982.  
  1983.  
  1984.  
  1985.  
  1986.  
  1987.           +-----------------------------+
  1988.           | MAP(NAME,L)                 |
  1989.           +-----------------------------+
  1990.  
  1991.             Returns NIL.
  1992.  
  1993.             General Categories: Mapping function
  1994.  
  1995.             Side Effects: Applies the function named NAME to L, then to
  1996.                CDR(L), then to CDDR(L), and so on.
  1997.  
  1998.             Example: %MAP( .PRINT, 'AARDVARK' ~ 'SYZYGY' ~ 'ZAX' ~ NIL)
  1999.                causes (AARDVARK SYZYGY ZAX), (SYZYGY ZAX), and (ZAX) to be
  2000.                printed on three successive lines, then fails.
  2001.  
  2002.             References: Charniak et al. (1980), 61.
  2003.                MTS LISP Manual, 28.
  2004.  
  2005.  
  2006.  
  2007.  
  2008.  
  2009.           +-----------------------------+
  2010.           | MAPC(NAME,L)                |
  2011.           +-----------------------------+
  2012.  
  2013.             Returns NIL.
  2014.  
  2015.             General Categories: Mapping function
  2016.  
  2017.             Side Effects: Applies the function named NAME to CAR(L), then
  2018.                to CADR(L), then to CADDR(L), and so on.
  2019.  
  2020.             Example: %MAPC( .PRINT, 'AARDVARK' ~ 'SYZYGY' ~ 'ZAX' ~ NIL)
  2021.                causes AARDVARK, SYZYGY, and ZAX to be printed on three
  2022.                successive lines, then fails.
  2023.  
  2024.             References: Charniak et al. (1980), 61, 306.
  2025.                MTS LISP Manual, 28.
  2026.                Schank & Riesbeck (1981), 65.
  2027.                Shapiro (1979), 153.
  2028.  
  2029.  
  2030.  
  2031.  
  2032.  
  2033.  
  2034.  
  2035.  
  2036.  
  2037.  
  2038.  
  2039.  
  2040.  
  2041.  
  2042.  
  2043.  
  2044.        AI Programming in SNOBOL4      - 117 -                    August, 1982
  2045.  
  2046.  
  2047.  
  2048.  
  2049.  
  2050.  
  2051.  
  2052.  
  2053.           +-----------------------------+
  2054.           | MAPCAN(NAME,L)              |
  2055.           +-----------------------------+
  2056.  
  2057.             Returns NCONC(MAPCAR(NAME,L)).
  2058.  
  2059.             General Categories: Alters existing CONS cell(s)
  2060.                List composition
  2061.                Mapping function
  2062.  
  2063.             Side Effects: See MAPCON.
  2064.  
  2065.             Example: MAPCAN( .LAST, ((1 ~ 2 ~ 3 ~ 4 ~ NIL) ~ (7 ~ 8 ~ NIL)
  2066.                ~ ('A' ~ 'B' ~ NIL) ~ NIL)) returns (4 ~ 8 ~ 'B' ~ NIL).
  2067.  
  2068.             References: Charniak et al. (1980), 61-62, 306.
  2069.                MTS LISP Manual, 28.
  2070.                Schank & Riesbeck (1981), 65.
  2071.  
  2072.  
  2073.  
  2074.  
  2075.  
  2076.           +-----------------------------+
  2077.           | MAPCAR(NAME,L)              |
  2078.           +-----------------------------+
  2079.  
  2080.             Returns a list of the values returned when the function named
  2081.                NAME is applied successively to CAR(L), CADR(L), CADDR(L),
  2082.                and so on.
  2083.  
  2084.             General Categories: List composition
  2085.                Mapping function
  2086.  
  2087.             Example: MAPCAR( .ADD1, 19 ~ 43 ~ '88' ~ '69' ~ NIL) returns
  2088.                (20 ~ 44 ~ 89 ~ 70 ~ NIL).
  2089.  
  2090.             References: Charniak et al. (1980), 15-17, 61-62, 306.
  2091.                MTS LISP Manual, 28.
  2092.                Schank & Riesbeck (1981), 65.
  2093.                Shapiro (1979), 153.
  2094.  
  2095.  
  2096.  
  2097.  
  2098.  
  2099.  
  2100.  
  2101.  
  2102.  
  2103.  
  2104.  
  2105.  
  2106.  
  2107.  
  2108.  
  2109.  
  2110.        AI Programming in SNOBOL4      - 118 -                    August, 1982
  2111.  
  2112.  
  2113.  
  2114.  
  2115.  
  2116.  
  2117.  
  2118.  
  2119.           +-----------------------------+
  2120.           | *MAPCARV(NAME,L)            |
  2121.           +-----------------------------+
  2122.  
  2123.             Returns the reverse of MAPCAR(NAME,L).
  2124.  
  2125.             General Categories: List composition
  2126.                Mapping function
  2127.  
  2128.             Example: MAPCARV( .NUMBERP, #'(zed 7 74 EQ *)' ) returns (NIL ~
  2129.                NIL ~ T ~ T ~ NIL ~ NIL).  (The final NIL is the list
  2130.                terminator.)
  2131.  
  2132.             Comments: This function is sometimes useful when an argument
  2133.                list is built up by CONSing elements together.  Generally,
  2134.                such a list is built backwards.  MAPCARV can then be used to
  2135.                map the list and to restore the original order.  This saves
  2136.                two needless calls to LREVERSE.
  2137.  
  2138.             References: See MAPCAR.
  2139.  
  2140.  
  2141.  
  2142.  
  2143.  
  2144.           +-----------------------------+
  2145.           | MAPCON(NAME,L)              |
  2146.           +-----------------------------+
  2147.  
  2148.             Returns NCONC(MAPLIST(NAME,L)).
  2149.  
  2150.             General Categories: Alters existing CONS cell(s)
  2151.                List composition
  2152.                Mapping function
  2153.  
  2154.             Side Effects: NCONC uses RPLACD, so the usual caveats apply:
  2155.                Functions that alter existing cons-cells can have unexpected
  2156.                consequences.  Note also that NAME must return a list for
  2157.                each argument in L.
  2158.  
  2159.             Example: MAPCON( .LREVERSE, 1 ~ 2 ~ 3 ~ 4 ~ 5 ~ NIL) returns (5
  2160.                ~ 4 ~ 3 ~ 2 ~ 1 ~ 5 ~ 4 ~ 3 ~ 2 ~ 5 ~ 4 ~ 3 ~ 5 ~ 4 ~ 5 ~
  2161.                NIL).
  2162.  
  2163.             References: Charniak et al. (1980), 61-62.
  2164.                MTS LISP Manual, 28.
  2165.  
  2166.  
  2167.  
  2168.  
  2169.  
  2170.  
  2171.  
  2172.  
  2173.  
  2174.  
  2175.  
  2176.        AI Programming in SNOBOL4      - 119 -                    August, 1982
  2177.  
  2178.  
  2179.  
  2180.  
  2181.  
  2182.  
  2183.  
  2184.  
  2185.           +-----------------------------+
  2186.           | MAPLIST(NAME,L)             |
  2187.           +-----------------------------+
  2188.  
  2189.             Returns a list of the values returned when the function named
  2190.                NAME is applied successively to L, CDR(L), CDDR(L), and so
  2191.                on.
  2192.  
  2193.             General Categories: List composition
  2194.                Mapping function
  2195.  
  2196.             Example: MAPLIST( .PLUS, 1 ~ 2 ~ 3 ~ 4 ~ NIL) returns
  2197.                (10 ~ 9 ~  7 ~ 4 ~ NIL).
  2198.  
  2199.             References: Charniak et al. (1980), 61.
  2200.                MTS LISP Manual, 28.
  2201.  
  2202.  
  2203.  
  2204.  
  2205.  
  2206.           +-----------------------------+
  2207.           | MAX(N1,N2)                  |
  2208.           +-----------------------------+
  2209.  
  2210.             Returns the larger of N1 and N2.
  2211.  
  2212.             General Categories: Arithmetic function
  2213.  
  2214.             Example: MAX(6.78, 12.2243) returns 12.2243.
  2215.  
  2216.             References: MTS LISP Manual, 26.
  2217.                Shapiro (1979), 153.
  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.        AI Programming in SNOBOL4      - 120 -                    August, 1982
  2243.  
  2244.  
  2245.  
  2246.  
  2247.  
  2248.  
  2249.  
  2250.  
  2251.           +-----------------------------+
  2252.           | MEMBER(X,L)                 |
  2253.           +-----------------------------+
  2254.  
  2255.             Returns the tail of L beginning with the first top-level
  2256.                element which is EQUAL to X.  If no such element exists,
  2257.                MEMBER returns NIL.
  2258.  
  2259.             General Categories: List composition
  2260.                List decomposition
  2261.                List search
  2262.  
  2263.             Example:
  2264.                MEMBER(1, ((1 ~ NIL) ~ (2 ~ NIL) ~ '1' ~ 'A' ~ NIL)) returns
  2265.                ('1' ~ 'A' ~ NIL).
  2266.  
  2267.             Comments: Cf. ASSOC and MEMQ.
  2268.  
  2269.             References: Charniak et al. (1980), 306.
  2270.                MTS LISP Manual, 19.
  2271.                Schank & Riesbeck (1981), 46, 57.
  2272.                Shapiro (1979), 153.
  2273.  
  2274.  
  2275.  
  2276.  
  2277.  
  2278.           +-----------------------------+
  2279.           | MEMQ(X,L)                   |
  2280.           +-----------------------------+
  2281.  
  2282.             Returns the null string.  It succeeds if MEMBER(X,L) is non-
  2283.                NIL; otherwise, it fails.
  2284.  
  2285.             General Categories: Predicate
  2286.  
  2287.             Example: The statement
  2288.                      = MEMQ(1, INTEGERS) 'ONE' ~ A
  2289.                will CONS the string 'ONE' onto the front of the list A if
  2290.                the integer 1 (or anything EQUAL to it, e.g., '1.0') is a
  2291.                member of the list INTEGERS.
  2292.  
  2293.             Comments: See MEMBER.
  2294.  
  2295.             References: See MEMBER.
  2296.  
  2297.  
  2298.  
  2299.  
  2300.  
  2301.  
  2302.  
  2303.  
  2304.  
  2305.  
  2306.  
  2307.  
  2308.        AI Programming in SNOBOL4      - 121 -                    August, 1982
  2309.  
  2310.  
  2311.  
  2312.  
  2313.  
  2314.  
  2315.  
  2316.  
  2317.           +-----------------------------+
  2318.           | MIN(N1,N2)                  |
  2319.           +-----------------------------+
  2320.  
  2321.             Returns the smaller of N1 and N2.
  2322.  
  2323.             General Categories: Arithmetic function
  2324.  
  2325.             Example: MIN(0,MAX(-7,8)) returns 0.
  2326.  
  2327.             References: MTS LISP Manual, 26.
  2328.                Shapiro (1979), 153.
  2329.  
  2330.  
  2331.  
  2332.  
  2333.  
  2334.           +-----------------------------+
  2335.           | MINUS(N)                    |
  2336.           +-----------------------------+
  2337.  
  2338.             Returns -N.
  2339.  
  2340.             General Categories: Arithmetic function
  2341.  
  2342.             Example: MINUS(80.8) returns -80.8.
  2343.  
  2344.             References: Charniak et al. (1980), 306.
  2345.                MTS LISP Manual, 26.
  2346.                Schank & Riesbeck (1981), 57.
  2347.                Shapiro (1979), 153.
  2348.  
  2349.  
  2350.  
  2351.  
  2352.  
  2353.           +-----------------------------+
  2354.           | MULT(N1,N2)                 |
  2355.           +-----------------------------+
  2356.  
  2357.             Returns the product of N1 and N2.
  2358.  
  2359.             General Categories: Arithmetic function
  2360.  
  2361.             Example: MULT(7, -8.1) returns -56.7.
  2362.  
  2363.             Comments: MULT is binary.  For a comparable function which
  2364.                takes a list argument, see TIMES.
  2365.  
  2366.             References: Charniak et al. (1980), 310.
  2367.                MTS LISP Manual, 26.
  2368.                Schank & Riesbeck (1981), 60.
  2369.                Shapiro (1979), 156.
  2370.  
  2371.  
  2372.  
  2373.  
  2374.        AI Programming in SNOBOL4      - 122 -                    August, 1982
  2375.  
  2376.  
  2377.  
  2378.  
  2379.  
  2380.  
  2381.  
  2382.  
  2383.           +-----------------------------+
  2384.           | NCONC(L)                    |
  2385.           +-----------------------------+
  2386.  
  2387.             Returns a concatenated list of the elements of CAR(L), CADR(L),
  2388.                CADDR(L), etc.  L must be a list of lists.
  2389.  
  2390.             General Categories: Alters existing CONS cell(s)
  2391.                List composition
  2392.  
  2393.             Side Effects: NCONC(L) works analogously to APPEND(L), except
  2394.                that NCONC links the sublists together by using
  2395.                RPLACD(LAST(...)) operations.  This avoids the creation of
  2396.                new CONS cells, and is therefore more efficient than APPEND.
  2397.                It does, however, introduce the risk of creating circular
  2398.                (endless) lists and/or altering the values of some variables
  2399.                in unanticipated ways.
  2400.  
  2401.             Example:
  2402.                Let A = ('B' ~ 'C' ~ NIL),
  2403.                    B = ('NN' ~ 'OO' ~ NIL), and
  2404.                    C = ('FRONT' ~ A).
  2405.                Now execute the statement
  2406.                    LONG = NCONC(A ~ B ~ NIL)
  2407.                At this point,
  2408.                    LONG = ('B' ~ 'C' ~ 'NN' ~ 'OO' ~ NIL),
  2409.                but we also have (!)
  2410.                    A = ('B' ~ 'C' ~ 'NN' ~ 'OO' ~ NIL) and
  2411.                    C = ('FRONT' ~ 'B' ~ 'C' ~ 'NN' ~ 'OO' ~ NIL).
  2412.                Even worse results would have been produced by
  2413.                    LONG = NCONC(A ~ C ~ NIL).
  2414.  
  2415.             Comments: Note that MAPCAN and MAPCON use NCONC.
  2416.  
  2417.             References: Charniak et al. (1980), 23, 306.
  2418.                MTS LISP Manual, 23-24 (GRAFT).
  2419.  
  2420.  
  2421.  
  2422.  
  2423.  
  2424.  
  2425.  
  2426.  
  2427.  
  2428.  
  2429.  
  2430.  
  2431.  
  2432.  
  2433.  
  2434.  
  2435.  
  2436.  
  2437.  
  2438.  
  2439.  
  2440.        AI Programming in SNOBOL4      - 123 -                    August, 1982
  2441.  
  2442.  
  2443.  
  2444.  
  2445.  
  2446.  
  2447.  
  2448.  
  2449.           +-----------------------------+
  2450.           | NEG(N)                      |
  2451.           +-----------------------------+
  2452.  
  2453.              Returns the null string.  It succeeds if N is less than 0;
  2454.                otherwise it fails.
  2455.  
  2456.             General Categories: Predicate
  2457.  
  2458.             Example: The statement
  2459.                     Y = NEG(FFC) SQRT( -FFC)
  2460.                sets Y to the square root of -FFC if FFC is negative;
  2461.                otherwise, the value of Y remains unchanged.
  2462.  
  2463.             Comments: In LISP, this predicate usually goes under the name
  2464.                MINUSP.
  2465.  
  2466.             References: Schank & Riesbeck (1981), 57.
  2467.                Shapiro (1979), 153.
  2468.  
  2469.  
  2470.  
  2471.  
  2472.  
  2473.           +-----------------------------+
  2474.           | NEGP(N)                     |
  2475.           +-----------------------------+
  2476.  
  2477.             Returns T if NEG(N) succeeds; NIL otherwise.
  2478.  
  2479.             General Categories: Predicate
  2480.  
  2481.             Example: MAPCAR( .NEGP, 6 ~ -7 ~ 8 ~ -9 ~ 10 ~ -11 ~ -12 ~ 13 ~
  2482.                NIL) returns (NIL ~ T ~ NIL ~ T ~ NIL ~ T ~ T ~ NIL ~ NIL).
  2483.                (The final NIL is the list terminator.)
  2484.  
  2485.             References: See NEG.
  2486.  
  2487.  
  2488.  
  2489.  
  2490.  
  2491.           +-----------------------------+
  2492.           | NEWSYM()                    |
  2493.           +-----------------------------+
  2494.  
  2495.             Synonym for GENSYM().
  2496.  
  2497.  
  2498.  
  2499.  
  2500.  
  2501.  
  2502.  
  2503.  
  2504.  
  2505.  
  2506.        AI Programming in SNOBOL4      - 124 -                    August, 1982
  2507.  
  2508.  
  2509.  
  2510.  
  2511.  
  2512.  
  2513.  
  2514.  
  2515.           +-----------------------------+
  2516.           | NOT()                       |
  2517.           +-----------------------------+
  2518.  
  2519.              Synonym for NULL().
  2520.  
  2521.  
  2522.  
  2523.  
  2524.  
  2525.           +-----------------------------+
  2526.           | NOTP()                      |
  2527.           +-----------------------------+
  2528.  
  2529.             Synonym for NULLP().
  2530.  
  2531.  
  2532.  
  2533.  
  2534.  
  2535.           +-----------------------------+
  2536.           | NTH(L,N)                    |
  2537.           +-----------------------------+
  2538.  
  2539.             Returns the tail of L beginning with the Nth top-level element.
  2540.                If N is 0 or 1, L is returned.  If N exceeds LENGTH(L), then
  2541.                NIL is returned.  If N is negative, then the last N elements
  2542.                of L are returned (not in reverse order).  NTH(L, -1) is
  2543.                equivalent to LAST(L).
  2544.  
  2545.             General Categories: List decomposition
  2546.                List search
  2547.  
  2548.             Example: Let LST = ('F' ~ 'G' ~ NIL) ~ (1 ~ 2 ~ NIL) ~
  2549.                     HOO' ~ 'HAH' ~ NIL.
  2550.                Then NTH(LST, -2) returns ('HOO' ~ 'HAH' ~ NIL).
  2551.  
  2552.             Comments: See LAST.
  2553.  
  2554.             References: Charniak et al. (1980), 310 (SUFLIST).
  2555.                MTS LISP Manual, 19.
  2556.                Shapiro (1979), 143.
  2557.  
  2558.  
  2559.  
  2560.  
  2561.  
  2562.  
  2563.  
  2564.  
  2565.  
  2566.  
  2567.  
  2568.  
  2569.  
  2570.  
  2571.  
  2572.        AI Programming in SNOBOL4      - 125 -                    August, 1982
  2573.  
  2574.  
  2575.  
  2576.  
  2577.  
  2578.  
  2579.  
  2580.  
  2581.           +-----------------------------+
  2582.           | *NULL(L)                    |
  2583.           +-----------------------------+
  2584.  
  2585.             *NULL(L)
  2586.  
  2587.             Returns the null string.  It succeeds if L is NIL; otherwise,
  2588.                it fails.  NOT is a synonym for NULL.
  2589.  
  2590.                The argument L must be a list (datatype CONS) or a fatal
  2591.                error will result.
  2592.  
  2593.             General Categories: Predicate
  2594.  
  2595.             Example: NULL(T) fails.
  2596.  
  2597.             References: Charniak et al. (1980), 306.
  2598.                MTS LISP Manual, 18.
  2599.                Schank & Riesbeck (1981), 49-50.
  2600.                Shapiro (1979), 153.
  2601.  
  2602.  
  2603.  
  2604.  
  2605.  
  2606.           +-----------------------------+
  2607.           | NULLP(L)                    |
  2608.           +-----------------------------+
  2609.  
  2610.             Returns T if NULL(L) succeeds; otherwise, NIL.  NOTP is a
  2611.                synonym for NULLP.
  2612.  
  2613.                The argument L must be a list (datatype CONS) or a fatal
  2614.                error will result.
  2615.  
  2616.             General Categories: Predicate
  2617.  
  2618.             Example: NULLP(8 ~ NIL) returns NIL.
  2619.  
  2620.             References: See NULL.
  2621.  
  2622.  
  2623.  
  2624.  
  2625.  
  2626.  
  2627.  
  2628.  
  2629.  
  2630.  
  2631.  
  2632.  
  2633.  
  2634.  
  2635.  
  2636.  
  2637.  
  2638.        AI Programming in SNOBOL4      - 126 -                    August, 1982
  2639.  
  2640.  
  2641.  
  2642.  
  2643.  
  2644.  
  2645.  
  2646.  
  2647.           +-----------------------------+
  2648.           | NUMBER(X)                   |
  2649.           +-----------------------------+
  2650.  
  2651.             Returns the null string.  It succeeds if X can be converted to
  2652.                any of the datatypes 'INTEGER', 'REAL', or 'DREAL'; fails
  2653.                otherwise.
  2654.  
  2655.             General Categories: Predicate
  2656.  
  2657.             Example: NUMBER('-3.1415926') succeeds and returns the null
  2658.                string.
  2659.  
  2660.             References: Charniak et al. (1980), 306.
  2661.                MTS LISP Manual, 18.
  2662.                Schank & Riesbeck (1981), 58.
  2663.                Shapiro (1979), 153.
  2664.  
  2665.  
  2666.  
  2667.  
  2668.  
  2669.           +-----------------------------+
  2670.           | NUMBERP(X)                  |
  2671.           +-----------------------------+
  2672.  
  2673.             Returns T if NUMBER(X) succeeds; NIL otherwise.
  2674.  
  2675.             General Categories: Predicate
  2676.  
  2677.             Example: NUMBERP('+3.1415926?') returns NIL.
  2678.  
  2679.             References: See NUMBER.
  2680.  
  2681.  
  2682.  
  2683.  
  2684.  
  2685.           +-----------------------------+
  2686.           | PLUS(L)                     |
  2687.           +-----------------------------+
  2688.  
  2689.             Returns the sum of the numbers in the list L.
  2690.  
  2691.             General Categories: Arithmetic function
  2692.  
  2693.             Example: PLUS(8.3 ~ -9.1 ~ 6.25 ~ NIL) returns 5.45.
  2694.  
  2695.             Comments: Cf. ADD.
  2696.  
  2697.             References: Charniak et al. (1980), 307.
  2698.                MTS LISP Manual, 26 (ADD).
  2699.                Schank & Riesbeck (1981), 58.
  2700.                Shapiro (1979), 154.
  2701.  
  2702.  
  2703.  
  2704.        AI Programming in SNOBOL4      - 127 -                    August, 1982
  2705.  
  2706.  
  2707.  
  2708.  
  2709.  
  2710.  
  2711.  
  2712.  
  2713.           +-----------------------------+
  2714.           | *POP(NAME)                  |
  2715.           +-----------------------------+
  2716.  
  2717.             Synonym for UNCONS(NAME).
  2718.  
  2719.  
  2720.  
  2721.  
  2722.  
  2723.           +-----------------------------+
  2724.           | PRELIST(L,N)                |
  2725.           +-----------------------------+
  2726.  
  2727.             Returns a list consisting of the first N top-level elements of
  2728.                L.  If N is zero, NIL is returned.  If N exceeds LENGTH(L),
  2729.                L is returned.  If N is negative, the last ABS(N) elements
  2730.                of L are returned.
  2731.  
  2732.             General Categories: List decomposition
  2733.                List search
  2734.  
  2735.             Example: PRELIST('A' ~ 'B' ~ 'C' ~ 'D' ~ 'E' ~ NIL, 3) returns
  2736.                'A' ~ 'B' ~ 'C' ~ NIL.
  2737.  
  2738.             References: Charniak et al. (1980), 96, 307.
  2739.  
  2740.  
  2741.  
  2742.  
  2743.  
  2744.           +-----------------------------+
  2745.           | *PRINT(X)                   |
  2746.           +-----------------------------+
  2747.  
  2748.             Synonym for PRT.VIA.OUTPUT.
  2749.  
  2750.  
  2751.  
  2752.  
  2753.  
  2754.  
  2755.  
  2756.  
  2757.  
  2758.  
  2759.  
  2760.  
  2761.  
  2762.  
  2763.  
  2764.  
  2765.  
  2766.  
  2767.  
  2768.  
  2769.  
  2770.        AI Programming in SNOBOL4      - 128 -                    August, 1982
  2771.  
  2772.  
  2773.  
  2774.  
  2775.  
  2776.  
  2777.  
  2778.  
  2779.           +-----------------------------+
  2780.           | PRINT.IN.FIELD(N,X)         |
  2781.           +-----------------------------+
  2782.  
  2783.             Returns a string which depends upon the values of N and X.  If
  2784.                the first two characters of X are 'C.', 'L.', or 'R.', then
  2785.                the rest of X is treated as an expression, and its value is
  2786.                centered ('C.'), left-justified ('L.'), or right-justified
  2787.                ('R.') in a field of N spaces.  If the first two characters
  2788.                of X do not match any of the three special prefixes ('C.',
  2789.                'L.', or 'R.'), then N copies of X are concatenated and the
  2790.                resulting string is returned.
  2791.  
  2792.                This function is intended to help with formatted output.
  2793.                The binary operator $ is OPSYNed to PRINT.IN.FIELD: (N % X)
  2794.                is equivalent to PRINT.IN.FIELD(N,X).
  2795.  
  2796.             General Categories: Datatype conversion
  2797.                Output
  2798.  
  2799.             Side Effects: If the first two characters of X are 'C.', 'L.',
  2800.                or 'R.', then the remainder of X is EVALed.  This may or may
  2801.                not have side effects, depending upon the value of X.
  2802.  
  2803.             Example: The statement
  2804.                     |(62 % 'C.LST')
  2805.                will center the value of LST in a 62-column field.  In other
  2806.                words, the value of LST will be padded with blanks on the
  2807.                left and right to increase its length to 62.
  2808.  
  2809.             Comments: If the string to be padded exceeds the requested
  2810.                field size, the string itself is returned.
  2811.  
  2812.                Note that, although this function is classified as an output
  2813.                function, it does not by itself cause anything to be written
  2814.                to the output file.  It is intended to be embedded in an
  2815.                argument to PRT.VIA.OUTPUT (|).
  2816.  
  2817.             References: Shapiro (1979), 144-147.
  2818.  
  2819.  
  2820.  
  2821.  
  2822.  
  2823.  
  2824.  
  2825.  
  2826.  
  2827.  
  2828.  
  2829.  
  2830.  
  2831.  
  2832.  
  2833.  
  2834.  
  2835.  
  2836.        AI Programming in SNOBOL4      - 129 -                    August, 1982
  2837.  
  2838.  
  2839.  
  2840.  
  2841.  
  2842.  
  2843.  
  2844.  
  2845.           +-----------------------------+
  2846.           | *PRT.VIA.OUTPUT(X)          |
  2847.           +-----------------------------+
  2848.  
  2849.             Returns the string representation of X.  The unary operator |
  2850.                is OPSYNed to this function: That is, |X is equivalent to
  2851.                PRT.VIA.OUTPUT(X).
  2852.  
  2853.             General Categories: Output
  2854.  
  2855.             Side Effects: This string representation of X is written to the
  2856.                output file associated with the identifier "OUTPUT.".  (Note
  2857.                that the name of this identifier ends with a period.)
  2858.                Initially,this output file will be the user's terminal.
  2859.  
  2860.             Example:
  2861.                |''  will print one blank line
  2862.                |||''  will print three blank lines
  2863.                |'Hi, sailor!'  will print a friendly greeting.
  2864.  
  2865.             Comments: See IN, PRINT.IN.FIELD, UNREAD, and PRINT.
  2866.  
  2867.  
  2868.  
  2869.  
  2870.  
  2871.           +-----------------------------+
  2872.           | PUT(NAME,S,X)               |
  2873.           +-----------------------------+
  2874.  
  2875.             Returns the modified property list of NAME.
  2876.  
  2877.             General Categories: Alters existing CONS cell(s)
  2878.                List composition
  2879.                List search
  2880.                Property-list function
  2881.  
  2882.             Side Effects: X is put on the property list of the identifier
  2883.                named NAME, under the indicator S.  If S already has a value
  2884.                or list of values associated with it, all such values are
  2885.                deleted and replaced by X.
  2886.  
  2887.                If X is NIL, then S is placed on the property list as an
  2888.                indicator with no associated values.
  2889.  
  2890.             Example: PUT( .CHILD, 'BEHAVIOR', 'CHARMING') puts the element
  2891.                ('BEHAVIOR' ~ 'CHARMING' ~ NIL) on the property list of the
  2892.                identifier CHILD.  Any previous value(s) associated with
  2893.                'BEHAVIOR' are erased.
  2894.  
  2895.             Comments: Cf. ADDPROP, GET, DEFPROP, PUTPROP, GETL, PUTL.
  2896.  
  2897.             References: MTS LISP Manual, 24.
  2898.                Shapiro (1979), 154.
  2899.  
  2900.  
  2901.  
  2902.        AI Programming in SNOBOL4      - 130 -                    August, 1982
  2903.  
  2904.  
  2905.  
  2906.  
  2907.  
  2908.  
  2909.  
  2910.  
  2911.           +-----------------------------+
  2912.           | PUTL(L,S,X)                 |
  2913.           +-----------------------------+
  2914.  
  2915.             Returns NIL.
  2916.  
  2917.             General Categories: Alters existing CONS cell(s)
  2918.                List composition
  2919.                List search
  2920.                Property-list function
  2921.  
  2922.             Side Effects: Puts X under the indicator S on the property list
  2923.                of each identifier whose name is an element of L, erasing
  2924.                any previous value(s) associated with S.
  2925.  
  2926.             Example: PUTL(LID,'STAGE',NIL) initializes the value for the
  2927.                property indicator 'STAGE' (or resets that value) for each
  2928.                identifier whose name is an element of LID.
  2929.  
  2930.             References: MTS LISP Manual, 24 (PUT).
  2931.  
  2932.  
  2933.  
  2934.  
  2935.  
  2936.  
  2937.  
  2938.  
  2939.  
  2940.  
  2941.  
  2942.  
  2943.  
  2944.  
  2945.  
  2946.  
  2947.  
  2948.  
  2949.  
  2950.  
  2951.  
  2952.  
  2953.  
  2954.  
  2955.  
  2956.  
  2957.  
  2958.  
  2959.  
  2960.  
  2961.  
  2962.  
  2963.  
  2964.  
  2965.  
  2966.  
  2967.  
  2968.        AI Programming in SNOBOL4      - 131 -                    August, 1982
  2969.  
  2970.  
  2971.  
  2972.  
  2973.  
  2974.  
  2975.  
  2976.  
  2977.           +-----------------------------+
  2978.           | PUTPROP(NAME,X,S)           |
  2979.           +-----------------------------+
  2980.  
  2981.             Returns the modified property list of NAME.
  2982.  
  2983.             General Categories: Alters existing CONS cell(s)
  2984.                List composition
  2985.                List search
  2986.                Property-list function
  2987.  
  2988.             Side Effects: It adds X to the list of values associated with
  2989.                the indicator S on the property list of the identifier named
  2990.                NAME (without erasing other values associated with S).
  2991.  
  2992.                If X is NIL, and if S is already an indicator on the
  2993.                property list, then nothing changes.  If X is NIL and S is
  2994.                not an indicator, then (S   NIL) is added to the property
  2995.                list.
  2996.  
  2997.             Example:
  2998.  
  2999.             Suppose 'BEHAVIOR' ~ 'CHARMING' ~ NIL is an element of the
  3000.                property list of CHILD.
  3001.  
  3002.                PUTPROP(.CHILD,'AMUSING','BEHAVIOR') would change this
  3003.                element to ('BEHAVIOR' ~ 'AMUSING' ~ 'CHARMING' ~ NIL).
  3004.  
  3005.             Comments: Cf. PUT, ADDPROP, PUTL, DEFPROP.
  3006.  
  3007.             References: Charniak et al. (1980), 308.
  3008.                MTS LISP Manual, 25 (ADDPROP).
  3009.                Schank & Riesbeck (1981), 50, 59.
  3010.  
  3011.  
  3012.  
  3013.  
  3014.  
  3015.  
  3016.  
  3017.  
  3018.  
  3019.  
  3020.  
  3021.  
  3022.  
  3023.  
  3024.  
  3025.  
  3026.  
  3027.  
  3028.  
  3029.  
  3030.  
  3031.  
  3032.  
  3033.  
  3034.        AI Programming in SNOBOL4      - 132 -                    August, 1982
  3035.  
  3036.  
  3037.  
  3038.  
  3039.  
  3040.  
  3041.  
  3042.  
  3043.           +-----------------------------+
  3044.           | QUOTIENT(L)                 |
  3045.           +-----------------------------+
  3046.  
  3047.             Returns the first element of L, divided by the product of the
  3048.                rest.  (If L has just one element, that element is
  3049.                returned.)
  3050.  
  3051.             General Categories: Arithmetic function
  3052.  
  3053.             Example: QUOTIENT(5 ~ 4 ~ 3 ~ 2 ~ 1 ~ NIL) returns
  3054.                .20833333333333.
  3055.  
  3056.             Comments: Double precision division is automatic.
  3057.  
  3058.             References: Charniak et al. (1980), 308.
  3059.                MTS LISP Manual, 26 (binary DIVIDE).
  3060.                Shapiro (1979), 154.
  3061.  
  3062.  
  3063.  
  3064.  
  3065.  
  3066.           +-----------------------------+
  3067.           | RAC(L)                      |
  3068.           +-----------------------------+
  3069.  
  3070.             Returns the last top-level element of L.
  3071.  
  3072.             General Categories: List decomposition
  3073.                List search
  3074.  
  3075.             Example: Let L = #'((E A T) MORE F I S H)'.  Then RAC(L)
  3076.                returns 'H'.
  3077.  
  3078.             Comments: RAC(L) is not equivalent to LAST(L), but it is
  3079.                equivalent to CAR(LREVERSE(L)).
  3080.  
  3081.             References: Shapiro (1979), 154.
  3082.  
  3083.  
  3084.  
  3085.  
  3086.  
  3087.           +-----------------------------+
  3088.           | RAD(N)                      |
  3089.           +-----------------------------+
  3090.  
  3091.             Returns the number of radians in N degrees.
  3092.  
  3093.             General Categories: Arithmetic function
  3094.  
  3095.             Example: RAD(66.666667) returns 1.1635529234349.
  3096.  
  3097.  
  3098.  
  3099.  
  3100.        AI Programming in SNOBOL4      - 133 -                    August, 1982
  3101.  
  3102.  
  3103.  
  3104.  
  3105.  
  3106.  
  3107.  
  3108.  
  3109.           +-----------------------------+
  3110.           | RAISE(N1,N2)                |
  3111.           +-----------------------------+
  3112.  
  3113.             Returns N1**N2.  N1 and N2 may be integers or floating point
  3114.                numbers.
  3115.  
  3116.             General Categories: Arithmetic function
  3117.  
  3118.             Example: RAISE(2, DIV(P...I., 2)) returns 2.9706864235513.
  3119.  
  3120.             References: Gimpel (1976), 337.
  3121.  
  3122.  
  3123.  
  3124.  
  3125.  
  3126.           +-----------------------------+
  3127.           | RDC(L)                      |
  3128.           +-----------------------------+
  3129.  
  3130.             Returns a copy of L with its last top-level element deleted.
  3131.  
  3132.             General Categories: List decomposition
  3133.                List search
  3134.  
  3135.             Example: Let L = #'(A AA AAA AAAA)'.  Then RDC(L) returns ('A'
  3136.                ~ 'AA' ~ 'AAA' ~ NIL).
  3137.  
  3138.             Comments: RDC(L) = LREVERSE(CDR(LREVERSE(L))).
  3139.  
  3140.             References: Shapiro (1979), 154.
  3141.  
  3142.  
  3143.  
  3144.  
  3145.  
  3146.  
  3147.  
  3148.  
  3149.  
  3150.  
  3151.  
  3152.  
  3153.  
  3154.  
  3155.  
  3156.  
  3157.  
  3158.  
  3159.  
  3160.  
  3161.  
  3162.  
  3163.  
  3164.  
  3165.  
  3166.        AI Programming in SNOBOL4      - 134 -                    August, 1982
  3167.  
  3168.  
  3169.  
  3170.  
  3171.  
  3172.  
  3173.  
  3174.  
  3175.           +-----------------------------+
  3176.           | *READ(S)                    |
  3177.           +-----------------------------+
  3178.  
  3179.             Returns the list represented by S.  String-to-list conversion
  3180.                is carried out using LISP-like rules.  The # unary operator
  3181.                is OPSYNed to the READ function: #S is equivalent to
  3182.                READ(S).
  3183.  
  3184.             General Categories: Datatype conversion
  3185.                List composition
  3186.  
  3187.             Side Effects: In READ only, a \ unary operator indicates that
  3188.                the value of a string is to replace the string.  Multiple
  3189.                \'s indicate multiple evaluations.
  3190.  
  3191.             Example:
  3192.                Let A = 5, B = 'BOOK', and C = 'CHILD'.
  3193.                Then #'((A \A) (B \B) (C . \C))' returns
  3194.                  (('A' ~ 5 ~ NIL) ~ ('B' ~ 'BOOK' ~ NIL) ~
  3195.                   ('C' ~ 'CHILD') ~ NIL).
  3196.  
  3197.             Comments: Dotted pairs are allowed, as in LISP, but there must
  3198.                be at least one blank on each side of the dot, and the
  3199.                dotted pair must be surrounded by parentheses.
  3200.  
  3201.                Quoted literal strings are recognized.  Double quotes (")
  3202.                can occur inside single-quoted (') strings and vice versa.
  3203.                Blanks and parentheses can occur inside quoted strings.
  3204.  
  3205.                The following expressions all translate to NIL:
  3206.                ('' . ''), ("" . ""), (), and NIL.  Also, as indicated in
  3207.                the example, NIL is provided automatically at the end of a
  3208.                normal list.
  3209.  
  3210.                The following expressions translate to T:
  3211.                T and (T . T).
  3212.  
  3213.  
  3214.  
  3215.  
  3216.  
  3217.  
  3218.  
  3219.  
  3220.  
  3221.  
  3222.  
  3223.  
  3224.  
  3225.  
  3226.  
  3227.  
  3228.  
  3229.  
  3230.  
  3231.  
  3232.        AI Programming in SNOBOL4      - 135 -                    August, 1982
  3233.  
  3234.  
  3235.  
  3236.  
  3237.  
  3238.  
  3239.  
  3240.  
  3241.           +-----------------------------+
  3242.           | READLIST(L)                 |
  3243.           +-----------------------------+
  3244.  
  3245.             Returns READ(CONCAT(L)).  L is a list of strings, not
  3246.                necessarily single characters.  All the strings are
  3247.                concatenated to form one long string S.  READLIST then
  3248.                returns READ(S).
  3249.  
  3250.             General Categories: Datatype conversion
  3251.                List composition
  3252.  
  3253.             Example: Let L =
  3254.                ( '(' ~ 'FO' ~ ' TO' ~ ' ' ~ 'MAT)' ~ NIL ).
  3255.  
  3256.             CONCAT would form the concatenated string '(FO TO MAT)' and
  3257.                READLIST would return #'(FO TO MAT)', which is the list
  3258.                ('FO' ~ 'TO' ~ 'MAT' ~ NIL).
  3259.  
  3260.             References: Charniak et al. (1980), 51, 71, 308.
  3261.                Shapiro (1979), 154.
  3262.  
  3263.  
  3264.  
  3265.  
  3266.  
  3267.           +-----------------------------+
  3268.           | *REMAINDER(N1,N2)           |
  3269.           +-----------------------------+
  3270.  
  3271.             Returns N1 modulo N2.
  3272.  
  3273.             General Categories: Arithmetic function
  3274.  
  3275.             Example: REMAINDER(8,3) returns 2.
  3276.  
  3277.             Comments: N1 and N2 must be integers.  REMAINDER is the same as
  3278.                the SPITBOL REMDR function.  This means that the sign of the
  3279.                result is, by definition, the sign of the first argument.
  3280.  
  3281.             References: Charniak et al. (1980), 308.
  3282.                MTS LISP Manual, 26.
  3283.                Shapiro (1979), 155.
  3284.  
  3285.  
  3286.  
  3287.  
  3288.  
  3289.  
  3290.  
  3291.  
  3292.  
  3293.  
  3294.  
  3295.  
  3296.  
  3297.  
  3298.        AI Programming in SNOBOL4      - 136 -                    August, 1982
  3299.  
  3300.  
  3301.  
  3302.  
  3303.  
  3304.  
  3305.  
  3306.  
  3307.           +-----------------------------+
  3308.           | REMOVE(L,X)
  3309.           +-----------------------------+
  3310.  
  3311.             Returns a new list in which all occurrences of X in L have been
  3312.                deleted.
  3313.  
  3314.             General Categories: List composition
  3315.                List decomposition
  3316.                List search
  3317.  
  3318.             Example: If L = #'((1 A) (2 B) (3 (2 B)))', then
  3319.                REMOVE( L, (2 ~ 'B' ~ NIL) ) returns
  3320.                (1 ~ 'A' ~ NIL) ~ (3 ~ NIL) ~ NIL.
  3321.  
  3322.             References: Charniak et al. (1980),
  3323.                MTS LISP Manual, 20-21 (COPY), 23 (DELETE).
  3324.                Schank & Riesbeck (1981), 59.
  3325.                Shapiro (1979), 155.
  3326.  
  3327.  
  3328.  
  3329.  
  3330.  
  3331.           +-----------------------------+
  3332.           | REMPROP(NAME,S)             |
  3333.           +-----------------------------+
  3334.  
  3335.             Returns T if the indicator S is found on the property list of
  3336.                the identifier named NAME; otherwise NIL.
  3337.  
  3338.             General Categories: List decomposition
  3339.                List search
  3340.                Predicate
  3341.                Property-list function
  3342.  
  3343.             Side Effects: The indicator S and all its associated values are
  3344.                removed from the property list of NAME.
  3345.  
  3346.             Example: REMPROP( .CHILD, 'BEHAVIOR') removes the indicator
  3347.                'BEHAVIOR' from the property list of CHILD, returning T if
  3348.                such an indicator was there to be removed, or NIL if no such
  3349.                indicator was there.
  3350.  
  3351.             References: Charniak et al. (1980), 308.
  3352.                MTS LISP Manual, 24 (REM).
  3353.                Schank & Riesbeck (1981), 59.
  3354.  
  3355.  
  3356.  
  3357.  
  3358.  
  3359.  
  3360.  
  3361.  
  3362.  
  3363.  
  3364.        AI Programming in SNOBOL4      - 137 -                    August, 1982
  3365.  
  3366.  
  3367.  
  3368.  
  3369.  
  3370.  
  3371.  
  3372.  
  3373.           +-----------------------------+
  3374.           | ROUND(N)                    |
  3375.           +-----------------------------+
  3376.  
  3377.             Returns N rounded to the nearest integer.   (.5 rounds up for
  3378.                positive numbers and down for negative numbers.)
  3379.  
  3380.             General Categories: Arithmetic function
  3381.  
  3382.             Example: ROUND(-8.5) returns -9.
  3383.  
  3384.             References: Shapiro (1979), 147.
  3385.  
  3386.  
  3387.  
  3388.  
  3389.  
  3390.           +-----------------------------+
  3391.           | RPLACA(L,X)                 |
  3392.           +-----------------------------+
  3393.  
  3394.             Returns the list formed by replacing the CAR of L with X.
  3395.  
  3396.             General Categories:  Alters existing CONS cell(s)
  3397.                List composition
  3398.  
  3399.             Side Effects: This is a function that alters an existing CONS
  3400.                cell.  Therefore, it carries the usual risks of creating
  3401.                circular lists and of unintentionally altering  the values
  3402.                of other variables (cf. NCONC).
  3403.  
  3404.             Example: Consider the assignment statement
  3405.                     L = RPLACA(L,L)
  3406.                This statement creates a circular list.
  3407.  
  3408.             References: Charniak et al. (1980), 21-22, 308.
  3409.                MTS LISP Manual, 22.
  3410.  
  3411.  
  3412.  
  3413.  
  3414.  
  3415.  
  3416.  
  3417.  
  3418.  
  3419.  
  3420.  
  3421.  
  3422.  
  3423.  
  3424.  
  3425.  
  3426.  
  3427.  
  3428.  
  3429.  
  3430.        AI Programming in SNOBOL4      - 138 -                    August, 1982
  3431.  
  3432.  
  3433.  
  3434.  
  3435.  
  3436.  
  3437.  
  3438.  
  3439.           +-----------------------------+
  3440.           | RPLACD(L,X)                 |
  3441.           +-----------------------------+
  3442.  
  3443.             Returns the list created by replacing the CDR of L with X.
  3444.  
  3445.             General Categories: Alters existing CONS cell(s)
  3446.                List composition
  3447.  
  3448.             Side Effects: See RPLACA, NCONC.
  3449.  
  3450.             Example: If L = #'((A B) (C (D E)) F)', then
  3451.                     RPLACD(L, ('E' ~ 'F' ~ NIL)) returns
  3452.                     (('A' ~ 'B' ~ NIL) ~ 'E' ~ 'F' ~ NIL).
  3453.                This list also becomes the value of L.
  3454.  
  3455.             References: Charniak et al. (1980), 21-22, 309.
  3456.                MTS LISP Manual, 22-23.
  3457.  
  3458.  
  3459.  
  3460.  
  3461.  
  3462.           +-----------------------------+
  3463.           | RPLACN(L,N,X)               |
  3464.           +-----------------------------+
  3465.  
  3466.             Returns the list created by replacing the Nth element of L with
  3467.                X.  If N is 0, then X is CONSed onto the front of L.  If N >
  3468.                LENGTH(L), then LIST(X,NIL) is NCONCed onto the end of L.
  3469.                If N < 0, the elements of L are numbered "from the right,"
  3470.                with the last element being number 1.
  3471.  
  3472.             General Categories: Alters existing CONS cell(s)
  3473.                List composition
  3474.                List search
  3475.  
  3476.             Side Effects: The value of L is changed unless N = 0.
  3477.  
  3478.             Example: If L = #'(1 2 3 4 5 6)', then
  3479.                     RPLACN(L,3,'THREE') returns
  3480.                     (1 ~ 2 ~  'THREE' ~ 4 ~ 5 ~ 6 ~ NIL).
  3481.                This list also becomes the new value of L.
  3482.  
  3483.             Comments: See RPLACA, RPLACD, NCONC.
  3484.  
  3485.             References: Shapiro (1979), 143.
  3486.  
  3487.  
  3488.  
  3489.  
  3490.  
  3491.  
  3492.  
  3493.  
  3494.  
  3495.  
  3496.        AI Programming in SNOBOL4      - 139 -                    August, 1982
  3497.  
  3498.  
  3499.  
  3500.  
  3501.  
  3502.  
  3503.  
  3504.  
  3505.           +-----------------------------+
  3506.           | SET.(NAME,X)                |
  3507.           +-----------------------------+
  3508.  
  3509.             Returns X.
  3510.  
  3511.             General Categories: Definitional function
  3512.  
  3513.             Side Effects: X becomes the value of the identifier named NAME.
  3514.  
  3515.             Example: SET.( .C, 'SHINING') returns 'SHINING' and sets the
  3516.                value of C to 'SHINING'.
  3517.  
  3518.             Comments: (Editor's note) This function was named SET (no
  3519.                period) in the original report.  The period is appended to
  3520.                distinguish the function from the Spitbol function by the
  3521.                same name, used to position direct-access files.
  3522.  
  3523.             References: Charniak et al. (1980), 18, 309.
  3524.                MTS LISP Manual, 22.
  3525.                Schank & Riesbeck (1981), 60.
  3526.                Shapiro (1979), 155.
  3527.  
  3528.  
  3529.  
  3530.  
  3531.  
  3532.           +-----------------------------+
  3533.           | SETL(L)                     |
  3534.           +-----------------------------+
  3535.  
  3536.             Returns the list with elements CADR(L), CADDDR(L), ...; i.e.,
  3537.                the even-numbered elements of L.
  3538.  
  3539.             General Categories: Definitional function
  3540.                List composition
  3541.                List decomposition
  3542.  
  3543.             Side Effects: Sets the value of CAR(L) to CADR(L), of CADDR(L)
  3544.                to CADDDR(L), and so on.  Note that the odd-numbered
  3545.                elements of L are interpreted as names, and the even-
  3546.                numbered elements are interpreted as values.
  3547.  
  3548.             Example: If A = #'(X1 5 X2 17 X3 19 X4 23)', then SETL(A)
  3549.                returns (5 ~ 17 ~ 19 ~ 23 ~ NIL) and sets X1 = 5, X2 = 17,
  3550.                X3 = 19, and X4 = 23.
  3551.  
  3552.             Comments: This is just the list-argument form of SET which is
  3553.                available in some LISPs.  Note that the structure of the
  3554.                argument list determines whether SETL acts like LISP's SETQ,
  3555.                SET, or something else.
  3556.  
  3557.  
  3558.  
  3559.  
  3560.  
  3561.  
  3562.        AI Programming in SNOBOL4      - 140 -                    August, 1982
  3563.  
  3564.  
  3565.  
  3566.  
  3567.  
  3568.  
  3569.  
  3570.  
  3571.           +-----------------------------+
  3572.           | SIGN(N)                     |
  3573.           +-----------------------------+
  3574.  
  3575.             Returns -1 if N is negative, 1 if N is positive, 0 if N is
  3576.                zero.
  3577.  
  3578.             General Categories: Arithmetic function
  3579.  
  3580.             Example: SIGN(8 x -9.5) returns -1.
  3581.  
  3582.  
  3583.  
  3584.  
  3585.  
  3586.           +-----------------------------+
  3587.           | SIN(N)                      |
  3588.           +-----------------------------+
  3589.  
  3590.             Returns the sine of N radians.  N may be any integer or real
  3591.                number.
  3592.  
  3593.             General Categories: Arithmetic function
  3594.  
  3595.             Example: SIN(P...I. / 4) returns 0.70710678118633.
  3596.                (P...I. = pi.)
  3597.  
  3598.             References: Gimpel (1976), 332-333.
  3599.  
  3600.  
  3601.  
  3602.  
  3603.  
  3604.           +-----------------------------+
  3605.           | SORT.(A,N1,N2,S)            |
  3606.           +-----------------------------+
  3607.  
  3608.             Returns the array A with elements N1 through N2 sorted
  3609.                according to predicate P.  P may be 'LE' (numeric array,
  3610.                ascending sort), 'GE' (numeric, descending), 'LLE' (string,
  3611.                ascending), or 'LGE' (string, descending).
  3612.  
  3613.             Side Effects: The array argument itself is altered.
  3614.  
  3615.             Example: If ROSTER is an array of N students' names, then
  3616.                SORT.(ROSTER,1,N, 'LLE') will cause the names to be arranged
  3617.                in alphabetical order.
  3618.  
  3619.             Comments: The sorting method is described in Singleton (1968).
  3620.                
  3621.                (Editor's note) This function was named SORT (no period) in
  3622.                the original report.  The period is appended to distinguish
  3623.                the function from the Spitbol function by the same name.
  3624.  
  3625.  
  3626.  
  3627.  
  3628.        AI Programming in SNOBOL4      - 141 -                    August, 1982
  3629.  
  3630.  
  3631.  
  3632.  
  3633.  
  3634.  
  3635.  
  3636.  
  3637.             References: Singleton (1968).
  3638.                Gimpel (1975), 280, 292, 299.
  3639.                Wirth (1976), 76-84.
  3640.  
  3641.  
  3642.  
  3643.  
  3644.  
  3645.           +-----------------------------+
  3646.           | SNOC(L,X)                   |
  3647.           +-----------------------------+
  3648.  
  3649.             Returns a copy of L with X added on as the last top-level
  3650.                element.
  3651.  
  3652.             General Categories: List composition
  3653.  
  3654.             Example: If L = ~'(A B C)', then
  3655.                SNOC( L, 4) returns ('A' ~ 'B' ~ 'C' ~ 4 ~ NIL).
  3656.  
  3657.             References: Schank & Riesbeck ~i981), 54, 69 (CONS-END).
  3658.                Shapiro (1979), 155,
  3659.  
  3660.  
  3661.  
  3662.  
  3663.  
  3664.           +-----------------------------+
  3665.           | SOME(NAME,L)                |
  3666.           +-----------------------------+
  3667.  
  3668.             Returns T if the function named NAME returns a non-NIL value
  3669.                for some argument in the list L; NIL otherwise.
  3670.  
  3671.             General Categories: Mapping function
  3672.                Predicate
  3673.  
  3674.             Example: If L = #'(! # $ % & 18.9 * =)',
  3675.                then SOME( .NUMBERP, L) returns T.
  3676.  
  3677.             Comments: Cf. EVERY, SUBSET.
  3678.  
  3679.             References: Charniak et al. (1980), 309.
  3680.                Schank & Riesbeck (1981), 66.
  3681.  
  3682.  
  3683.  
  3684.  
  3685.  
  3686.  
  3687.  
  3688.  
  3689.  
  3690.  
  3691.  
  3692.  
  3693.  
  3694.        AI Programming in SNOBOL4      - 142 -                    August, 1982
  3695.  
  3696.  
  3697.  
  3698.  
  3699.  
  3700.  
  3701.  
  3702.  
  3703.           +-----------------------------+
  3704.           | SQRT(N)                     |
  3705.           +-----------------------------+
  3706.  
  3707.             Returns the double-precision square root of N.  N may be any
  3708.                non-negative integer or floating point number.
  3709.  
  3710.             General Categories: Arithmetic function
  3711.  
  3712.             Example: SQRT(4.5) returns 2.1213203435596.
  3713.  
  3714.             References: Gimpel (1976), 330-331.
  3715.  
  3716.  
  3717.  
  3718.  
  3719.  
  3720.           +-----------------------------+
  3721.           | SUB(N1,N2)                  |
  3722.           +-----------------------------+
  3723.  
  3724.             Returns N1 - N2.
  3725.  
  3726.             General Categories: Arithmetic function
  3727.  
  3728.             Example: SUB(1,8) returns -7.
  3729.  
  3730.             References: Charniak et al. (1980), 303 (DIFFERENCE).
  3731.                MTS LISP Manual, 26.
  3732.                Schank & Riesbeck (1981), 55 (DIFFERENCE).
  3733.                Shapiro (1979), 150 (DIFFERENCE).
  3734.  
  3735.  
  3736.  
  3737.  
  3738.  
  3739.           +-----------------------------+
  3740.           | SUB1(N)                     |
  3741.           +-----------------------------+
  3742.  
  3743.             Returns N - 1.
  3744.  
  3745.             General Categories: Arithmetic function
  3746.  
  3747.             Example: SUB1(14) returns 13.
  3748.  
  3749.             References: Charniak et al. (1980), 309.
  3750.                MTS LISP Manual, 26.
  3751.                Shapiro (1979), 155.
  3752.  
  3753.  
  3754.  
  3755.  
  3756.  
  3757.  
  3758.  
  3759.  
  3760.        AI Programming in SNOBOL4      - 143 -                    August, 1982
  3761.  
  3762.  
  3763.  
  3764.  
  3765.  
  3766.  
  3767.  
  3768.  
  3769.           +-----------------------------+
  3770.           | SUBSET(NAME,L)              |
  3771.           +-----------------------------+
  3772.  
  3773.             Returns a list of the elements of L for which the function
  3774.                named NAME returns a non-NIL value.
  3775.  
  3776.             General Categories: List composition
  3777.                List decomposition
  3778.                Mapping function
  3779.  
  3780.             Example: SUBSET( .ATOMP, #'((A J) (J R) JUDY (SAM SON)
  3781.                ORVILLE)') returns ('JUDY' ~ 'ORVILLE' ~ NIL).
  3782.  
  3783.             References: Charniak et al. (1980), 309.
  3784.  
  3785.  
  3786.  
  3787.  
  3788.  
  3789.           +-----------------------------+
  3790.           | SUBST(L,X1,X2)              |
  3791.           +-----------------------------+
  3792.  
  3793.             Returns a copy of L with each occurrence of X1 replaced by X2.
  3794.  
  3795.             General Categories: List composition
  3796.                List decomposition
  3797.                List search
  3798.  
  3799.             Example: Let L = #'(PAC-MAN (CHOMP CHOMP CHOMP))', X1 =
  3800.                'CHOMP', and X2 = #'(RUN)'.  Then SUBST(L,X1,X2) returns
  3801.                ('PAC-MAN' ~ (('RUN' ~ NIL) ~ ('RUN' ~ NIL) ~ ('RUN' ~ NIL)
  3802.                ~ NIL) ~ NIL).
  3803.  
  3804.             References: Charniak et al. (1980), 309.
  3805.                MTS LISP Manual, 20-21 (COPY).
  3806.                Schank & Riesbeck (1981), 60.
  3807.                Shapiro (1979), 155.
  3808.  
  3809.  
  3810.  
  3811.  
  3812.  
  3813.           +-----------------------------+
  3814.           | SUFLIST(L,N)                |
  3815.           +-----------------------------+
  3816.  
  3817.             Returns the list obtained by applying the CDR operation N times
  3818.                to L.  If N is zero, L is returned.  If N is negative,
  3819.                PRELIST(L,LENGTH(L) + N) is returned; i.e., RDC is applied N
  3820.                times to L.  If ABS(N) exceeds LENGTH(L), NIL is returned.
  3821.  
  3822.  
  3823.  
  3824.  
  3825.  
  3826.        AI Programming in SNOBOL4      - 144 -                    August, 1982
  3827.  
  3828.  
  3829.  
  3830.  
  3831.  
  3832.  
  3833.  
  3834.  
  3835.             General Categories: List decomposition
  3836.                List search
  3837.  
  3838.             Example: If L = #'(A I PROGRAMMING)' then SUFLIST(L,2) returns
  3839.                ('PROGRAMMING' ~ NIL).
  3840.  
  3841.             References: Charniak et al. (1980), 310.
  3842.  
  3843.  
  3844.  
  3845.  
  3846.  
  3847.  
  3848.  
  3849.  
  3850.  
  3851.  
  3852.  
  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.        AI Programming in SNOBOL4      - 145 -                    August, 1982
  3893.  
  3894.  
  3895.  
  3896.  
  3897.  
  3898.  
  3899.  
  3900.  
  3901.           +-----------------------------+
  3902.           | TAN(N)                      |
  3903.           +-----------------------------+
  3904.  
  3905.             Returns the tangent of N radians.  N may be any integer or real
  3906.                number such that COS(N) is different from 0.
  3907.  
  3908.             General Categories: Arithmetic function
  3909.  
  3910.             Example: TAN(SQRT(2) * P...I.) returns 3.6202185670771.
  3911.  
  3912.             References: Gimpel (1976), 332-33j.
  3913.  
  3914.  
  3915.  
  3916.  
  3917.  
  3918.           +-----------------------------+
  3919.           | TDUMP(NAME,N)               |
  3920.           +-----------------------------+
  3921.  
  3922.             Returns nothing: It produces a fatal-error message and
  3923.                terminates the run.
  3924.  
  3925.             General Categories: Output
  3926.  
  3927.             Side Effects: NAME is the name of the function in which the
  3928.                fatal error occurred.  N, which is optional, is the number
  3929.                of the argument (to NAME) which caused the fatal error.
  3930.  
  3931.                TDUMP prints a message which gives the name of the function
  3932.                NAME, the name and value of each argument to NAME, and the
  3933.                name and value of each local variable in NAME when the error
  3934.                occurred.  If N is specified, then the Nth argument is
  3935.                flagged (with a row of asterisks to its left) to indicate
  3936.                that it was the cause of the error.
  3937.  
  3938.                Finally, TDUMP accepts an integer (0, 1, or 2) from the
  3939.                user's terminal.  (The user is prompted for this.)  A zero
  3940.                indicates that no SPITBOL dump is desired; a 1 requests a 1-
  3941.                level SPITBOL dump (names and values of all keywords and
  3942.                natural variables); and a 2 requests a 2-level dump (same as
  3943.                1, plus array, table, and list elements).
  3944.  
  3945.             Example: TDUMP(.F9,2) causes a fatal-error message to be
  3946.                printed, with F9 as the name of the offending function and
  3947.                with the second argument to F9 flagged as the cause of the
  3948.                error.
  3949.  
  3950.  
  3951.  
  3952.  
  3953.  
  3954.  
  3955.  
  3956.  
  3957.  
  3958.        AI Programming in SNOBOL4      - 146 -                    August, 1982
  3959.  
  3960.  
  3961.  
  3962.  
  3963.  
  3964.  
  3965.  
  3966.  
  3967.           +-----------------------------+
  3968.           | TIMES(L)                    |
  3969.           +-----------------------------+
  3970.  
  3971.             Returns the product of the numbers on the list L.
  3972.  
  3973.             General Categories: Arithmetic function
  3974.  
  3975.             Example: TIMES( #'(8 7 6 5 4 3 2 1 0)') returns 0.
  3976.  
  3977.             Comments: Cf. MULT.
  3978.  
  3979.             References: Charniak et al. (1980), 310.
  3980.                MTS LISP Manual, 26.
  3981.                Schank & Riesbeck (1981), 60.
  3982.                Shapiro (1979), 156.
  3983.  
  3984.  
  3985.  
  3986.  
  3987.  
  3988.           +-----------------------------+
  3989.           | *UNCONS(NAME)               |
  3990.           +-----------------------------+
  3991.  
  3992.             Returns the CAR of the list which is the value of the
  3993.                identifier named NAME.  A synonym for UNCONS is POP.
  3994.  
  3995.             General Categories: List decomposition
  3996.  
  3997.             Side Effects: The value of the identifier named NAME becomes
  3998.                the CDR of its former value.
  3999.  
  4000.             Example: Let C = #'(F R U I T)'.  Then POP( .C) returns 'F',
  4001.                and the value of C becomes ('R' ~ 'U' ~ 'I' ~ 'T' ~ NIL).
  4002.  
  4003.             Comments: The value of NAME cannot be a dotted pair or an atom;
  4004.                if it is, a fatal error results.  If the value of NAME is
  4005.                NIL, then POP fails; this is useful for loop control.
  4006.  
  4007.             References: Charniak et al. (1980), 34-37, 307.
  4008.                MTS LISP Manual, 29.
  4009.                Schank & Riesbeck (1981), 49, 58, 69.
  4010.  
  4011.  
  4012.  
  4013.  
  4014.  
  4015.  
  4016.  
  4017.  
  4018.  
  4019.  
  4020.  
  4021.  
  4022.  
  4023.  
  4024.        AI Programming in SNOBOL4      - 147 -                    August, 1982
  4025.  
  4026.  
  4027.  
  4028.  
  4029.  
  4030.  
  4031.  
  4032.  
  4033.           +-----------------------------+
  4034.           | UNION(L1,L2)                |
  4035.           +-----------------------------+
  4036.  
  4037.             Returns a list of the elements which appear in L1 or in L2,
  4038.                without duplicates.
  4039.  
  4040.             General Categories: List composition
  4041.                List decomposition
  4042.                List search
  4043.  
  4044.             Example: UNION(#'(Z W X)', #'(8 X R W)') returns ('Z' ~ 'W' ~
  4045.                'X' ~ 8 ~ 'R' ~ NIL).
  4046.  
  4047.             References: Charniak et al. (1980), 110-112.
  4048.                MTS LISP Manual, 21.
  4049.                Shapiro (1979), 130.
  4050.  
  4051.  
  4052.  
  4053.  
  4054.  
  4055.           +-----------------------------+
  4056.           | *UNREAD(L)                  |
  4057.           +-----------------------------+
  4058.  
  4059.             Returns the string expression for the list L, using (more or
  4060.                less) LISP syntax.  Lists and dotted pairs are
  4061.                parenthesized.  Literal atoms containing internal blanks are
  4062.                enclosed in quotes (") unless they are already enclosed in
  4063.                quotes.
  4064.  
  4065.             The unary operator | is OPSYNed to the UNREAD function: !L is
  4066.                equivalent to UNREAD(L).
  4067.  
  4068.             General Categories: Datatype conversion
  4069.  
  4070.             Example: If L = 'L' ~ 'I' ~ 'S' ~ 'T' ~ NIL, then
  4071.                !L = '(L I S T)'.
  4072.  
  4073.             References: Charniak et al. (1980).
  4074.                MTS LISP Manual.
  4075.                Schank & Riesbeck (1981).
  4076.                Shapiro (1979).
  4077.  
  4078.  
  4079.  
  4080.  
  4081.  
  4082.  
  4083.  
  4084.  
  4085.  
  4086.  
  4087.  
  4088.  
  4089.  
  4090.        AI Programming in SNOBOL4      - 148 -                    August, 1982
  4091.  
  4092.  
  4093.  
  4094.  
  4095.  
  4096.  
  4097.  
  4098.  
  4099.           +-----------------------------+
  4100.           | ZERO(N)                     |
  4101.           +-----------------------------+
  4102.  
  4103.             Returns the null string.  It succeeds if N is equal to 0; fails
  4104.                otherwise.
  4105.  
  4106.             General Categories: Arithmetic function
  4107.                Predicate
  4108.  
  4109.             Example: ZERO(11.23581321) fails.
  4110.  
  4111.             References: Charniak et al. (;980), 310.
  4112.                MTS LISP Manual, 25.
  4113.                Shapiro (1979), i56.
  4114.  
  4115.  
  4116.  
  4117.  
  4118.  
  4119.           +-----------------------------+
  4120.           | ZEROP(N)                    |
  4121.           +-----------------------------+
  4122.  
  4123.             Returns T if ZERO(N) succeeds; NIL otherwise.
  4124.  
  4125.             General Categories: Arithmetic function
  4126.                Predicate
  4127.  
  4128.             Example: ZEROP(5.0 ~ '5') returns T.
  4129.  
  4130.             References: See ZERO.
  4131.  
  4132.  
  4133.  
  4134.  
  4135.  
  4136.  
  4137.  
  4138.  
  4139.  
  4140.  
  4141.  
  4142.  
  4143.  
  4144.  
  4145.  
  4146.  
  4147.  
  4148.  
  4149.  
  4150.  
  4151.  
  4152.  
  4153.  
  4154.  
  4155.  
  4156.        AI Programming in SNOBOL4      - 149 -                    August, 1982
  4157.  
  4158.  
  4159.  
  4160.  
  4161.  
  4162.  
  4163.  
  4164.  
  4165.                                      APPENDIX G
  4166.  
  4167.             This is a compilation listing of a group of programs which were
  4168.           used in debugging SNOLISPIST.  They illustrate a few of the
  4169.           system's capabilities, as well as some LISPish programming
  4170.           techniques (e.g., mapping functions and EVALing expressions).
  4171.           The test program is designed to run interactively from a
  4172.           terminal.  The tests are largely self-documenting.
  4173.  
  4174.               *
  4175.               * To run this test program:
  4176.               *     a)  have copies of TEST, SNOLISP/LIB, and SNOLISP/CORE
  4177.               *         under your account;
  4178.               *     b)  type
  4179.               *         $RUN *SPITBOL SCARDS=SNOLISP/CORE+TEST PAR=SIZE=64
  4180.               *
  4181.               *
  4182.               * Tests of single-argument numerical functions
  4183.               *     SNOLISPIST
  4184.               *
  4185.           1    PAWS = *?( |'' |'Press ENTER to continue.'
  4186.               +     |'' IN()    |(COLLECT() ' bytes available' |'') |'' )
  4187.           2    DEXP('PAUSE() = EVAL(PAWS)')
  4188.               *
  4189.           3    ||''
  4190.           4    ?( |'Single-argument numerical functions' |'' )
  4191.           5    |'Incidentally uses MAPC, DEXP with LAMBDA, and EVALCODE'
  4192.           6    |''
  4193.           7    MAPC(DEXP('LAMBDA(EXPR) = '
  4194.               +          '|("     " EVALCODE( |EXPR))' ),
  4195.               +     'ABS(-15.9999)' ~
  4196.               +     'SIGN(0 - 4444.4444)' ~
  4197.               +     'ADD1(-1)' ~
  4198.               +     'SUB1(14456.9765)' ~
  4199.               +     'FLOAT(13 + 15 + 17)' ~
  4200.               +     'DFLOAT(17 - 15 - 13)' ~
  4201.               +     'FIX(P...I.)' ~
  4202.               +     'MINUS(LN...10.)' ~
  4203.               +     'ROUND(-8.5)' ~ NIL)
  4204.               *
  4205.           8    PAUSE()
  4206.               *
  4207.               *
  4208.               * Tests of binary numerical functions
  4209.               *     SNOLISPIST
  4210.               *
  4211.               *
  4212.           9    ||''
  4213.           10   |'Binary numerical functions'
  4214.           11   |''
  4215.           12   MAPC(DEXP('LAMBDA(EXPR) = '
  4216.               +          '|("    " EVALCODE( |EXPR))' ),
  4217.               +     'ADD(P...I.,LN...10.)' ~
  4218.               +     'SUB(P...I.,LN...10.)' ~
  4219.  
  4220.  
  4221.  
  4222.        AI Programming in SNOBOL4      - 150 -                    August, 1982
  4223.  
  4224.  
  4225.  
  4226.  
  4227.  
  4228.  
  4229.  
  4230.  
  4231.               +     'MULT(P...I.,LN...10.)' ~
  4232.               +     'DIV(P...I.,LN...10.)' ~
  4233.               +     'MAX(1,-1)' ~
  4234.               +     'MIN(1,-1)' ~
  4235.               +     'REMAINDER(-44444444.119)' ~ NIL)
  4236.               *
  4237.           13   PAUSE()
  4238.               *
  4239.               *
  4240.               * Tests of list-argument numerical functions
  4241.               *     SNOLISPIST
  4242.               *
  4243.           14   ||''
  4244.           15   |'List-argument numerical functions'
  4245.           16   |''
  4246.           17   |'Incidentally uses MAPCAR, LREVERSE, and READ'
  4247.           18   |''
  4248.           19   ARGUMENT.LIST =
  4249.               +     MAPCAR(.DFLOAT,
  4250.               +        LREVERSE(
  4251.               +             #'(1 1 2 -3 5 8 -13 21)' ))
  4252.           20   ?( |'Here is the argument list: ' |'' )
  4253.           21   |ARGUMENT.LIST
  4254.               *
  4255.           22   PAUSE()
  4256.               *
  4257.           23   MAPC(DEXP('LAMBDA(FUNCTION) = '
  4258.               +          '|("     " APPLY( |FUNCTION, ARGUMENT.LIST))' ),
  4259.               +     .PLUS ~
  4260.               +     .DIFFERENCE ~
  4261.               +     .TIMES ~
  4262.               +     .QUOTIENT ~
  4263.               +     NIL)
  4264.               *
  4265.           24   PAUSE()
  4266.               *
  4267.               *
  4268.               * Tests of extended numerical functions
  4269.               *     SNOLISPIST
  4270.               *
  4271.               *
  4272.           25   |''
  4273.           26   |'Extended numerical functions'
  4274.           27   |''
  4275.           28   ?( |'Testing FLOOR' |'' )
  4276.           29   AL = #'(-10.9 -7.9 -6.01 -0.00001 0.00001 6.01 7.9 10.9)'
  4277.           30   |'Argument list = '
  4278.           31   ?( I("     "   !AL) |'' )
  4279.           32   |MAPCAR(.FLOOR,AL)
  4280.               *
  4281.           33   PAUSE()
  4282.               *
  4283.           34   |''
  4284.           35   ?( |'Testing CEIL' |'' )
  4285.  
  4286.  
  4287.  
  4288.        AI Programming in SNOBOL4      - 151 -                    August, 1982
  4289.  
  4290.  
  4291.  
  4292.  
  4293.  
  4294.  
  4295.  
  4296.  
  4297.           36   |'Argument list = '
  4298.           37   ?( |("     "   !AL) |'' )
  4299.           38   |MAPCAR(.CEIL,AL)
  4300.               *
  4301.           39   PAUSE()
  4302.               *
  4303.           40   |''
  4304.           41   ?( |'Testing SQRT by inverse mapping' |'' )
  4305.           42   AL = #'(1 10 100 1000 10000 100000 1000000 10000000)'
  4306.           43   |'Argument list = '
  4307.           44   ?( |("     "   !AL) |'' )
  4308.           45   |MAPCAR(DEXP('LAMBDA(A) = ROUND(A * A)'),
  4309.               +     MAPCAR(.SQRT,AL))
  4310.               *
  4311.           46   PAUSE()
  4312.               *
  4313.           47   |''
  4314.           48   |'Testing trigonometric and inverse trigonometric functions'
  4315.           49   ?( |('     by inverse mapping') |'' )
  4316.           50   AL = #( '(0 10 20 30 40 50 60 70 80 90 100 120 '
  4317.               +     '130 140 150 160 170 180 190 200 210 220 230 240 '
  4318.               +     '250 260 270 280 290 300 310 320 330 340 350 360)' )
  4319.           51   |'Argument list = '
  4320.           52   ?( |("     "   !AL) |'' )
  4321.           53   ?( |'SIN and ASIN' |'' )
  4322.           54   |MAPCAR(.ROUND,
  4323.               +     MAPCAR(.DEG,
  4324.               +        MAPCAR(.ASIN,
  4325.               +             MAPCAR(.SIN,
  4326.               +                  MAPCAR(.RAD,AL)))))
  4327.               *
  4328.           55   PAUSE()
  4329.               *
  4330.           56   ?( |'COS and ACOS' |'' )
  4331.           57   |MAPCAR(.ROUND,
  4332.               +     MAPCAR(.DEG,
  4333.               +        MAPCAR(.ACOS,
  4334.               +             MAPCAR(.COS,
  4335.               +                  MAPCAR(.RAD,AL)))))
  4336.               *
  4337.           58   PAUSE()
  4338.               *
  4339.           59   ?( |'TAN and ATAN' |'' )
  4340.           60   |MAPCAR(.ROUND,
  4341.               +     MAPCAR(.DEG,
  4342.               +        MAPCAR(.ATAN,
  4343.               +             MAPCAR(.TAN,
  4344.               +                  MAPCAR(.RAD,AL)))))
  4345.               *
  4346.           61   PAUSE()
  4347.               *
  4348.           62   |''
  4349.           63   |'Logarithms to the base 2 of the first 30 powers of 2'
  4350.           64   |''
  4351.  
  4352.  
  4353.  
  4354.        AI Programming in SNOBOL4      - 152 -                    August, 1982
  4355.  
  4356.  
  4357.  
  4358.  
  4359.  
  4360.  
  4361.  
  4362.  
  4363.           65   I = 0 ; AL  = NIL  ; TWP = 1
  4364.           68  TWO.LOOP
  4365.           69        I = LT(I,30) I + 1      :F(TWO.LOOP.END)
  4366.           70        TWP = 2 * TWP
  4367.           71        AL = TWP ~ AL      :(TWO.LOOP)
  4368.           72  TWO.LOOP.END
  4369.           73        AL =  LREVERSE(AL)
  4370.               *
  4371.           74   |MAPCAR(DEXP('LAMBDA(Z) = ROUND(LOG(Z,2))'), AL)
  4372.               *
  4373.           75   PAUSE()
  4374.               *
  4375.           76   |''
  4376.           77   ?( |'The first 10 powers of e' |'' )
  4377.           78   |MAPCAR(DEXP('LAMBDA(Z) = RAISE(NAT...BASE.,Z)' ),
  4378.               +     #'(1 2 3 4 5 6 7 8 9 10)' )
  4379.               *
  4380.           79   PAUSE()
  4381.               *
  4382.           80   |''
  4383.           81   ?( |'The first 10 negative powers of e' |'' )
  4384.           82   |MAPCAR(DEXP('LAMBDA(X) = RAISE(NAT...BASE., -X)' ),
  4385.               +     #'(1 2 3 4 5 6 7 8 9 10)' )
  4386.               *
  4387.           83   PAUSE()
  4388.               *
  4389.               *
  4390.               * Test program for all compound CAR/CDR
  4391.               * functions in SNOLISPIST
  4392.               *
  4393.           84   MNMNM = #'(1 2 3 4)'
  4394.               *
  4395.               * Build a reasonably hairy list
  4396.               *
  4397.           85   LKLKL = #'((((\MNMNM) \MNMNM) \MNMNM) \MNMNM)'
  4398.           86   MNMNM = #'(\LKLKL \LKLKL \LKLKL \LKLKL)'
  4399.           87   LKLKL = LCOPY(MNMNM)
  4400.               *
  4401.           88   ||''
  4402.           89   |('LKLKL = ' !LKLKL)
  4403.           90   |''
  4404.           91   MAPC(DEXP('LAMBDA(S) = '
  4405.               +          '|EVAL( |(  "C" S "R(LKLKL)" ))' ),
  4406.               +     #('(A D AA AD DA DD '
  4407.               +       ' AAA AAD ADA DAA '
  4408.               +       ' ADD DAD DDA DDD '
  4409.               +       ' AAAA AAAD AADA ADAA DAAA '
  4410.               +       ' AADD ADAD DAAD ADDA DADA DDAA '
  4411.               +       ' ADDD DADD DDAD DDDA DDDD)' ))
  4412.               *
  4413.           92   PAUSE()
  4414.               *
  4415.               *
  4416.               * SNOLISPIST I/O test program
  4417.  
  4418.  
  4419.  
  4420.        AI Programming in SNOBOL4      - 153 -                    August, 1982
  4421.  
  4422.  
  4423.  
  4424.  
  4425.  
  4426.  
  4427.  
  4428.  
  4429.               *
  4430.           93       A = 'C' ; B = 'L' ; C = 'R'
  4431.               *
  4432.           96       (|(11 % 'C.A') |'Centered.' ||'')
  4433.           97       (|(11 % 'L.B') |'Left justified.'  ||'')
  4434.           98       (|(11 % 'R.C') |'Right justified.'  ||'')
  4435.           99    L = #'(A CENTERED LIST)'
  4436.               *
  4437.           100   (|(72 % 'C.L') |'A centered list.' ||'')
  4438.               *
  4439.           101  (|'Test of indentation via % operator.' |'')
  4440.           102  ?( |'Outline Level I' |'' )
  4441.           103  ?( |(5 % ' '   'Outline Level I.A') |'' )
  4442.           104  ?( |(10 % ' '   'Outline Level I.A.1') |'' )
  4443.           105  ?( |(15 % ' '   'Outline Level I.A.1.a') ||'' )
  4444.               *
  4445.           106  PAUSE()
  4446.               *
  4447.           107  |'Input test:   Should print echo of next input line.'
  4448.           108  |''
  4449.           109  |IN()
  4450.               *
  4451.           110  PAUSE()
  4452.               *
  4453.               *
  4454.               * Tests of recursively defined list processing functIons
  4455.               *   SNOLISPIST
  4456.               *
  4457.               *
  4458.           111  ||''
  4459.           112  |'Recursively defined list processing functions'
  4460.           113  |''
  4461.           114  ?( |'Test LCOPY' |'' )
  4462.           115  ORIGINAL = #'((O . R) (I . G) (I . N) (A . L))'
  4463.           116  COPY = LCOPY(ORIGINAL)
  4464.           117  |'Here is the original:'
  4465.           118  ?( |(62 % 'C.ORIGINAL') |'' )
  4466.           119  |'Here is the copy:'
  4467.           120  ?( |(62 % 'C.COPY') |'' )
  4468.           121  |'Are they EQU?'
  4469.           122  ?( |("     "   ~EQU(COPY,ORIGINAL) 'No.') |'' )
  4470.           123  |'Are they EQUAL?'
  4471.           124  ?( |("     "   EQUAL(COPY,ORIGINAL) 'Yes.') |'' )
  4472.               *
  4473.           125  PAUSE()
  4474.               *
  4475.           126  ?( |'Test SUBST' |'' )
  4476.           127  TEST.LIST = #'(1 (2) (3 . 4) ((5 . 6) 7) 1 2 3 4 5 6 7)'
  4477.           128  SUBST.LIST = #'(S I X)'
  4478.           129  |'Here is the original list:'
  4479.           130  ?( |(62 % 'C.TEST.LIST') |'' )
  4480.           131  ?( |'Here is the target sublist:  6' |'' )
  4481.           132  |'Here is the result:'
  4482.           133  ?( |(62 % 'C.SUBST(TEST.LIST,6,SUBST.LIST)' ) |'' )
  4483.  
  4484.  
  4485.  
  4486.        AI Programming in SNOBOL4      - 154 -                    August, 1982
  4487.  
  4488.  
  4489.  
  4490.  
  4491.  
  4492.  
  4493.  
  4494.  
  4495.               *
  4496.           134  PAUSE()
  4497.               *
  4498.           135  ?( |'Test REMOVE' |'' )
  4499.           136  TEST.LIST = #'(A (B (C . D) E (F . G)) H A I R)'
  4500.           137  REM.LIST = #'(C . D)'
  4501.           138  |'Here is the test list:'
  4502.           139  ?( |(62 % 'C.TEST.LIST') |'' )
  4503.           140  |'Here is the list to be removed:'
  4504.           141  ?( |(62 % 'C.REM.LIST') |'' )
  4505.           142  |'Here is the result:'
  4506.           143  ?( |(62 % 'C.REMOVE(TEST.LIST.REM.LIST)' ) |'' )
  4507.               *
  4508.           144  PAUSE()
  4509.               *
  4510.           145  ?( |'Test FIND' |'' )
  4511.           146  TEST.LIST = #'(H A Y ((N . E) (E . D) (L . E)) S T A C K)'
  4512.           147  FIND.LIST = #'(E . D)'
  4513.           148  |'Here is the test list:'
  4514.           149  ?( |(62 % 'C.TEST.LIST') |'' )
  4515.           150  |'Here is the list to be found:'
  4516.           151  ?( |(62 % 'C.FIND.LIST') |'' )
  4517.           152  |'Here is the result:'
  4518.           153  ?( |(62 % 'C.FIND(FIND.LIST,TEST.LIST)' ) |'' )
  4519.               *
  4520.           154  PAUSE()
  4521.               *
  4522.               * Tests of miscellaneous list processing functions
  4523.               *     SNOLISPIST
  4524.               *
  4525.           155  ||''
  4526.           156  |'Miscellaneous list processing functions'
  4527.           157  |''
  4528.           158  ?( |'Test EXPLODE and READLIST by inverse mapping' |'' )
  4529.           159  |MAPCAR(.READLIST,
  4530.               +     MAPCAR(.EXPLODE,
  4531.               +        #'(1 AARDVARK (SUB LIST) (C (O (MPLEX))))' ))
  4532.               *
  4533.           160  PAUSE()
  4534.               *
  4535.           161  |''
  4536.           162  ?( |'Test LENGTH' |'' )
  4537.           163  |MAPLIST(.LENGTH,
  4538.               +     EXPLODE('abcdefghijklmnopqrstuvwxyz'))
  4539.               *
  4540.           164  PAUSE()
  4541.               *
  4542.           165  |''
  4543.           166  |'Test SETL (SET indirectly)'
  4544.           167  |''
  4545.           168  DEFINE('PLACE(CH)A')    :(PLACE.END)
  4546.           169 PLACE
  4547.               +     &ALPHABET CH @A
  4548.           170       PLACE = A     :(RETURN)
  4549.  
  4550.  
  4551.  
  4552.        AI Programming in SNOBOL4      - 155 -                    August, 1982
  4553.  
  4554.  
  4555.  
  4556.  
  4557.  
  4558.  
  4559.  
  4560.  
  4561.           171 PLACE.END
  4562.               *
  4563.           172  DEFINE('INTERLEAVE(L1,L2)LL')      :(INTERLEAVE.END)
  4564.           173 INTERLEAVE
  4565.               +     LL = NIL
  4566.           174 INTERLEAVE1
  4567.               +     LL = POP( .L2) ~ POP( .L1) ~ LL
  4568.               +        :S(INTERLEAVE1)
  4569.           175       INTERLEAVE = LREVERSE(LL)    :(RETURN)
  4570.           176 INTERLEAVE.END
  4571.               *
  4572.           177       AA =  EXPLODE('abcdefghijklmnopqrstuvwxyz')
  4573.           178       VV =  MAPCAR(.PLACE,AA)
  4574.           179       SETL(INTERLEAVE(AA,VV))
  4575.           180       MAPC(DEXP('LAMBDA(Z) = '
  4576.               +          '?|(Z " = " VALUE(Z))' ),  AA)
  4577.               *
  4578.           181  PAUSE()
  4579.               *
  4580.               *
  4581.               *  Tests of set functions on lists
  4582.               *     SNOLISPIST
  4583.               *
  4584.               *
  4585.           182  ||''
  4586.           183  |'Set functions'
  4587.           184  |''
  4588.           185  EVEN  = #'(2 4 6 8 10 12 14 16 18 20)'
  4589.           186  ODD   = #'(1 3 5 7 9 11 13 15 17 19)'
  4590.           187  PRIME = #'(2 3 5 7 11 13 17 19)'
  4591.           188  FIBONACCI = #'(1 1 2 3 5 8 13)'
  4592.           189  UNIVERSE = UNION(EVEN,ODD)
  4593.           190  NON.PRIME = EXCLUDE(UNIVERSE,PRIME)
  4594.           191  EVEN.PRIME = INTERSECT(EVEN,PRIME)
  4595.           192  PRIME.FIBO = INTERSECT(PRIME,FIBONACCI)
  4596.           193  ODD.FIBO = INTERSECT(ODD,FIBONACCI)
  4597.           194  PRIME.OR.FIBO = UNION(PRIME,FIBONACCI)
  4598.           195  NEITHER.PRIME.NOR.FIBO = EXCLUDE(UNIVERSE,PRIME.OR.FIBO)
  4599.               *
  4600.           196  MAPC(DEXP('LAMBDA(NAME) = |$|( |"" NAME )' ),
  4601.               +     #( '(EVEN ODD PRIME FIBONACCI UNIVERSE NON.PRIME '
  4602.               +          'EVEN.PRIME PRIME.FIBO ODD.FIBO PRIME.OR.FIBO '
  4603.               +          'NEITHER.PRIME.NOR.FIBO)' ))
  4604.               *
  4605.           197  PAUSE()
  4606.               *
  4607.               *
  4608.               *  Tests of some functions for adding to a list
  4609.               *     SNOLISPIST
  4610.               *
  4611.               *
  4612.           198  ||''
  4613.           199  |'Functions which add elements to lists'
  4614.           200  |''
  4615.  
  4616.  
  4617.  
  4618.        AI Programming in SNOBOL4      - 156 -                    August, 1982
  4619.  
  4620.  
  4621.  
  4622.  
  4623.  
  4624.  
  4625.  
  4626.  
  4627.           201  LIST1 = EXPLODE('APPEND')
  4628.           202  LIST2 = EXPLODE('NCONC')
  4629.           203  LIST3 = EXPLODE('SNOC')
  4630.           204  LIST4 = EXPLODE('INSERT')
  4631.               *
  4632.           205  EXTRA.LIST = EXPLODE('EXTRA')
  4633.           206  EXTRA.ATOM = CONCAT(EXTRA.LIST)
  4634.               *
  4635.           207  ||''
  4636.           208  ?( |'Test APPEND' |'' )
  4637.           209  |(62 % 'C.APPEND(LIST1 ~ EXTRA.LIST ~ NIL)' )
  4638.               *
  4639.           210  PAUSE()
  4640.               *
  4641.           211  ?( |'Test NCONC' |'' )
  4642.           212  |(62 % 'C.NCONC(LIST2 ~ EXTRA.LIST ~ NIL)' )
  4643.               *
  4644.           213  PAUSE()
  4645.               *
  4646.           214  ?( |'Test SNOC' |'' )
  4647.           215  |(62 % 'C.SNOC(LIST3,EXTRA.ATOM)' )
  4648.               *
  4649.           216  PAUSE()
  4650.               *
  4651.           217  ?( |'Test INSERT' |'' )
  4652.           218  |(62 % 'C.INSERT("R",LIST4)'  )
  4653.           219  |''
  4654.           220  |(62 % 'C.INSERT(EXTRA.ATOM,LIST4)' )
  4655.               *
  4656.           221  PAUSE()
  4657.               *
  4658.               * Tests of replacement functions
  4659.               *     SNOLISPIST
  4660.               *
  4661.               *
  4662.           222  ||''
  4663.           223  |'Replacement functions'
  4664.           224  |''
  4665.           225  LST = READ(
  4666.               +     '(NOW IS THE TIME FOR ALL GOOD MEN '
  4667.               +     'TO COME TO THE AID OF THEIR PARTY)' )
  4668.           226  |''
  4669.           227  |'The test list is'
  4670.           228  ?( |(62 % 'C.LST') |'' )
  4671.               *
  4672.           229  PAUSE()
  4673.               *
  4674.           230  ?( |'Reverse the CDR' |'' )
  4675.           231  RPLACD(LST,LREVERSE(CDR(LST)))
  4676.           232  ?( |(62 % 'C.LST') |'' )
  4677.               *
  4678.           233  PAUSE()
  4679.               *
  4680.           234  ?( |'Put it back like it was' |'' )
  4681.  
  4682.  
  4683.  
  4684.        AI Programming in SNOBOL4      - 157 -                    August, 1982
  4685.  
  4686.  
  4687.  
  4688.  
  4689.  
  4690.  
  4691.  
  4692.  
  4693.           235  RPLACD(LST,LREVERSE(CDR(LST)))
  4694.           236  ?( |(62 % 'C.LST') |'' )
  4695.               *
  4696.           237  PAUSE()
  4697.               *
  4698.           238  ?( |'Use RPLACA to change the first five words' |'' )
  4699.           239  RPLACA(LST,'Now')
  4700.           240  RPLACA(CDR(LST),'is')
  4701.           241  RPLACA(CDDR(LST),'the')
  4702.           242  RPLACA(CDDDR(LST),'time')
  4703.           243  RPLACA(CDDDDR(LST),'for')
  4704.           244  ?( |(62 % 'C.LST') |'' )
  4705.               *
  4706.           245  PAUSE()
  4707.               *
  4708.           246  ?( |'Change the last five words using RPLACN' |'' )
  4709.           247  RPLACN(LST,-1,'party?')
  4710.           248  RPLACN(LST,-2,'their')
  4711.           249  RPLACN(LST,-3,'of')
  4712.           250  RPLACN(LST,-4,'aid')
  4713.           251  RPLACN(LST,-5,'the')
  4714.           252  ?( |(62 % 'C.LST') |'' )
  4715.               *
  4716.           253  PAUSE()
  4717.               *
  4718.           254  |'Restore the original list; then reverse each '
  4719.           255  ?( I("     "   'word, starting with the last.') |'' )
  4720.           256  LST = READ(
  4721.               +     '(NOW IS THE TIME FOR ALL GOOD MEN '
  4722.               +     'TO COME TO THE AID OF THEIR PARTY)' )
  4723.           257  |''
  4724.           258  |'The test list is'
  4725.           259  ?( |(62 % 'C.LST') |'' )
  4726.               *
  4727.           260  PAUSE()
  4728.               *
  4729.           261        N = LENGTH(LST)
  4730.           262        I = 0
  4731.           263 LUPE
  4732.           264        I = LT(I,N) I + 1       :F(LUPE.END)
  4733.           265        K = -I
  4734.           266        RPLACN(LST,K,REVERSE(CAR(NTH(LST,K))))
  4735.           267        PRINT(LST)         :(LUPE)
  4736.           268 LUPE.END
  4737.               +     PAUSE()
  4738.               *
  4739.               *
  4740.               * Tests of sublist functions
  4741.               *     SNOLISPIST
  4742.               *
  4743.               *
  4744.           269  ||''
  4745.           270  |'Sublist functions'
  4746.           271  |''
  4747.  
  4748.  
  4749.  
  4750.        AI Programming in SNOBOL4      - 158 -                    August, 1982
  4751.  
  4752.  
  4753.  
  4754.  
  4755.  
  4756.  
  4757.  
  4758.  
  4759.           272  LST = READ(
  4760.               +     '(NEVER TRY TO GIVE NECESSARY AND SUFFICIENT '
  4761.               +     'CONDITIONS FOR ANYTHING -- Linsky)' )
  4762.           273  |''
  4763.           274  |'The test list is'
  4764.           275  PRINT(LST)
  4765.           276  PAUSE()
  4766.               *
  4767.           277  |'The last element is'
  4768.           278  PRINT(LAST(LST))
  4769.               *
  4770.           279   PAUSE()
  4771.               *
  4772.           280  ?( |'Here is a vertical listing, using NTH' |'' )
  4773.           281       N = LENGTH(LST)
  4774.           282       I = 0
  4775.           283 LOOP
  4776.               +     I = LT(I,N) I + 1       :F(LOOP.END)
  4777.           284       PRINT(CAR(NTH(LST,I)))       :(LOOP)
  4778.           285 LOOP.END      PAUSE()
  4779.               *
  4780.           286  |''
  4781.           287  |'The first 8 elements are'
  4782.           288  PRINT(PRELIST(LST,8))
  4783.           289  PAUSE()
  4784.               *
  4785.           290  |'The tail starting with element 4 is'
  4786.           291  PRINT(SUFLIST(LST,3))
  4787.           292  PAUSE()
  4788.               *
  4789.           293  |'The sublist consisting of elements 4 through 8 is'
  4790.           294  PRINT(PRELIST(SUFLIST(LST,3),5))
  4791.           295  PAUSE()
  4792.               *
  4793.           296  |'The RAC is'
  4794.           297  PRINT(RAC(LST))
  4795.           298  |'The RDC is'
  4796.           299  PRINT(RDC(LST))
  4797.           300  PAUSE()
  4798.               *
  4799.               *
  4800.               * Tests of list searching functions
  4801.               *      SNOLISPIST
  4802.               *
  4803.               *
  4804.           301  ||''
  4805.           302  |'Searching functions'
  4806.           303  |''
  4807.           304  ALIST = READ(
  4808.               +      '((1 BUN) '
  4809.               +      '(2 SHOE) '
  4810.               +      '(3 TREE) '
  4811.               +      '(4 DOOR BORE SHORE CORE) '
  4812.               +      '(5 HIVE JIVE) '
  4813.  
  4814.  
  4815.  
  4816.        AI Programming in SNOBOL4      - 159 -                    August, 1982
  4817.  
  4818.  
  4819.  
  4820.  
  4821.  
  4822.  
  4823.  
  4824.  
  4825.               +      '(6 SEX) '
  4826.               +      '(7 HEAVEN) '
  4827.               +      '(8 WAIT) '
  4828.               +      '(9 RESIGN) '
  4829.               +      '(10 WHEN?) )' )
  4830.               *
  4831.           305  |'The test list is'
  4832.           306  PRINT(ALIST)
  4833.           307  PAUSE()
  4834.               *
  4835.           308  ?( |'NIL followed-by beat poetry' |'' )
  4836.           309  PRINT(ASSOC(95,ALIST))
  4837.           310  PRINT(ASSOC(6,ALIST))
  4838.           311  PRINT(ASSOC(9,ALIST))
  4839.           312  PRINT(ASSOC(5,ALIST))
  4840.           313  PRINT(ASSOC(10,ALIST))
  4841.               *
  4842.           314  PAUSE()
  4843.               *
  4844.           315  MESS = #'(47 ABC XYZ BUN WAIT 5 7 1 3)'
  4845.           316  |''
  4846.           317  |'The list of targets for ASSOCL is'
  4847.           318  |''
  4848.           319  |'LTRACE is also tested here.'
  4849.           320  |''
  4850.           321  PRINT(MESS)
  4851.           322  PAUSE()
  4852.               *
  4853.           323  LTRACE(3, .ASSOCL ~ NIL) ; &TRACE = 10000
  4854.           325  PRINT(ASSOCL(MESS,ALIST))
  4855.           326  LTRACE(0, .ASSOCL ~ NIL) ; &TRACE = 0
  4856.           328  PAUSE()
  4857.               *
  4858.           329  |'Here is the tail of MESS starting with BUN'
  4859.           330  PRINT(MEMBER('BUN',MESS))
  4860.           331  PAUSE()
  4861.               *
  4862.           332  MEMQ('WAIT',MESS) ?|'This line should appear'
  4863.           333  MEMQ('INCLINE',ALIST) ?|'This line should NOT appear'
  4864.               *
  4865.           334  PAUSE()
  4866.               *
  4867.               * Tests of mapping functions
  4868.               *     SNOLISPIST
  4869.               *
  4870.               *
  4871.           335  ||''
  4872.           336  |'Mapping functions'
  4873.           337  |''
  4874.           338  ?( |'Unimaginative MAP test' |'' )
  4875.           339  MAP(.PRINT,#'(A B C D 11 22 33 44 (5 . 5))' )
  4876.               *
  4877.           340  PAUSE()
  4878.               *
  4879.  
  4880.  
  4881.  
  4882.        AI Programming in SNOBOL4      - 160 -                    August, 1982
  4883.  
  4884.  
  4885.  
  4886.  
  4887.  
  4888.  
  4889.  
  4890.  
  4891.           341  ?( |'Unimaginative MAPC test' |'' )
  4892.           342  MAPC(.PRINT,
  4893.               +     READ(
  4894.               +         '(Now is the time for all good men '
  4895.               +         'to come to the aid of their party)' ))
  4896.               *
  4897.           343  PAUSE()
  4898.               *
  4899.           344  ?( |'Unimaginative MAPLIST test' |'' )
  4900.           345  PRINT(MAPLIST(.LENGTH,
  4901.               +     #'(10 9 8 7 6 5 4 pi 3 e 2 1 0 BLAST OFF!    i)' ))
  4902.               *
  4903.           346  PAUSE()
  4904.               *
  4905.           347  ?( |'MAPCON test -- What will happen???' |'' )
  4906.           348  PRINT(MAPCON(.EXPLODE,
  4907.               +     #'(EVERY GOOD BOY DOES FINE)' ))
  4908.               *
  4909.           349  PAUSE()
  4910.               *
  4911.           350  ?( |'MAPCAN test -- What wlll happen?????' |'' )
  4912.           351  PRINT(MAPCAN(.EXPLODE,
  4913.               +     #'(CINNAMON PERSIMMON SIMIAN)' ))
  4914.           352  PAUSE()
  4915.               *
  4916.           353  |'EVERY test (correct answer = NIL)'
  4917.           354  PRINT(EVERY(.NUMBERP,
  4918.               +     #'(5 4 3 2 1 0 X)' ))
  4919.               *
  4920.           355  PAUSE()
  4921.               *
  4922.           356  |'EVLIS test'
  4923.           357  |'Correct answer is (1 2 3 (LIST VALUE))'
  4924.           358  SETL( #'(A 1 B 2 C 3 D (LIST VALUE))' )
  4925.           359  PRINT(EVLIS(#'(A B C D)' ))
  4926.               *
  4927.           360  PAUSE()
  4928.               *
  4929.           361  |'SOME test (correct answer = NIL)'
  4930.           362  PRINT(SOME(.ZEROP,
  4931.               +     #'(19 9 8 3 6 4 2 \P...I. \LN...10. 66 666 -1)' ))
  4932.               *
  4933.           363  PAUSE()
  4934.               *
  4935.           364  |'SUBSET test (should print only negative numbers)'
  4936.           365  PRINT(SUBSET(.NEGP,
  4937.               +     #'(0 0 0 -1 -2 9 8 6.3 \-P...I. \LN...10. -5)' ))
  4938.               *
  4939.           366  PAUSE()
  4940.               *
  4941.               *
  4942.               * Tests of non-numerical Predicates
  4943.               *     SNOLISPIST
  4944.               *
  4945.  
  4946.  
  4947.  
  4948.        AI Programming in SNOBOL4      - 161 -                    August, 1982
  4949.  
  4950.  
  4951.  
  4952.  
  4953.  
  4954.  
  4955.  
  4956.  
  4957.           367       LLST = #'(A (SMALL (TEST (LIST))))'
  4958.           368  ||''
  4959.           369  |'A series of Ts'
  4960.           370  |''
  4961.           371  MAPC(DEXP('LAMBDA(EXPR) = |("      " !EVALCODE( |EXPR))' ),
  4962.               +     '/T' ~
  4963.               +     'NULLP(NIL)' ~
  4964.               +     'NOTP(NIL)' ~
  4965.               +     'ATOMP(13.965)' ~
  4966.               +     'NUMBERP(-13.965)' ~
  4967.               +     'EQP(13,"13.000000")' ~
  4968.               +     'EQUALP(LLST,LCOPY(LLST))' ~
  4969.               +     NIL)
  4970.               *
  4971.           372  PAUSE()
  4972.               *
  4973.           373  ||''
  4974.           374  |'A series of NILs'
  4975.           375  |''
  4976.           376  LLST = #'(TWEEDLE (DEE . DUM))'
  4977.           377  MAPC(DEXP('LAMBDA(EXPR) = |("    " !EVALCOOE( |EXPR))' ),
  4978.               +    'NULLP(14 ~ NIL)' ~
  4979.               +    'NOTP(1 ~ 1)' ~
  4980.               +    'ATOMP(1 ~ 2 ~ 3 ~ NIL)' ~
  4981.               +    'NUMBERP("LINDA")' ~
  4982.               +    'EQP(LLST,LCOPY(LLST))' ~
  4983.               +    NIL)
  4984.               *
  4985.           378  PAUSE()
  4986.               *
  4987.               *
  4988.               * Tests of numerical predicates
  4989.               *    SNOLISPIST
  4990.               *
  4991.               *
  4992.           379  ||''
  4993.           380  |'Alternating series of Ts and NILs'
  4994.           381  |''
  4995.           382  ?( |'Testing NEGP' |'' )
  4996.           383  |MAPCAR(.NEGP,
  4997.               +    #'(-1 2 -3.0 4 -5.00 6.00 -7.7 8.8 -8.999 10.101010)')
  4998.               *
  4999.           384  PAUSE()
  5000.               *
  5001.           385  ?( |'Testing ZEROP' |'' )
  5002.           386  |MAPCAR(.ZEROP,
  5003.               +    #'(0 14 0. -41 0.0 29 -0.0 2.99 00000 99999)')
  5004.               *
  5005.           387  PAUSE()
  5006.               *
  5007.           388  ?( |'Testing LESSP' |'' )
  5008.           389  |LESSP( #'( \-P...I. 0.00 0.01 10000000)' )
  5009.           390  |LESSP( #'( \-LN...10. 0.00 1.01 1.000000)' )
  5010.               *
  5011.  
  5012.  
  5013.  
  5014.        AI Programming in SNOBOL4      - 162 -                    August, 1982
  5015.  
  5016.  
  5017.  
  5018.  
  5019.  
  5020.  
  5021.  
  5022.  
  5023.           391  PAUSE()
  5024.               *
  5025.           392  |'Testing GREATERP.'
  5026.           393  |''
  5027.           394  |GREATERP( #'( \P...I. 3.1 -4  -19.84)' )
  5028.           395  |GREATERP( #'( 6 16 7 17    14.82   )' )
  5029.               *
  5030.           396  PAUSE()
  5031.               *
  5032.               *
  5033.               * Tests of the property-list functions
  5034.               *    SNOLISPIST
  5035.               *
  5036.               *
  5037.           397  ||''
  5038.           398  |'Property list functions'
  5039.           399  |''
  5040.               *
  5041.               *
  5042.           400  MAPC(DEXP('LAMBDA(XPR) = '
  5043.               +     '|("      " !EVAL( |( |"" XPR )))' ),
  5044.               +     'PUT(.DOG,"NUMBER.OF.LEGS",4)' ~
  5045.               +     'GET(.DOG,"NUMBER.OF.LEGS")' ~ 'PAUSE()' ~
  5046.               +     'REMPROP(.DOG,"NUMBER.OF.LEGS")' ~
  5047.               +     'GET(.DOG,"NUMBER.OF.LEGS")' ~ 'PAUSE()' ~
  5048.               +     'PUTL(#"(DOG CAT HORSE)","NUMBER.OF.LEGS",4)' ~
  5049.               +     'GET(.DOG,"NUMBER.OF.LEGS")' ~
  5050.               +     'GET(.CAT,"NUMBER.OF.LEGS")' ~
  5051.               +     'GET(.HORSE,"NUMBER.OF.LEGS")' ~
  5052.               +     'GET(.ARMADILLO,"NUMBER.OF.LEGS")' ~ 'PAUSE()' ~
  5053.               +     'PUTPROP(.DOG,3,"LEGS")' ~
  5054.               +     'PUTPROP(.DOG,2,"LEGS")' ~
  5055.               +     'PUTPROP(.DOG,1,"LEGS")' ~
  5056.               +     'PUTPROP(.DOG,1,"HEAD")' ~
  5057.               +     'GETL(.DOG,#"(LEGS HEAD)")' ~
  5058.               +     'GETL(.DOG,#"(HEAD)")' ~ 'PAUSE()' ~
  5059.               +     'ADDPROP(.DOG,3,"LEGS")' ~
  5060.               +     'GET(.DOG,"LEGS")' ~
  5061.               +     'ADDPROP(.DOG,"ANOMALY","LEGS")' ~
  5062.               +     'GET(.DOG,"LEGS")' ~ 'PAUSE()' ~
  5063.               +     'DEFPROP(.FISH,0,"LEGS")' ~
  5064.               +     'GETL(.FISH,#"(EYES ARMS TEETH LEGS)")' ~
  5065.               +     NIL )
  5066.               *
  5067.           401  PAUSE()
  5068.               *
  5069.               *
  5070.           402  |''
  5071.           403  ?( |'Empty all property stacks' |'' )
  5072.           404  ?( |'DOG -- "LEGS"' |'' )
  5073.               *
  5074.           405 LOOP1 TEMP = GETPROP( .DOG, 'LEGS' )
  5075.           406       ?( PRINT(TEMP) DIFFER(TEMP,NIL) )     :S(LOOP1)
  5076.           407  |''
  5077.  
  5078.  
  5079.  
  5080.        AI Programming in SNOBOL4      - 163 -                    August, 1982
  5081.  
  5082.  
  5083.  
  5084.  
  5085.  
  5086.  
  5087.  
  5088.  
  5089.           408  PAUSE()
  5090.           409  ?( |'DOG -- "NUMBER.OF.LEGS"' |'' )
  5091.           410 LOOP2   TEMP = GETPROP( .DOG, 'NUMBER.OF.LEGS' )
  5092.           411         ?( PRINT(TEMP) DIFFER(TEMP,NIL) )     :S(LOOP2)
  5093.           412  |''
  5094.           413  PAUSE()
  5095.           414  ?( |'DOG -- "HEAD"' |'' )
  5096.           415 LOOP3   TEMP = GETPROP( .DOG, 'HEAD' )
  5097.           416         ?( PRINT(TEMP) DIFFER(TEMP,NIL) )       :S(LOOP3)
  5098.           417  |''
  5099.           418  PAUSE()
  5100.           419  |'CAT -- "NUMBER.OF.LEGS"'
  5101.           420 LOOP4   TEMP = GETPROP( .CAT, 'NUMBER.OF.LEGS' )
  5102.           421         ?( PRINT(TEMP) DIFFER(TEMP,NIL) )     :S(LOOP4)
  5103.           422  |''
  5104.           423  PAUSE()
  5105.           424  ?( |'FISH -- "LEGS"' |'' )
  5106.           425 LOOP5 TEMP = GETPROP( .FISH, 'LEGS' )
  5107.           426       ?( PRINT(TEMP) DIFFER(TEMP,NIL) )      :S(LOOP5)
  5108.           427  |''
  5109.           428  PAUSE()
  5110.           429  ?( |'HORSE -- "NUMBER.OF.LEGS"' |''   )
  5111.           430 LOOP6 TEMP = GETPROP( .HORSE, 'NUMBER.OF.LEGS' )
  5112.           431       ?( PRINT(TEMP) DIFFER(TEMP,NIL) )      :S(LOOP6)
  5113.               *
  5114.           432  PAUSE()
  5115.               *
  5116.           433  ||''
  5117.           434  ?( |'A combined test of CLA, CAL, and SORT' |'' )
  5118.           435  ?( |'Should print ABDENWSSREBA' |'' )
  5119.           436  L = CLA(EXPLODE('BADNEWSBEARS'))
  5120.           437  SORT(L,7,12,'LGE')
  5121.           438  SORT(L,1,6,'LLE')
  5122.           439  |READLIST(CAL(L))
  5123.               *
  5124.           440  PAUSE()
  5125.               *
  5126.           441  ||''
  5127.           442  |'A further test of SORT/CAL/CLA:'
  5128.           443  |'Make anagrams out of some six-letter names by'
  5129.           444  |'alphabetizing their letters.'
  5130.           445  |''
  5131.           446  MAPC(
  5132.               + DEXP(
  5133.               +   'LAMBDA(X) = '
  5134.               +    'PRINT('
  5135.               +     'CONCAT('
  5136.               +      'CAL('
  5137.               +       'SORT(CLA(EXPLODE(X)),1,6,.LLE) )))' ),
  5138.               +         ('MARVIN' ~
  5139.               +         'PACMAN' ~
  5140.               +         'LOLITA' ~
  5141.               +         'MERLIN' ~
  5142.               +         'ELIJAH' ~
  5143.  
  5144.  
  5145.  
  5146.        AI Programming in SNOBOL4      - 164 -                    August, 1982
  5147.  
  5148.  
  5149.  
  5150.  
  5151.  
  5152.  
  5153.  
  5154.  
  5155.               +         'SHAFTO' ~
  5156.               +         'SYLVIA' ~
  5157.               +         'ITALIA' ~
  5158.               +         'GEORGE' ~
  5159.               +         'GIMPEL' ~
  5160.               +         'BACKUS' ~ NIL) )
  5161.               *
  5162.           447  PAUSE()
  5163.               *
  5164.           448  ||''
  5165.           449  |'TDUMP test:  Should print suitable error message.'
  5166.           450  |''
  5167.           451  |(72 % 'C.a=b+c?')
  5168.           452 END
  5169.  
  5170.  
  5171.  
  5172.  
  5173.  
  5174.  
  5175.  
  5176.  
  5177.  
  5178.  
  5179.  
  5180.  
  5181.  
  5182.  
  5183.  
  5184.  
  5185.  
  5186.  
  5187.  
  5188.  
  5189.  
  5190.  
  5191.  
  5192.  
  5193.  
  5194.  
  5195.  
  5196.  
  5197.  
  5198.  
  5199.  
  5200.  
  5201.  
  5202.  
  5203.  
  5204.  
  5205.  
  5206.  
  5207.  
  5208.  
  5209.  
  5210.  
  5211.  
  5212.        AI Programming in SNOBOL4      - 165 -                    August, 1982
  5213.  
  5214.  
  5215.  
  5216.  
  5217.  
  5218.  
  5219.  
  5220.  
  5221.                                      APPENDIX H
  5222.  
  5223.             This is a compilation listing of a version of Bertram Raphael's
  5224.           SIR (Semantic Information Retrieve) program.  This version of the
  5225.           program is an almost literal SNOBOL4 translation of Shapiro's
  5226.           (1979, pp. 123-138) LISP version.  This SNOBOL4 version has been
  5227.           tested on Shapiro's (138-140) test dialogue.
  5228.  
  5229.               * This version of Bertram Raphael's SIR program
  5230.               * was translated into SNOBOL4 using the SNOLISPIST
  5231.               * list processing routines.
  5232.               *
  5233.               * This program follows closely the LISP version by
  5234.               * S. Shapiro (Techniques of Artificial Intelligence,
  5235.               * 1979, pp. 123-140.
  5236.               *
  5237.               * To run the program:
  5238.               *   a) have copies of SIR, SNOLISP/CORE, and SNOLISP/LIB
  5239.               *      under your account:
  5240.               *   b) type $RUN *SPITBOL SCARDS=SNOLISP/CORE+SIR PAR=SIZE=64
  5241.               *
  5242.               *
  5243.           1    DEFINE('SIR()S')    :(SIR.END)
  5244.           2   SIR   S = GET.SENTENCE()      :F(FRETURN)
  5245.           3         SIR = EQU(CAR(S),"BYE") "GOOD-BYE"     :S(RETURN)
  5246.           4         PROCESS(S)    :S(SIR)F(FRETURN)
  5247.           5   SIR.END
  5248.               *
  5249.           6    DEFINE('GET.SENTENCE()S,P')       :(GET.SENTENCE.END)
  5250.           7   GET.SENTENCE   S = S " " IN()          :F(FRETURN)
  5251.           8        S RPOS(1) ANY("!?") . P = " " P
  5252.               +         :F(GET.SENTENCE)
  5253.           9    GET.SENTENCE = READ( "(" S ")" )      :S(RETURN)F(FRETURN)
  5254.           10  GET.SENTENCE.END
  5255.               *
  5256.           11   DEXP('PROCESS(SENTENCE) = PROCESS.1(SENTENCE,RULE.LIST)')
  5257.               *
  5258.           12   DEFINE('PROCESS.1(SENTENCE,RULES)RESP,CA')
  5259.               +         :(PROCESS.1.END)
  5260.           13  PROCESS.1      CA = POP( .RULES)   :F(PROCESS.1.ERR)
  5261.           14       RESP = APPLY.RULE(CA,SENTENCE)
  5262.           15       IDENT(RESP,NIL)    :S(PROCESS.1)
  5263.           16       PROCESS.1 = |RESP       :(RETURN)
  5264.           17  PROCESS.1.ERR
  5265.               +     |"STATEMENT FORM NOT RECOGNIZED."
  5266.           18        |"   IN PROCESS.1, "
  5267.           19        |("    SENTENCE = " CONCAT(SENTENCE," "))     :(RETURN)
  5268.           20  PROCESS.1.END
  5269.               *
  5270.           21   DATA('RULE(PATTERN,VARIABLES,TESTS,ACTION)')
  5271.               *
  5272.           22   DEFINE('APPLY.RULE(RULE,INP)')   :(APPLY.RULE.END)
  5273.           23  APPLY.RULE     APPLY.RULE = NIL
  5274.  
  5275.  
  5276.  
  5277.  
  5278.        AI Programming in SNOBOL4      - 166 -                    August, 1982
  5279.  
  5280.  
  5281.  
  5282.  
  5283.  
  5284.  
  5285.  
  5286.  
  5287.           24        APPLY.RULE =
  5288.               +        DIFFER(NIL,MATCH(INP,PATTERN(RULE),VARIABLES(RULE)))
  5289.               +        APPLY.RULE.1(
  5290.               +            APPLY.TESTS(TESTS(RULE),EVLIS(VARIABLES(RULE))),
  5291.               +            ACTION(RULE))       :(RETURN)
  5292.           25  APPLY.RULE.END
  5293.               *
  5294.           26   DEFINE('MATCH(INP,PAT,VARS)')     :(MATCH.END)
  5295.           27  MATCH     ATOM(PAT)      :S(MATCH.A)
  5296.           28        INITIALIZE(VARS)
  5297.           29        MATCH.FLAG = MATCH1(INP,PAT,VARS)
  5298.           30  MATCH.A  MATCH = MATCH.FLAG   :(RETURN)
  5299.           31  MATCH.END
  5300.               *
  5301.           32   DEXP('INITIALIZE(LVARS) = MAPC( .'
  5302.               + DEXP('LAMBDA(LAMBDA...V) = SET(LAMBDA...V,NIL)')
  5303.               +     ',LVARS)')
  5304.               *
  5305.           33   DEFINE('MATCH1(INP,PAT,VARS)CA')    :(MATCH1.END)
  5306.           34  MATCH1  MATCH1 = NULL(INP) NULLP(PAT)       :S(RETURN)
  5307.           35        MATCH1 = NULL(PAT) NIL       :S(RETURN)
  5308.           36        CA = CAR(PAT)
  5309.           37        MEMQ(CA,VARS)     :F(MATCH1A)
  5310.           38           MATCH1 = NULL( CDR(PAT))
  5311.               +             SET(CA,APPEND($CA ~ INP ~ NIL))
  5312.               +             :S(RETURN)
  5313.           39           MATCH1 = EQU(CAR(INP),CADR(PAT))
  5314.               +             MATCH1(CDR(INP),CDDR(PAT),VARS)
  5315.               +             :S(RETURN)
  5316.           40           MATCH1 = DIFFER(NIL,SET(CA,SNOC($CA,CAR(INP))))
  5317.               +             MATCH1(CDR(INP),PAT,VARS)     :(RETURN)
  5318.           41  MATCH1A  MATCH1 = EQU(CAR(INP),CA)
  5319.               +             MATCH1(CDR(INP),CDR(PAT),VARS)
  5320.               +             :S(RETURN)
  5321.           42           MATCH1 = NIL       :(RETURN)
  5322.           43  MATCH1.END
  5323.               *
  5324.           44   DEFINE('APPLY.TESTS(TESTS,PHRASES)L')     :(APPLY.TESTS.END)
  5325.           45  APPLY.TESTS    APPLY.TESTS = NIL
  5326.           46        L = NIL
  5327.           47  APPLY.TESTS1 L = DIFFER(NIL,PHRASES) DIFFER(NIL,TESTS)
  5328.               +        APPLY(CAR(TESTS),CAR(PHRASES)) ~ L       :F(RETURN)
  5329.           48        DIFFER(NIL,CAR(L))  ?POP( .TESTS)  ?POP( .PHRASES)
  5330.               +                 :F(RETURN)
  5331.           49        APPLY.TESTS = NULL(TESTS) NULL(PHRASES)
  5332.               +        LREVERSE(L)      :S(RETURN)F(APPLY.TESTS1)
  5333.           50  APPLY.TESTS.END
  5334.               *
  5335.           51   DEFINE('APPLY.RULE.1(L,ACT)XPR')       :(APPLY.RULE.1.END)
  5336.           52  APPLY.RULE.1
  5337.               +     APPLY.RULE.1 = NULL(L)  NIL  :S(RETURN)
  5338.           53        XPR =
  5339.               +        CAR(ACT) '('
  5340.               +        CONCAT( RMAPCAR( L, CDR(ACT)), ',', '"') ')'
  5341.  
  5342.  
  5343.  
  5344.        AI Programming in SNOBOL4      - 167 -                    August, 1982
  5345.  
  5346.  
  5347.  
  5348.  
  5349.  
  5350.  
  5351.  
  5352.  
  5353.           54        APPLY.RULE.1 = EVALCODE(XPR)      :(RETURN)
  5354.           55  APPLY.RULE.1.END
  5355.               *
  5356.           56   DEFINE('RMAPCAR(S,LF)F')    :(RMAPCAR.END)
  5357.           57  RMAPCAR  RMAPCAR = NIL
  5358.           58  RMAPCAR1      F = POP( .LF)       :F(RMAPCAR2)
  5359.           59        RMAPCAR = APPLY(F,S) ~ RMAPCAR        :(RMAPCAR1)
  5360.           60  RMAPCAR2      RMAPCAR = LREVERSE(RMAPCAR)   :(RETURN)
  5361.           61  RMAPCAR.END
  5362.               *
  5363.           62   DEFINE('ADDXRY(X,REL,Y)')    :(ADDXRY.END)
  5364.           63  ADDXRY   ADDXRY = MEMQ(Y,GET(X,REL)) NIL    :S(RETURN)
  5365.           64        ADDXRY = PUTPROP(X,Y,REL)    :(RETURN)
  5366.           65  ADDXRY.END   OPSYN( .ADDYRX, .ADDXRY)
  5367.           66   DEXP('PATH(PATH...X,PATH...R,PATH...Y) = '
  5368.               +     'MEMQ( $PATH...Y,'
  5369.               +     'PATH1( $PATH...X ~ NIL, PATH...R))')
  5370.               *
  5371.           67   DEFINE('PATH1(LN,LR)')     :(PATH1.END)
  5372.           68  PATH1    DIFFER(NIL,LN)  DIFFER(NIL,LR)      :F(PATH1C)
  5373.           69        DIFFER(NIL,CDR(LR)) MEMQ(CADR(LR),"*" ~ "+" ~ NIL)
  5374.               +             :F(PATH1A)
  5375.           70         LN = EXTENDM(CADR(LR),LN,CAR(LR))
  5376.           71         LR = CDR(LR)       :(PATH1B)
  5377.           72  PATH1A    LN = EXTEND(LN,CAR(LR))
  5378.           73  PATH1B    LR = CDR(LR)    :(PATH1)
  5379.           74  PATH1C    PATH1 = LN      :(RETURN)
  5380.           75  PATH1.END
  5381.               *
  5382.           76   DEFINE('EXTENDM(OP,LN,R)')   :(EXTENDM.END)
  5383.           77  EXTENDM  LN = IDENT(OP,"+") EXTEND(LN,R)
  5384.           78        EXTENDM = LN
  5385.           79  EXTENDM1      DIFFER(NIL,LN) :F(RETURN)
  5386.           80        LN = COMPLEMENT(EXTEND(LN,R),EXTENDM)
  5387.           81        EXTENDM = APPEND(EXTENDM ~ LN ~ NIL)  :(EXTENDM1)
  5388.           82  EXTENDM.END
  5389.               *
  5390.           83   DEFINE('EXTEND(LN,R)')       :(EXTEND.END)
  5391.           84  EXTEND   EXTEND = NULL(LN) NIL    :S(RETURN)
  5392.           85        EXTEND = ~ATOM(R) PATH1(LN,R)     :S(RETURN)
  5393.           86        EXTEND = UNION(GET(CAR(LN),R),
  5394.               +        EXTEND(CDR(LN),R))   :(RETURN)
  5395.           87  EXTEND.END
  5396.               *
  5397.           88   OPSYN( .COMPLEMENT, .EXCLUDE)
  5398.               *
  5399.           89   G.DETS = READ( "(EACH EVERY ANY A AN)" )
  5400.           90   S.DETS = READ( "(THE)" )
  5401.               *
  5402.           91   DEXP('UNIQUE(NP) = NIL ; UNIQUE = '
  5403.               +     'NULL(CDR(NP)) CAR(NP) ; ')
  5404.               *
  5405.           92   DEXP('GENERIC(NP) = NIL ; GENERIC = '
  5406.               +     'MEMQ(CAR(NP),G.DETS) RAC(NP) ; ')
  5407.  
  5408.  
  5409.  
  5410.        AI Programming in SNOBOL4      - 168 -                    August, 1982
  5411.  
  5412.  
  5413.  
  5414.  
  5415.  
  5416.  
  5417.  
  5418.  
  5419.               *
  5420.           93   DEXP('SPECIFIC(NP) = NIL ; SPECIFIC = '
  5421.               +     'MEMQ(CAR(NP),S.DETS) RAC(NP) ; ')
  5422.               *
  5423.           94   DEXP('UNIQUE.GENERIC(NPNP) = '
  5424.               +   'APPLY.TESTS( #"(UNIQUE GENERIC)", SPLIT(NPNP,G.DETS))')
  5425.               *
  5426.           95   DEXP('SPECIFIC.GENERIC(NPNP) = '
  5427.               +  'APPLY.TESTS( #"(SPECIFIC GENERIC)", SPLIT(NPNP,G.DETS))')
  5428.               *
  5429.           96   DEXP('GENERIC.GENERIC(NPNP) = '
  5430.               +  'APPLY.TESTS( #"(GENERIC GENERIC)", SPLIT(NPNP,G.DETS))')
  5431.               *
  5432.           97   DEXP('SPLIT(SNP.LD) = SPLIT1(CDR(SNP),LD,CAR(SNP) ~'
  5433.               +        'NIL,NIL)')
  5434.               *
  5435.           98   DEFINE('SPLIT1(SNP,LD,NP,LNP)')   :(SPLIT1.END)
  5436.           99  SPLIT1   SPLIT1 =
  5437.               +     NULL(SNP) LREVERSE( LREVERSE(NP) ~ LNP)     :S(RETURN)
  5438.           100       SPLIT1 = MEMQ(CAR(SNP),LD)
  5439.               +        SPLIT1(CDR(SNP),LD,CAR(SNP) ~ NIL,
  5440.               +             LREVERSE(NP) ~ LNP)       :S(RETURN)
  5441.           101       SPLIT1 =
  5442.               +        SPLIT1( CDR(SNP), LD, CAR(SNP) ~ NP, LNP)
  5443.               +             :(RETURN)
  5444.           102 SPLIT1.END
  5445.               *
  5446.               * Some responses returned from semantic routines
  5447.               *
  5448.           103  UNDERSTAND = "I UNDERSTAND."
  5449.           104  YES = "YES."
  5450.           105  SOMETIMES = "SOMETIMES."
  5451.           106  INSUFFICIENT = "INSUFFICIENT INFORMATION"
  5452.           107  SILENCE = ""
  5453.               *
  5454.           108  DEFINE('SETR(X,Y)')    :(SETR.END)
  5455.           109 SETR  ADDXRY(X,"SUBSET",Y)
  5456.           110       ADDYRX(Y,"SUPERSET",X)
  5457.           111       SETR = UNDERSTAND      :(RETURN)
  5458.           112 SETR.END
  5459.               *
  5460.           113  DEFINE('SETRQ(X,Y)')   :(SETRQ.END)
  5461.           114 SETRQ  SETRQ = PATH( .X, #"(SUBSET *)", .Y)   YES
  5462.               +        :S(RETURN)
  5463.           115       SETRQ = PATH( .Y, #"(SUBSET +)", .X)   SOMETIMES
  5464.               +        :S(RETURN)
  5465.           116       SETRQ = INSUFFICIENT   :(RETURN)
  5466.           117 SETRQ.END
  5467.               *
  5468.           118  DEFINE('SETRS(X,Y)')  :(SETRS.END)
  5469.           119 SETRS ADDXRY(X,"MEMBER",Y)
  5470.           120         ADDYRX(Y,"ELEMENTS",X)
  5471.           121         SETRS = UNDERSTAND  :(RETURN)
  5472.           122 SETRS.END
  5473.  
  5474.  
  5475.  
  5476.        AI Programming in SNOBOL4      - 169 -                    August, 1982
  5477.  
  5478.  
  5479.  
  5480.  
  5481.  
  5482.  
  5483.  
  5484.  
  5485.               *
  5486.           123  DEFINE('SETRSQ(X,Y)') :(SETRSQ.END)
  5487.           124 SETRSQ   SETRSQ =
  5488.               +        PATH( .X, #"(EQUIV * MEMBER SUBSET *)", .Y)   YES
  5489.               +        :S(RETURN)
  5490.           125       SETRSQ = INSUFFICIENT :(RETURN)
  5491.           126 SETRSQ.END
  5492.               *
  5493.           127  DEFINE('SETRS1(X,Y)') :(SETRS1.END)
  5494.           128 SETRS1   SETRS1 = DIFFER(NIL,SET(.X,SPECIFY(X)))
  5495.               +        SETRS(X,Y)      :S(RETURN)
  5496.           129       SETRS1 = SILENCE   :(RETURN)
  5497.           130 SETRS1.END
  5498.               *
  5499.           131  DEXP('SPECIFY(X) = '
  5500.               +     'SPECIFY1(EQUIV.COMPRESS(GET(X,"ELEMENTS")),X)')
  5501.               *
  5502.           132  DEFINE('SPECIFY1(U,X)')      :(SPECIFY1.END)
  5503.           133 SPECIFY1     NULL(U)    :F(SPECIFY1A)
  5504.           134       SPECIFY1 = SET( .U, GENSYM())
  5505.           135       SETRS(U,X)
  5506.           136       |(U " IS A " X ".")   :(RETURN)
  5507.           137 SPECIFY1A
  5508.               +     SPECIFY1 = NULL(CDR(U)) CAR(U)    :S(RETURN)
  5509.           138       |("WHICH " X "? ... " !U)
  5510.           139       SPECIFY1 = NIL    :(RETURN)
  5511.           140 SPECIFY1.END
  5512.               *
  5513.           141  DEXP('EQUIV.COMPRESS(LX) = EQUIV.COMP1(LX,NIL)')
  5514.               *
  5515.           142  DEFINE('EQUIV.COMP1(LX,LEX)')     :(EQUIV.COMP1.END)
  5516.           143 EQUIV.COMP1
  5517.               +     EQUIV.COMP1 = NULL(LX) NIL   :S(RETURN)
  5518.           144       EQUIV.COMP1 = MEMQ(CAR(LX),LEX)
  5519.               +        EQUIV.COMP1(CDR(LX),LEX)      :S(RETURN)
  5520.           145       EQUIV.COMP1 =
  5521.               +        CAR(LX) ~
  5522.               +             EQUIV.COMP1( CDR(LX),
  5523.               +                  APPEND( GET(CAR(LX),"EQUIV") ~ LEX ~ NIL))
  5524.               +                  :(RETURN)
  5525.           146 EQUIV.COMP1.END
  5526.               *
  5527.           147  DEFINE('SETRS1Q(X,Y)')      :(SETRS1Q.END)
  5528.           148 SETRS1Q  SETRS1Q = DIFFER(NIL,SET(.X,SPECIFY(X)))
  5529.               +        SETRSQ(X,Y)    :S(RETURN)
  5530.           149       SETRS1Q = SILENCE      :(RETURN)
  5531.           150 SETRS1Q.END
  5532.               *
  5533.           151  DEFINE('EQUIV(X,Y)')   :(EQUIV.END)
  5534.           152 EQUIV  ADDXRY(X,"EQUIV",Y)
  5535.           153        ADDYRX(Y,"EQUIV",X)
  5536.           154        EQUIV = UNDERSTAND   :(RETURN)
  5537.           155 EQUIV.END
  5538.               *
  5539.  
  5540.  
  5541.  
  5542.        AI Programming in SNOBOL4      - 170 -                    August, 1982
  5543.  
  5544.  
  5545.  
  5546.  
  5547.  
  5548.  
  5549.  
  5550.  
  5551.           156 DEFINE('EQUIV1(X,Y)')  :(EQUIV1.END)
  5552.           157 EQUIV1  EQUIV1 = DIFFER(NIL,SET(.Y,SPECIFY(Y)))
  5553.               +       EQUIV(X,Y)     :S(RETURN)
  5554.           158      EQUIV1 = SILENCE  :(RETURN)
  5555.           159 EQUIV1.END
  5556.               *
  5557.           160  DEFINE('OWNR(X,Y)')   :(OWNR.END)
  5558.           161 OWNR  ADDXRY(X,"OWNED.BY",Y)
  5559.           162       ADDYRX(Y,"POSSESS.BY.EACH",X)
  5560.           163       OWNR = UNDERSTAND      :(RETURN)
  5561.           164 OWNR.END
  5562.               *
  5563.           165  DEFINE('OWNRQ(X,Y)')  :(OWNRQ.END)
  5564.           166 OWNRQ OWNRQ = EQU(X,Y)
  5565.               +        "NO, THEY ARE THE SAME."     :S(RETURN)
  5566.           167       OWNRQ = PATH( .Y, #"(SUBSET * POSSESS.BY.EACH)", .X)
  5567.               +        YES  :S(RETURN)
  5568.           168       OWNRQ = INSUFFICIENT  :(RETURN)
  5569.           169 OWNRQ.END
  5570.               *
  5571.           170  DEFINE('OWNRGU(X,Y)') :(OWNRGU.END)
  5572.           171 OWNRGU   ADDYRX(Y,"POSSESS",X)
  5573.           172       ADDXRY(X,"OWNED",Y)
  5574.           173       OWNRGU = UNDERSTAND       :(RETURN)
  5575.           174 OWNRGU.END
  5576.               *
  5577.           175  DEFINE('OWNRGUQ(X,Y)')     :(OWNRGUQ.END)
  5578.           176 OWNRGUQ OWNRGUQ =
  5579.               +         PATH( .Y, #"(EQUIV * POSSESS SUBSET *)", .X)
  5580.               +         YES     :S(RETURN)
  5581.           177       OWNRGUQ =
  5582.               +         PATH( .Y, #("(EQUIV * MEMBER SUBSET *"
  5583.               +           " POSSESS.BY.EACH SUBSET *)"), .X)
  5584.               +         YES      :S(RETURN)
  5585.           178       OWNRGUQ = INSUFFICIENT      :(RETURN)
  5586.           179 OWNRGUQ.END
  5587.               *
  5588.           180  DEFINE('OWNRSGQ(X,Y)')     :(OWNRSGQ.END)
  5589.           181 OWNRSGQ  OWNRSGQ = IDENT(NIL,SPECIFY(X)) SILENCE :S(RETURN)
  5590.           182       OWNRSGQ =
  5591.               +        PATH( .X, #"(OWNED EQUIV * MEMBER SUBSET *)", .Y)
  5592.               +        YES      :S(RETURN)
  5593.           183       OWNRSGQ = INSUFFICIENT      :(RETURN)
  5594.           184 OWNRSGQ.END
  5595.               *
  5596.           185  DEFINE('MAKE.RULES(STL)ST,R')    :(MAKE.RULES.END)
  5597.           186 MAKE.RULES    MAKE.RULES = NIL
  5598.           187 MAKE.RULES1   ST = POP( .STL)    :F(MAKE.RULES2)
  5599.           188       ST = READ( "(" ST ")" )
  5600.           189       R = RULE(CAR(ST),CADR(ST),CADDR(ST),CADDDR(ST))
  5601.           190       MAKE.RULES = R ~ MAKE.RULES       :(MAKE.RULES1)
  5602.           191 MAKE.RULES2   MAKE.RULES = LREVERSE(MAKE.RULES)    :(RETURN)
  5603.           192 MAKE.RULES.END
  5604.               *
  5605.  
  5606.  
  5607.  
  5608.        AI Programming in SNOBOL4      - 171 -                    August, 1982
  5609.  
  5610.  
  5611.  
  5612.  
  5613.  
  5614.  
  5615.  
  5616.  
  5617.           193  RULE.LIST = MAKE.RULES(
  5618.               + '(IS *X* ?) (*X*) (UNIQUE.GENERIC) (SETRSQ CAAR CADAR)' ~
  5619.               + '   -    (*X*) (SPECIFIC.GENERIC) (SETRS1Q CAAR CADAR)' ~
  5620.               + '   -    (*X*) (GENERIC.GENERIC) (SETRQ CAAR CADAR)' ~
  5621.               + '(DOES *X* OWN *Y* ?) (*X* *Y*) (GENERIC GENERIC) '
  5622.               +    '(OWNRQ CADR CAR)' ~
  5623.               + '   -    (*X* *Y*) (UNIQUE GENERIC) (OWNRGUQ CADR CAR)' ~
  5624.               + '   -    (*X* *Y*) (GENERIC SPECIFIC) (OWNRSGQ CADR CAR)' ~
  5625.               + '(*X* IS *Y* !) (*X* *Y*) (UNIQUE GENERIC) '
  5626.               +    '(SETRS CAR CADR)' ~
  5627.               + '   -    (*X* *Y*) (GENERIC GENERIC) (SETR CAR CADR)' ~
  5628.               + '   -    (*X* *Y*) (SPECIFIC GENERIC) (SETRS1 CAR CADR)' ~
  5629.               + '   -    (*X* *Y*) (UNIQUE UNIQUE) (EQUIV CAR CADR)' ~
  5630.               + '   -    (*X* *Y*) (UNIQUE SPECIFIC) (EQUIV1 CAR CADR)' ~
  5631.               + '   -    (*X* *Y*) (SPECIFIC UNIQUE) (EQUIV1 CADR CAR)' ~
  5632.               + '(*X* OWNS *Y* !) (*X* *Y*)  (GENERIC GENERIC) '
  5633.               +    '(OWNR CADR CAR)' ~
  5634.               + '   -     (*X* *Y*) (UNIQUE GENERIC) (OWNRGU CADR CAR)' ~
  5635.               + NIL)
  5636.               *
  5637.           194  |("THE SIR PROGRAM STARTS  WITH " COLLECT() " BYTES.")
  5638.           195  |SIR()
  5639.           196 END
  5640.  
  5641.  
  5642.  
  5643.  
  5644.  
  5645.  
  5646.  
  5647.  
  5648.  
  5649.  
  5650.  
  5651.  
  5652.  
  5653.  
  5654.  
  5655.  
  5656.  
  5657.  
  5658.  
  5659.  
  5660.  
  5661.  
  5662.  
  5663.  
  5664.  
  5665.  
  5666.  
  5667.  
  5668.  
  5669.  
  5670.  
  5671.  
  5672.  
  5673.  
  5674.        AI Programming in SNOBOL4      - 172 -                    August, 1982
  5675.  
  5676.  
  5677.