home *** CD-ROM | disk | FTP | other *** search
/ Programmer's ROM - The Computer Language Library / programmersrom.iso / ada / ai / alspuser.doc < prev    next >
Encoding:
Text File  |  1988-05-03  |  85.5 KB  |  3,499 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18.                          C2 Support Software in Ada(R)
  19.  
  20.  
  21.  
  22.  
  23.                                  User's Manual
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.                                  SAE-DC-85-R002
  34.  
  35.  
  36.                                  March 17, 1986
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.                       Software Architecture & Engineering
  46.                         1600 Wilson Boulevard, Suite 500
  47.                            Arlington, Virginia 22209
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.            (R) Ada is a registered trademark of the U.S. Government -
  59.                             Ada Joint Program Office
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.           1.  Preface
  75.  
  76.  
  77.           This document represents the final delivery of CDRL A003
  78.           (User's Manual) for Contract N66001-85-C-0039 ("C2 Support
  79.           Software in Ada") between Software Architecture & Engineer-
  80.           ing, Inc. (Software A & E) and Naval Ocean Systems Center
  81.           (NOSC), 271 Catalina Blvd, Building A-33, San Diego, CA
  82.           92152.
  83.  
  84.           The C2 Support Software in Ada to be provided by
  85.           Software A & E consists of a generic package, the AI Data
  86.           Types package, which provides the necessary facilities to
  87.           emulate the capabilities commonly used in Artificial Intel-
  88.           ligence (AI) applications but not directly supported in Ada.
  89.           These facilities are:
  90.  
  91.           (1)  Definitions of the primary data object to be used
  92.                throughout this package, the symbolic expression.
  93.  
  94.           (2)  Symbolic expression operators.  These include functions
  95.                and procedures for creation, selection, manipulation
  96.                and destruction of symbolic expressions.
  97.  
  98.           (3)  Packages which define generic AI objects generally
  99.                found useful in AI applications:  patterns, rules and
  100.                rulebases.
  101.  
  102.           This manual will consist of six sections.  Each of the first
  103.           four sections will document one of the four data type pack-
  104.           ages: Symbolic_Expressions, Patterns, Rules and Rulebases.
  105.           The fifth will provide an explanation of how to use the AI
  106.           Data Types package including restrictions on instantiating
  107.           the package and a description of the necessary parameters
  108.           for instantiation.  The final section will describe the com-
  109.           pilation and use of the demonstration program provided with
  110.           the package.
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.           2.  Symbolic Expressions
  141.  
  142.           2.1.  Syntax
  143.  
  144.  
  145.           The following is a Backus-Naur Form (BNF) representation of
  146.           the syntax of symbolic expressions:
  147.  
  148.  
  149.               Symbolic_Expr ::= Atomic_Expr | Non_Atomic_Expr | Null_S_Expr
  150.  
  151.               Atomic_Expr ::= Literal  | Variable
  152.  
  153.               Literal ::= User defined, supplied by package instantiation.
  154.  
  155.               Variable ::= '?' Variable_Name
  156.  
  157.               Variable_Name ::= String_Literal
  158.  
  159.               Non_Atomic_Expr ::= '(' Component {',' Component} ')'
  160.  
  161.               Component ::= Symbolic_Expr
  162.  
  163.               Null_S_Expr ::= '(' ')'
  164.  
  165.  
  166.  
  167.           As can be seen from the above syntax specification, there
  168.           are three types of symbolic expressions:  atomic expres-
  169.           sions, non-atomic expressions and the null component.
  170.  
  171.           Atomic expressions are defined as being either literals or
  172.           variables.  An atomic literal is supplied by the user as a
  173.           result of package instantiation.  This literal can be a
  174.           value of any predefined or user-defined Ada enumeration,
  175.           numeric, record, array, access or private type.  For pur-
  176.           poses of discussion, literals based on enumeration or
  177.           numeric types will be referred to as simple atomic literals.
  178.           Those based on record, array, access or private types will
  179.           be called complex atomic literals.  While complex atomic
  180.           literals can be simulated using non-atomic expressions, in
  181.           cases where dynamic data structures are not necessary (the
  182.           data structures used do not grow and shrink with time) or
  183.           where additional data encapsulation is required, using com-
  184.           plex atomic literals will result in more efficient implemen-
  185.           tations.  The only values which an atomic literal may not
  186.           take on are values of a task type or any limited private
  187.           type due to the fact that equality and assignment are not
  188.           defined for these types.
  189.  
  190.           The other type of atomic expression is a variable.  A vari-
  191.           able consists of a one-character prefix ('?') and a string
  192.           literal indicating the name of the variable.  Variables are
  193.  
  194.  
  195.                                        2
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.           used primarily for pattern matching purposes which will be
  207.           discussed at length in the AI Object Packages section.
  208.  
  209.           Examples of atomic expressions:
  210.  
  211.               1234                    - integer literal
  212.               122.34                  - floating or fixed point literal
  213.               "bcd"                   - string literal
  214.               `(46, 22, 33, 97, 134)  - array of integers
  215.               `(July, 4, 1986)        - record
  216.               ?x                      - variable
  217.  
  218.  
  219.           Note that the some type of character must be used to distin-
  220.           guish between an atomic expression whose representation
  221.           includes parentheses from a non-atomic expression.  The
  222.           choice of this indicator is user-specified.
  223.  
  224.           Non-atomic expressions are composite expressions consisting
  225.           of a left ('(') and right (`)`) non-atomic delimiter and one
  226.           or more components.  Each component of a non-atomic expres-
  227.           sion is a symbolic expression.  Thus, a symbolic expression
  228.           is a recursive data type and it is possible to nest non-
  229.           atomic expressions within one another to any desired depth.
  230.  
  231.           Examples of non-atomic expressions:
  232.  
  233.               ('a', 'b', 'c', 13678)
  234.               ('(1, 2, 3, 10, 46), "foo", (Apr, 12, 1983))
  235.               ((("bar")))
  236.               (("abc", "def"), ("ghi", "jkl"))
  237.  
  238.  
  239.           The final type of symbolic expression is Null_S_Expr.
  240.           Null_S_Expr is a special constant symbolic expression which
  241.           denotes the null component and serves primarily as a
  242.           representation of an empty non-atomic expression.
  243.           Null_S_Expr cannot be placed in either of the two previous
  244.           categories because it is the only symbolic expression which
  245.           is treated as both an atomic and a non-atomic expression.
  246.           Null_S_Expr is represented as a left and right non-atomic
  247.           delimiter enclosing white space ('('')').
  248.  
  249.           2.2.  Symbolic Expression Operators
  250.  
  251.  
  252.           The following is a list of the available symbolic expression
  253.           operators categorized by their functionality.  Each entry
  254.           contains an interface specification, description and a list
  255.           of restrictions on use and possible exceptions which can be
  256.           raised.  The parameters of the subprograms in the examples
  257.           are representations of the variables supplied to the subpro-
  258.           grams, not the parameters themselves.
  259.  
  260.  
  261.                                        3
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.  
  272.           2.2.1.  Storage Management Routines
  273.  
  274.           2.2.1.1.  Free
  275.  
  276.           Interface:
  277.  
  278.               procedure Free (S_Expr_Arg : in out S_Expr);
  279.  
  280.  
  281.           Description:
  282.                Because symbolic expressions are dynamic objects, their
  283.                storage must be managed.   Free provides a way of deal-
  284.                locating storage from a symbolic expression which is no
  285.                longer in use.  It is HIGHLY recommended that this pro-
  286.                cedure be called for each symbolic expression declared
  287.                locally in a block, procedure or function before exit-
  288.                ing that local scope.
  289.  
  290.           Restrictions:
  291.                None.
  292.  
  293.           Examples:
  294.  
  295.                    procedure X (Var : in S_Expr) is
  296.                       SE : S_Expr;
  297.                    begin
  298.                       -- Process SE;
  299.  
  300.                       Free (SE);
  301.                    end X;
  302.  
  303.  
  304.  
  305.           2.2.1.2.  Return_And_Free
  306.  
  307.           Interface:
  308.  
  309.               function Return_And_Free (S_Expr_Arg : in S_Expr)
  310.                  return S_Expr;
  311.  
  312.  
  313.           Description:
  314.                Return_And_Free is another storage management function
  315.                which is to be used when returning a value from a func-
  316.                tion to insure that its storage is later reclaimed.
  317.                When returning a value of type S_Expr from a function,
  318.                Return_And_Free should be called and the value returned
  319.                from Return_And_Free should be returned directly.  Once
  320.                again, it is HIGHLY recommended that this convention be
  321.                followed to avoid inefficient use of and possible
  322.                exhaustion of available storage space.
  323.  
  324.  
  325.  
  326.  
  327.                                        4
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336.  
  337.  
  338.           Restrictions:
  339.                None.
  340.  
  341.           Examples:
  342.  
  343.                    function X (Var : in S_Expr) return S_Expr is
  344.                       SE : S_Expr;
  345.                    begin
  346.                       -- Process SE;
  347.  
  348.                       return Return_And_Free(SE);
  349.                    end X;
  350.  
  351.  
  352.  
  353.  
  354.  
  355.  
  356.  
  357.  
  358.  
  359.  
  360.  
  361.  
  362.  
  363.  
  364.  
  365.  
  366.  
  367.  
  368.  
  369.  
  370.  
  371.  
  372.  
  373.  
  374.  
  375.  
  376.  
  377.  
  378.  
  379.  
  380.  
  381.  
  382.  
  383.  
  384.  
  385.  
  386.  
  387.  
  388.  
  389.  
  390.  
  391.  
  392.  
  393.                                        5
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400.  
  401.  
  402.  
  403.  
  404.           2.2.2.  Creation Routines
  405.  
  406.           2.2.2.1.  Create_Atomic_Literal
  407.  
  408.           Interface:
  409.  
  410.               function Create_Atomic_Literal (Literal_Arg : in Atomic_Literal)
  411.                  return S_Expr;
  412.  
  413.  
  414.           Description:
  415.                Create_Atomic_Literal returns an atomic expression con-
  416.                taining the specified Literal_Arg.
  417.  
  418.           Restrictions:
  419.                None.
  420.  
  421.  
  422.           2.2.2.2.  Create_Atomic_Variable
  423.  
  424.           Interface:
  425.  
  426.               function Create_Atomic_Variable (Name : in String)
  427.                  return S_Expr;
  428.  
  429.  
  430.           Description:
  431.                Create_Atomic_Variable returns an atomic expression
  432.                containing an atomic variable with the specified Name.
  433.  
  434.           Restrictions:
  435.                None.
  436.  
  437.  
  438.           2.2.2.3.  Prefix
  439.  
  440.           Interface:
  441.  
  442.               function Prefix (First_Value : in S_Expr;
  443.                                Rest_Value  : in S_Expr := Null_S_Expr)
  444.                  return S_Expr;
  445.  
  446.  
  447.           Description:
  448.                If the second argument is atomic, Prefix returns an
  449.                expression, X, such that First (X) = First_Value and
  450.                First (Rest (X)) = Rest_Value.  Otherwise, it returns
  451.                an expression, Y, such that First (Y) = First_Value and
  452.                Rest (Y) = Rest_Value.
  453.  
  454.           Restrictions:
  455.                None.
  456.  
  457.  
  458.  
  459.                                        6
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466.  
  467.  
  468.  
  469.  
  470.           Examples:
  471.  
  472.                Prefix  () ()    ==> (())
  473.                Prefix  a ()     ==> (a)
  474.                Prefix  () a     ==> ((), a)
  475.                Prefix  () (a)   ==> ((), a)
  476.                Prefix  a b      ==> (a, b)
  477.                Prefix  a (b)    ==> (a, b)
  478.                Prefix  (a) b    ==> ((a), b)
  479.                Prefix  (a) (b)  ==> ((a), b)
  480.  
  481.  
  482.  
  483.           2.2.2.4.  &
  484.  
  485.           Interface:
  486.  
  487.               function "&" (S_Expr_Arg1, S_Expr_Arg2 : in S_Expr)
  488.                  return S_Expr;
  489.  
  490.  
  491.           Description:
  492.                "&" returns Null_S_Expr if both its arguments are
  493.                Null_S_Expr.  Otherwise, "&" returns a non-atomic
  494.                expression which contains as components:
  495.  
  496.                (1) S_Expr_Arg1 and S_Expr_Arg2, if both are atomic
  497.                expressions.
  498.  
  499.                (2) the components of S_Expr_Arg1 appended with
  500.                S_Expr_Arg2, if S_Expr_Arg1 is a non-atomic expression
  501.                and S_Expr_Arg2 is an atomic expression.
  502.  
  503.                (3) S_Expr_Arg1 appended with the components of
  504.                S_Expr_Arg2, if S_Expr_Arg1 is an atomic expression and
  505.                S_Expr_Arg2 is a non-atomic expression.
  506.  
  507.                (4) the components of S_Expr_Arg1 appended with the
  508.                components of S_Expr_Arg2, if both are non-atomic
  509.                expressions.
  510.  
  511.           Restrictions:
  512.                None.
  513.  
  514.           Examples:
  515.  
  516.                () & ()          ==> ()
  517.                () & a           ==> (a)
  518.                () & (a)         ==> (a)
  519.                a & b            ==> (a, b)
  520.                a & (b)          ==> (a, b)
  521.                (a) & (b)        ==> (a, b)
  522.                (a, b) & (c, d)  ==> (a, b, c, d)
  523.  
  524.  
  525.                                        7
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532.  
  533.  
  534.  
  535.  
  536.           2.2.3.  Component Selection Routines
  537.  
  538.           2.2.3.1.  First
  539.  
  540.           Interface:
  541.  
  542.               function First (Non_Atomic_Arg : in S_Expr)
  543.                  return S_Expr;
  544.  
  545.  
  546.           Description:
  547.                First returns the first component of Non_Atomic_Arg.
  548.  
  549.           Restrictions:
  550.                Non_Atomic_Arg must be a non-null, non-atomic expres-
  551.                sion.  If not, the exception Atomic_Expr is raised.
  552.  
  553.           Examples:
  554.  
  555.                First ((), a, b)   ==> ()
  556.                First (a, b, c)    ==> a
  557.                First ((a), b, c)  ==> (a)
  558.  
  559.  
  560.  
  561.           2.2.3.2.  Rest
  562.  
  563.           Interface:
  564.  
  565.               function Rest (Non_Atomic_Arg : in S_Expr)
  566.                  return S_Expr;
  567.  
  568.  
  569.           Description:
  570.                If Non_Atomic_Arg is a non-atomic expression containing
  571.                only one component, Rest returns Null_S_Expr.  Other-
  572.                wise, Rest returns a non-atomic expression which con-
  573.                tains all components of Non_Atomic_Arg except the
  574.                first.
  575.  
  576.           Restrictions:
  577.                Non_Atomic_Arg must be a non-null, non-atomic expres-
  578.                sion.  If not, the exception Atomic_Expression is
  579.                raised.
  580.  
  581.           Examples:
  582.  
  583.                Rest (a)          ==> ()
  584.                Rest (a, b, c)    ==> (b, c)
  585.                Rest (a, (b, c))  ==> ((b, c))
  586.  
  587.  
  588.  
  589.  
  590.  
  591.                                        8
  592.  
  593.  
  594.  
  595.  
  596.  
  597.  
  598.  
  599.  
  600.  
  601.  
  602.           2.2.3.3.  Nth
  603.  
  604.           Interface:
  605.  
  606.               function Nth (Non_Atomic_Arg : in S_Expr;
  607.                             Position       : in Positive)
  608.                  return S_Expr;
  609.  
  610.  
  611.           Description:
  612.                Nth returns the Position-th component of
  613.                Non_Atomic_Arg.
  614.  
  615.           Restrictions:
  616.                Non_Atomic_Arg must be a non-null, non-atomic expres-
  617.                sion.  If not, the exception Atomic_Expression is
  618.                raised.  Position must be a valid position within
  619.                Non_Atomic_Arg.  If not, the exception Invalid_Position
  620.                is raised.
  621.  
  622.           Examples:
  623.  
  624.                Nth (a, (b), c)  1  ==> a
  625.                Nth (a, (b), c)  2  ==> (b)
  626.                Nth (a, (b), c)  3  ==> c
  627.  
  628.  
  629.  
  630.           2.2.3.4.  Last
  631.  
  632.           Interface:
  633.  
  634.               function Last (Non_Atomic_Arg : in S_Expr)
  635.                  return S_Expr;
  636.  
  637.  
  638.           Description:
  639.                Last returns the last component of Non_Atomic_Arg.
  640.  
  641.           Restrictions:
  642.                Non_Atomic_Arg must be a non-null, non-atomic expres-
  643.                sion.  If not, the exception Atomic_Expression is
  644.                raised.
  645.  
  646.           Examples:
  647.  
  648.                Last (a, b, c)      ==> c
  649.                Last (a, b, (c))    ==> (c)
  650.                Last (a, (b, (c)))  ==> (b, (c))
  651.  
  652.  
  653.  
  654.  
  655.  
  656.  
  657.                                        9
  658.  
  659.  
  660.  
  661.  
  662.  
  663.  
  664.  
  665.  
  666.  
  667.  
  668.           2.2.3.5.  Nth_First
  669.  
  670.           Interface:
  671.  
  672.               function Nth_First (Non_Atomic_Arg : in S_Expr;
  673.                                   Repetitions : in Positive)
  674.                  return S_Expr;
  675.  
  676.  
  677.           Description:
  678.                Nth_First returns the result of calling the function
  679.                First Repetitions times each time using the result of
  680.                the previous call as the argument for the new itera-
  681.                tion.
  682.  
  683.           Restrictions:
  684.                Non_Atomic_Arg must be a non-null, non-atomic expres-
  685.                sion.  If not, the exception Atomic_Expression is
  686.                raised.  Also, if the function First cannot be called
  687.                Repetitions times with a non-atomic argument each time,
  688.                the exception Invalid_Repetitions is raised.
  689.  
  690.           Examples:
  691.  
  692.                Nth_First (((a)), b, c)  1   ==> ((a))
  693.                Nth_First (((a)), b, c)  2   ==> (a)
  694.                Nth_First (((a)), b, c)  3   ==> a
  695.  
  696.  
  697.  
  698.           2.2.3.6.  Nth_Rest
  699.  
  700.           Interface:
  701.  
  702.               function Nth_Rest (Non_Atomic_Arg : in S_Expr;
  703.                                  Repetitions : in Positive)
  704.                  return S_Expr;
  705.  
  706.  
  707.           Description:
  708.                Nth_Rest returns the result of calling the function
  709.                Rest Repetitions times each time using the result of
  710.                the previous call as the argument for the new itera-
  711.                tion.
  712.  
  713.           Restrictions:
  714.                Non_Atomic_Arg must be a non-null, non-atomic expres-
  715.                sion.  If not, the exception Atomic_Expression is
  716.                raised.  Also, if the function Rest cannot be called
  717.                Repetitions times with a non-atomic argument each time,
  718.                the exception Invalid_Repetitions is raised.
  719.  
  720.  
  721.  
  722.  
  723.                                        10
  724.  
  725.  
  726.  
  727.  
  728.  
  729.  
  730.  
  731.  
  732.  
  733.  
  734.           Examples:
  735.  
  736.                Nth_Rest (a, b, c) 1  ==> (b, c)
  737.                Nth_Rest (a, b, c) 2  ==> (c)
  738.                Nth_Rest (a, b, c) 3  ==> ()
  739.  
  740.  
  741.  
  742.  
  743.  
  744.  
  745.  
  746.  
  747.  
  748.  
  749.  
  750.  
  751.  
  752.  
  753.  
  754.  
  755.  
  756.  
  757.  
  758.  
  759.  
  760.  
  761.  
  762.  
  763.  
  764.  
  765.  
  766.  
  767.  
  768.  
  769.  
  770.  
  771.  
  772.  
  773.  
  774.  
  775.  
  776.  
  777.  
  778.  
  779.  
  780.  
  781.  
  782.  
  783.  
  784.  
  785.  
  786.  
  787.  
  788.  
  789.                                        11
  790.  
  791.  
  792.  
  793.  
  794.  
  795.  
  796.  
  797.  
  798.  
  799.  
  800.           2.2.4.  Comparison Operators
  801.  
  802.           2.2.4.1.  Is_Null
  803.  
  804.           Interface:
  805.  
  806.               function Is_Null (S_Expr_Arg : in S_Expr)
  807.                  return Boolean;
  808.  
  809.  
  810.           Description:
  811.                Is_Null returns True if S_Expr_Arg is equal to
  812.                Null_S_Expr.
  813.  
  814.           Restrictions:
  815.                None.
  816.  
  817.           Examples:
  818.  
  819.                Is_Null ()       ==> TRUE
  820.                Is_Null (())     ==> FALSE
  821.                Is_Null a        ==> FALSE
  822.                Is_Null ((), a)  ==> FALSE
  823.  
  824.  
  825.  
  826.           2.2.4.2.  Is_Atomic
  827.  
  828.           Interface:
  829.  
  830.               function Is_Atomic (S_Expr_Arg : in S_Expr)
  831.                  return Boolean;
  832.  
  833.  
  834.           Description:
  835.                Is_Atomic returns True if S_Expr_Arg is an atomic
  836.                expression.
  837.  
  838.           Restrictions:
  839.                None.
  840.  
  841.           Examples:
  842.  
  843.                Is_Atomic ()       ==> TRUE
  844.                Is_Atomic a        ==> TRUE
  845.                Is_Atomic (())     ==> FALSE
  846.                Is_Atomic ((), a)  ==> FALSE
  847.                Is_Atomic (a, b)   ==> FALSE
  848.  
  849.  
  850.  
  851.  
  852.  
  853.  
  854.  
  855.                                        12
  856.  
  857.  
  858.  
  859.  
  860.  
  861.  
  862.  
  863.  
  864.  
  865.  
  866.           2.2.4.3.  Is_Non_Atomic
  867.  
  868.           Interface:
  869.  
  870.               function Is_Non_Atomic (S_Expr_Arg : in S_Expr)
  871.                  return Boolean;
  872.  
  873.  
  874.           Description:
  875.                Is_Non_Atomic returns True if S_Expr_Arg is a non-
  876.                atomic expression.
  877.  
  878.           Restrictions:
  879.                None.
  880.  
  881.           Examples:
  882.  
  883.                Is_Non_Atomic ()       ==> TRUE
  884.                Is_Non_Atomic a        ==> FALSE
  885.                Is_Non_Atomic (())     ==> TRUE
  886.                Is_Non_Atomic ((), a)  ==> TRUE
  887.                Is_Non_Atomic (a, b)   ==> TRUE
  888.  
  889.  
  890.  
  891.           2.2.4.4.  Is_Variable
  892.  
  893.           Interface:
  894.  
  895.               function Is_Variable (S_Expr_Arg : in S_Expr)
  896.                  return Boolean;
  897.  
  898.  
  899.           Description:
  900.                Is_Variable returns True if S_Expr_Arg is an atomic
  901.                variable.
  902.  
  903.           Restrictions:
  904.                None.
  905.  
  906.           Examples:
  907.  
  908.                Bind (AV, Create_Atomic_Variable("var1"));
  909.                Is_Variable AV ==> TRUE
  910.  
  911.  
  912.  
  913.           2.2.4.5.  Is_Equal
  914.  
  915.           Interface:
  916.  
  917.               function Is_Equal (S_Expr_Arg1, S_Expr_Arg2 : in S_Expr)
  918.                  return Boolean;
  919.  
  920.  
  921.                                        13
  922.  
  923.  
  924.  
  925.  
  926.  
  927.  
  928.  
  929.  
  930.  
  931.  
  932.           Description:
  933.                Is_Equal returns True if S_Expr_Arg1 and S_Expr_Arg2
  934.                are equal. Two atomic expressions are equal if they
  935.                contain equivalent literals or equivalent variables.
  936.                Two non-atomic expressions are equal if each component
  937.                of the expression is equal.
  938.  
  939.           Restrictions:
  940.                None.
  941.  
  942.           Examples:
  943.  
  944.                Is_Equal () ()          ==> TRUE
  945.                Is_Equal a a            ==> TRUE
  946.                Is_Equal a b            ==> FALSE
  947.                Is_Equal a (a)          ==> FALSE
  948.                Is_Equal () (())        ==> FALSE
  949.                Is_Equal (a, b) (a, b)  ==> TRUE
  950.  
  951.  
  952.  
  953.  
  954.  
  955.  
  956.  
  957.  
  958.  
  959.  
  960.  
  961.  
  962.  
  963.  
  964.  
  965.  
  966.  
  967.  
  968.  
  969.  
  970.  
  971.  
  972.  
  973.  
  974.  
  975.  
  976.  
  977.  
  978.  
  979.  
  980.  
  981.  
  982.  
  983.  
  984.  
  985.  
  986.  
  987.                                        14
  988.  
  989.  
  990.  
  991.  
  992.  
  993.  
  994.  
  995.  
  996.  
  997.  
  998.           2.2.5.  Manipulation Routines
  999.  
  1000.           2.2.5.1.  Reverse_S_Expr
  1001.  
  1002.           Interface:
  1003.  
  1004.               function Reverse_S_Expr (Non_Atomic_Arg : in S_Expr)
  1005.                  return S_Expr;
  1006.  
  1007.  
  1008.           Description:
  1009.                Reverse_S_Expr returns a non-atomic expression with the
  1010.                top-level components of Non_Atomic_Arg in reverse
  1011.                order.
  1012.  
  1013.           Restrictions:
  1014.                Non_Atomic_Arg must be a non-null, non-atomic expres-
  1015.                sion.  If not, the exception Atomic_Expression is
  1016.                raised.
  1017.  
  1018.           Examples:
  1019.  
  1020.                Reverse_S_Expr (a, b, c)       ==> (c, b, a)
  1021.                Reverse_S_Expr ((a, b), c, d)  ==> (d, c, (a, b))
  1022.  
  1023.  
  1024.  
  1025.           2.2.5.2.  Flatten
  1026.  
  1027.           Interface:
  1028.  
  1029.               function Flatten (Non_Atomic_Arg : in S_Expr)
  1030.                  return S_Expr;
  1031.  
  1032.  
  1033.           Description:
  1034.                Flatten returns a non-atomic expression which has as
  1035.                components all atomic components of Non_Atomic_Arg and
  1036.                all atomic components of all non-atomic expression
  1037.                within Non_Atomic_Arg.  That is, Flatten removes all
  1038.                internal parentheses from Non_Atomic_Arg.
  1039.  
  1040.           Restrictions:
  1041.                Non_Atomic_Arg must be a non-null, non-atomic expres-
  1042.                sion.  If not, the exception Atomic_Expression is
  1043.                raised.
  1044.  
  1045.           Examples:
  1046.  
  1047.                Flatten ((a), (b, (c, ((d)), e)))  ==> (a, b, c, d, e)
  1048.                Flatten (())  ==> ()
  1049.  
  1050.  
  1051.  
  1052.  
  1053.                                        15
  1054.  
  1055.  
  1056.  
  1057.  
  1058.  
  1059.  
  1060.  
  1061.  
  1062.  
  1063.  
  1064.           2.2.5.3.  Delete
  1065.  
  1066.           Interface:
  1067.  
  1068.               function Delete (S_Expr_Arg, Non_Atomic_Arg : in S_Expr)
  1069.                  return S_Expr;
  1070.  
  1071.  
  1072.           Description:
  1073.                Delete returns a copy of Non_Atomic_Arg with all top-
  1074.                level occurrences of S_Expr_Arg removed.
  1075.  
  1076.           Restrictions:
  1077.                Non_Atomic_Arg must be a non-null, non-atomic expres-
  1078.                sion.  If not, the exception Atomic_Expression is
  1079.                raised.
  1080.  
  1081.           Examples:
  1082.  
  1083.                Delete a (a, b, (a), a, c)  ==> (b, (a), c)
  1084.                Delete a (b, b, (a), c, c)  ==> (b, b, (a), c, c)
  1085.  
  1086.  
  1087.  
  1088.           2.2.5.4.  Replace
  1089.  
  1090.           Interface:
  1091.  
  1092.               function Replace (S_Expr_Arg1, S_Expr_Arg2,
  1093.                                 Non_Atomic_Arg : in S_Expr)
  1094.                  return S_Expr;
  1095.  
  1096.  
  1097.           Description:
  1098.                Replace returns a copy of Non_Atomic_Arg with all top-
  1099.                level occurrences of S_Expr_Arg1 replaced by
  1100.                S_Expr_Arg2.
  1101.  
  1102.           Restrictions:
  1103.                Non_Atomic_Arg must be a non-null, non-atomic expres-
  1104.                sion.  If not, the exception Atomic_Expression is
  1105.                raised.
  1106.  
  1107.           Examples:
  1108.  
  1109.                Replace a b (a, b, (a), a, c)  ==> (b, b, (a), b, c)
  1110.                Replace a b (b, b, (a), c, c)  ==> (b, b, (a), c, c)
  1111.  
  1112.  
  1113.  
  1114.  
  1115.  
  1116.  
  1117.  
  1118.  
  1119.                                        16
  1120.  
  1121.  
  1122.  
  1123.  
  1124.  
  1125.  
  1126.  
  1127.  
  1128.  
  1129.  
  1130.           2.2.6.  Set Operators
  1131.  
  1132.           2.2.6.1.  Is_Member
  1133.  
  1134.           Interface:
  1135.  
  1136.               function Is_Member (S_Expr_Arg,
  1137.                                   Non_Atomic_Arg : in S_Expr)
  1138.                  return Boolean;
  1139.  
  1140.  
  1141.           Description:
  1142.                Is_Member returns True if S_Expr_Arg is a top-level
  1143.                component of Non_Atomic_Arg.
  1144.  
  1145.           Restrictions:
  1146.                Non_Atomic_Arg must be a non-atomic expression.  If
  1147.                not, the exception Atomic_Expression is raised.
  1148.  
  1149.           Examples:
  1150.  
  1151.                Is_Member a (a, b, c)    ==> TRUE
  1152.                Is_Member a (b, c, d)    ==> FALSE
  1153.                Is_Member a ((a), b, c)  ==> FALSE
  1154.  
  1155.  
  1156.  
  1157.           2.2.6.2.  And (Intersection)
  1158.  
  1159.           Interface:
  1160.  
  1161.               function "And" (Non_Atomic_Arg1,
  1162.                               Non_Atomic_Arg2 : in S_Expr)
  1163.                  return S_Expr;
  1164.  
  1165.  
  1166.           Description:
  1167.                "And" returns a non-atomic expression which contains as
  1168.                components only those components which are both in
  1169.                Non_Atomic_Arg1 AND Non_Atomic_Arg2 with no duplicates.
  1170.  
  1171.           Restrictions:
  1172.                Non_Atomic_Arg1 and Non_Atomic_Arg2 must both be non-
  1173.                atomic expressions.  If not, the exception
  1174.                Atomic_Expression is raised.
  1175.  
  1176.           Examples:
  1177.  
  1178.                (a, b, c) And (a, d, e)     ==> (a)
  1179.                (a, b, c) And (a, b, b, e)  ==> (b, a)
  1180.  
  1181.  
  1182.  
  1183.  
  1184.  
  1185.                                        17
  1186.  
  1187.  
  1188.  
  1189.  
  1190.  
  1191.  
  1192.  
  1193.  
  1194.  
  1195.  
  1196.           2.2.6.3.  Or (Union)
  1197.  
  1198.           Interface:
  1199.  
  1200.               function "Or" (Non_Atomic_Arg1,
  1201.                              Non_Atomic_Arg2 : in S_Expr)
  1202.                  return S_Expr;
  1203.  
  1204.  
  1205.           Description:
  1206.                "Or" returns a non-atomic expression which contains as
  1207.                components all components which are either in
  1208.                Non_Atomic_Arg1 OR Non_Atomic_Arg2 with no duplicates.
  1209.  
  1210.           Restrictions:
  1211.                Non_Atomic_Arg1 and Non_Atomic_Arg2 must both be non-
  1212.                atomic expressions.  If not, the exception
  1213.                Atomic_Expression is raised.
  1214.  
  1215.           Examples:
  1216.  
  1217.                (a, b, c) Or (a, d, e)     ==> (c, b, e, d, a)
  1218.                (a, b, c) Or (a, b, b, e)  ==> (c, e, b, a)
  1219.  
  1220.  
  1221.  
  1222.           2.2.6.4.  - (Difference)
  1223.  
  1224.           Interface:
  1225.  
  1226.               function "-" (Non_Atomic_Arg1,
  1227.                             Non_Atomic_Arg2 : in S_Expr)
  1228.                  return S_Expr;
  1229.  
  1230.  
  1231.           Description:
  1232.                "-" returns a non-atomic expression which contains as
  1233.                components all those components of Non_Atomic_Arg1
  1234.                which are not contained in Non_Atomic_Arg2 with no
  1235.                duplicates.
  1236.  
  1237.           Restrictions:
  1238.                Non_Atomic_Arg1 and Non_Atomic_Arg2 must both be non-
  1239.                atomic expressions.  If not, the exception
  1240.                Atomic_Expression is raised.
  1241.  
  1242.           Examples:
  1243.  
  1244.                (a, b, c) - (a, d, e)     ==> (c, b)
  1245.                (a, b, c) - (a, b, b, e)  ==> (c)
  1246.  
  1247.  
  1248.  
  1249.  
  1250.  
  1251.                                        18
  1252.  
  1253.  
  1254.  
  1255.  
  1256.  
  1257.  
  1258.  
  1259.  
  1260.  
  1261.  
  1262.           2.2.6.5.  Xor (Excluded Union)
  1263.  
  1264.           Interface:
  1265.  
  1266.               function "Xor" (Non_Atomic_Arg1,
  1267.                               Non_Atomic_Arg2 : in S_Expr)
  1268.                  return S_Expr;
  1269.  
  1270.  
  1271.           Description:
  1272.                "Xor" returns a non-atomic expression which contains as
  1273.                components all those components of Non_Atomic_Arg1
  1274.                which are not contained in Non_Atomic_Arg2 and all
  1275.                those components of Non_Atomic_Arg2 which are not con-
  1276.                tained in Non_Atomic_Arg1 with no duplicates.
  1277.  
  1278.           Restrictions:
  1279.                Non_Atomic_Arg1 and Non_Atomic_Arg2 must both be non-
  1280.                atomic expressions.  If not, the exception
  1281.                Atomic_Expression is raised.
  1282.  
  1283.           Examples:
  1284.  
  1285.                (a, b, c) Xor (a, d, e)     ==> (b, c, d, e)
  1286.                (a, b, c) Xor (a, b, b, e)  ==> (c, e)
  1287.  
  1288.  
  1289.  
  1290.  
  1291.  
  1292.  
  1293.  
  1294.  
  1295.  
  1296.  
  1297.  
  1298.  
  1299.  
  1300.  
  1301.  
  1302.  
  1303.  
  1304.  
  1305.  
  1306.  
  1307.  
  1308.  
  1309.  
  1310.  
  1311.  
  1312.  
  1313.  
  1314.  
  1315.  
  1316.  
  1317.                                        19
  1318.  
  1319.  
  1320.  
  1321.  
  1322.  
  1323.  
  1324.  
  1325.  
  1326.  
  1327.  
  1328.           2.2.7.  Input/Output Routines
  1329.  
  1330.           2.2.7.1.  Get
  1331.  
  1332.           Interface:
  1333.  
  1334.               procedure Get (Input_File : in File_Type;
  1335.                              S_Expr_Result : in out S_Expr);
  1336.  
  1337.               procedure Get (S_Expr_Result : in out S_Expr);
  1338.  
  1339.  
  1340.           Description:
  1341.                Get reads a symbolic expression from either the speci-
  1342.                fied or the current default input file.
  1343.  
  1344.           Restrictions:
  1345.                The following exceptions may be raised based on the
  1346.                error in the input:   Extra_Separator,
  1347.                Missing_Separator, Invalid_Variable_Name and
  1348.                Improper_Input.  The first three are self-explanatory,
  1349.                the last is raised upon any error condition not handled
  1350.                by the other three.
  1351.  
  1352.  
  1353.           2.2.7.2.  Put
  1354.  
  1355.           Interface:
  1356.  
  1357.               procedure Put (Output_File : in File_Type;
  1358.                              S_Expr_Arg : in S_Expr);
  1359.  
  1360.               procedure Put (S_Expr_Arg : in S_Expr);
  1361.  
  1362.  
  1363.           Description:
  1364.                Put writes a symbolic expression to either the speci-
  1365.                fied or current default output file.
  1366.  
  1367.           Restrictions:
  1368.                None.
  1369.  
  1370.  
  1371.  
  1372.  
  1373.  
  1374.  
  1375.  
  1376.  
  1377.  
  1378.  
  1379.  
  1380.  
  1381.  
  1382.  
  1383.                                        20
  1384.  
  1385.  
  1386.  
  1387.  
  1388.  
  1389.  
  1390.  
  1391.  
  1392.  
  1393.  
  1394.           2.2.8.  Miscellaneous Operators
  1395.  
  1396.           2.2.8.1.  Bind
  1397.  
  1398.           Interface:
  1399.  
  1400.               procedure Bind (Current_Value : in out S_Expr;
  1401.                               New_Value : in S_Expr);
  1402.  
  1403.  
  1404.           Description:
  1405.                Bind assigns the value of New_Value to Current_Value
  1406.                freeing the structure originally associated with
  1407.                Current_Value in the process.
  1408.  
  1409.           Restrictions:
  1410.                None.
  1411.  
  1412.  
  1413.           2.2.8.2.  Length
  1414.  
  1415.           Interface:
  1416.  
  1417.               function Length (S_Expr_Arg : in S_Expr)
  1418.                  return Natural;
  1419.  
  1420.  
  1421.           Description:
  1422.                If S_Expr_Arg is an atomic expression, Length returns
  1423.                0.  Otherwise, Length returns the number of components
  1424.                in S_Expr_Arg.
  1425.  
  1426.           Restrictions:
  1427.                None.
  1428.  
  1429.           Examples:
  1430.  
  1431.                Length a          ==> 0
  1432.                Length ()         ==> 0
  1433.                Length (a, b, c)  ==> 3
  1434.  
  1435.  
  1436.  
  1437.           2.2.8.3.  Return_Atomic_Literal
  1438.  
  1439.           Interface:
  1440.  
  1441.               function Return_Atomic_Literal (Atomic_Arg : in S_Expr)
  1442.                  return Atomic_Literal;
  1443.  
  1444.  
  1445.           Description:
  1446.                Return_Atomic_Literal returns the Atomic_Literal
  1447.  
  1448.  
  1449.                                        21
  1450.  
  1451.  
  1452.  
  1453.  
  1454.  
  1455.  
  1456.  
  1457.  
  1458.  
  1459.  
  1460.                extracted from the given Atomic_Arg.
  1461.  
  1462.           Restrictions:
  1463.                Atomic_Arg must be a non-null, atomic expression.  If
  1464.                not, the exception Non_Atomic_Expression is raised.
  1465.                Atomic_Arg must be a literal.  If not, the exception
  1466.                Not_A_Literal is raised.
  1467.  
  1468.  
  1469.           2.2.8.4.  Set_Variable_Tag
  1470.  
  1471.           Interface:
  1472.  
  1473.               procedure Set_Variable_Tag (Atomic_Arg : in S_Expr;
  1474.                                           New_Tag : in Natural);
  1475.  
  1476.  
  1477.           Description:
  1478.                Sets the tag of the given variable to the given number.
  1479.                A variable tag is used to rename a variable to make it
  1480.                distinct from other variables with the same name.
  1481.  
  1482.           Restrictions:
  1483.                Atomic_Arg must be a non-null, atomic expression.  If
  1484.                not, the exception Non_Atomic_Expression is raised.
  1485.                Atomic_Arg must be a variable.  If not, the exception
  1486.                Not_A_Variable is raised.
  1487.  
  1488.           Examples:
  1489.  
  1490.                Bind (AV, Create_Atomic_Variable("var"));
  1491.                Put (AV);  ==> var
  1492.                Set_Variable_Tag (AV, 1);
  1493.                Put (AV);  ==> var1
  1494.                Set_Variable_Tag (AV, 0);
  1495.                Put (AV);  ==> var
  1496.  
  1497.  
  1498.  
  1499.           2.2.8.5.  Return_Variable_Name
  1500.  
  1501.           Interface:
  1502.  
  1503.               function Return_Variable_Name (Atomic_Arg : in S_Expr)
  1504.                  return String;
  1505.  
  1506.  
  1507.           Description:
  1508.                Returns the name associated with the given variable.
  1509.  
  1510.           Restrictions:
  1511.                Atomic_Arg must be a non-null, atomic expression.  If
  1512.                not, the exception Non_Atomic_Expression is raised.
  1513.  
  1514.  
  1515.                                        22
  1516.  
  1517.  
  1518.  
  1519.  
  1520.  
  1521.  
  1522.  
  1523.  
  1524.  
  1525.  
  1526.                Atomic_Arg must be a variable.  If not, the exception
  1527.                Not_A_Variable is raised.
  1528.  
  1529.  
  1530.           2.2.8.6.  Return_Variable_Tag
  1531.  
  1532.           Interface:
  1533.  
  1534.               function Return_Variable_Tag (Atomic_Arg : in S_Expr)
  1535.                  return Natural;
  1536.  
  1537.  
  1538.           Description:
  1539.                Returns the tag associated with the given variable.
  1540.  
  1541.           Restrictions:
  1542.                Atomic_Arg must be a non-null, atomic expression.  If
  1543.                not, the exception Non_Atomic_Expression is raised.
  1544.                Atomic_Arg must be a variable.  If not, the exception
  1545.                Not_A_Variable is raised.
  1546.  
  1547.  
  1548.           2.2.8.7.  Associate
  1549.  
  1550.           Interface:
  1551.  
  1552.               function Associate (Key, A_Table : in S_Expr;
  1553.                                   Search_Position : Positive:= 1)
  1554.                  return S_Expr;
  1555.  
  1556.  
  1557.           Description:
  1558.  
  1559.                A_Table is of the form:
  1560.                ((a11 a12 ... a1n) (a21 a22 ... a2n) ... (am1 am2 ... amn))
  1561.  
  1562.  
  1563.                Associate returns the first component of A_Table which
  1564.                has a component in the Search_Position-th position
  1565.                which Is_Equal to the symbolic expression Key.
  1566.  
  1567.           Restrictions:
  1568.                A_Table must be a non-null, non-atomic expression.  If
  1569.                not, the exception Atomic_Expression is raised.
  1570.  
  1571.           Examples:
  1572.  
  1573.                Associate a ((a, b), (b, a), (a, d))    ==> (a, b)
  1574.                Associate a ((a, b), (b, a), (a, d)) 2  ==> (b, a)
  1575.                Associate c ((a, b), (b, a), (a, d))    ==> ()
  1576.  
  1577.  
  1578.  
  1579.  
  1580.  
  1581.                                        23
  1582.  
  1583.  
  1584.  
  1585.  
  1586.  
  1587.  
  1588.  
  1589.  
  1590.  
  1591.  
  1592.           2.2.8.8.  Associate_All
  1593.  
  1594.           Interface:
  1595.  
  1596.               function Associate_All (Key, A_Table : in S_Expr;
  1597.                                       Search_Position : Positive:= 1)
  1598.                  return S_Expr;
  1599.  
  1600.  
  1601.           Description:
  1602.  
  1603.                A_Table is of the form:
  1604.                ((a11 a12 ... a1n) (a21 a22 ... a2n) ... (am1 am2 ... amn))
  1605.  
  1606.  
  1607.                Associate_All returns a non-atomic expression which
  1608.                contains as components all components of A_Table which
  1609.                have a component in the Search_Position-th position
  1610.                which Is_Equal to the symbolic expression Key.
  1611.  
  1612.           Restrictions:
  1613.                A_Table must be a non-null, non-atomic expression.  If
  1614.                not, the exception Atomic_Expression is raised.
  1615.  
  1616.           Examples:
  1617.  
  1618.                Associate_All a ((a, b), (b, a), (a, d))    ==> ((a, b), (a, d))
  1619.                Associate_All a ((a, b), (b, a), (a, d)) 2  ==> ((b, a))
  1620.                Associate_All c ((a, b), (b, a), (a, d))    ==> ()
  1621.  
  1622.  
  1623.  
  1624.  
  1625.  
  1626.  
  1627.  
  1628.  
  1629.  
  1630.  
  1631.  
  1632.  
  1633.  
  1634.  
  1635.  
  1636.  
  1637.  
  1638.  
  1639.  
  1640.  
  1641.  
  1642.  
  1643.  
  1644.  
  1645.  
  1646.  
  1647.                                        24
  1648.  
  1649.  
  1650.  
  1651.  
  1652.  
  1653.  
  1654.  
  1655.  
  1656.  
  1657.  
  1658.           3.  Patterns
  1659.  
  1660.           3.1.  Pattern Variables, Patterns and Pattern Matching
  1661.  
  1662.           A pattern is a data object derived from symbolic expressions
  1663.           which is used primarily in the operation of pattern match-
  1664.           ing.  It consists of a pattern template which can be any
  1665.           symbolic expression and a variable binding context which is
  1666.           a symbolic expression of the form of the A_Table argument to
  1667.           the Associate routines described in the Symbolic Expressions
  1668.           section.  A pattern which has a null template and null bind-
  1669.           ing context is said to be a null pattern.  A constant,
  1670.           Null_Pattern, has been defined to represent this pattern.
  1671.           Examples of pattern templates:
  1672.  
  1673.               ()
  1674.               ?x
  1675.               a
  1676.               (a, b, c)
  1677.               (?x, 1983))
  1678.               (hit, ?x, ?z)
  1679.               ((hit, ?x, ?z), (hurt, ?z))
  1680.  
  1681.  
  1682.           Examples of variable binding contexts:
  1683.  
  1684.               ()
  1685.               ((?x, a))
  1686.               ((?x, John), (?z, Joe))
  1687.  
  1688.  
  1689.           The primary operation on patterns is pattern matching.  Pat-
  1690.           tern matching consists of comparing two patterns to see if
  1691.           they are equivalent or can be made equivalent.
  1692.  
  1693.           If the original symbolic expressions (from which the two
  1694.           patterns being compared were made) contain only atomic
  1695.           literals, the pattern matching operation only involves
  1696.           determining if the corresponding components in each pattern
  1697.           are equal.  If so, the patterns match.
  1698.  
  1699.           However, if either of the original symbolic expressions con-
  1700.           tain variables, the pattern matching operation is quite dif-
  1701.           ferent.  When a variable is encountered in either pattern
  1702.           during a matching operation, the corresponding component in
  1703.           the other pattern is bound to the variable.  Binding a com-
  1704.           ponent, the bound value, to a variable involves placing a
  1705.           copy of the bound value in the entry of the variable binding
  1706.           context for the variable.
  1707.  
  1708.           Once a pattern variable is bound, the bound value is used
  1709.           throughout the remainder of the matching process.  Any sub-
  1710.           sequent instances of the bound variable are replaced by its
  1711.  
  1712.  
  1713.                                        25
  1714.  
  1715.  
  1716.  
  1717.  
  1718.  
  1719.  
  1720.  
  1721.  
  1722.  
  1723.  
  1724.           bound value.  If a variable is bound to a literal, the sub-
  1725.           sequent instances of the variable are replaced by that
  1726.           literal.  If, however, one variable is bound to another, the
  1727.           subsequent instances of the first variable are replaced by
  1728.           the literal to which the second variable is bound.  If the
  1729.           second variable has not been bound yet, subsequent instances
  1730.           of the first variable are replaced by the second.  When the
  1731.           second variable becomes bound to a literal, all instances of
  1732.           both variables will be replaced by the same literal.  If the
  1733.           matching process completes with no inconsistent bindings
  1734.           (two possible literal values for the same variable) being
  1735.           found, the patterns are said to match.
  1736.  
  1737.           The following is a list of the available pattern operators.
  1738.           The parameters of the subprograms in the examples are
  1739.           representations of the variables supplied to the subpro-
  1740.           grams, not the parameters themselves.
  1741.  
  1742.  
  1743.  
  1744.  
  1745.  
  1746.  
  1747.  
  1748.  
  1749.  
  1750.  
  1751.  
  1752.  
  1753.  
  1754.  
  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.                                        26
  1780.  
  1781.  
  1782.  
  1783.  
  1784.  
  1785.  
  1786.  
  1787.  
  1788.  
  1789.  
  1790.           3.2.  Patterns Routines
  1791.  
  1792.           3.2.1.  Is_Null
  1793.  
  1794.           Interface:
  1795.  
  1796.               function Is_Null (Pattern_Arg : in Pattern)
  1797.                  return Boolean;
  1798.  
  1799.  
  1800.           Description:
  1801.                Determines if Pattern_Arg is a null pattern.
  1802.  
  1803.  
  1804.           3.2.2.  Is_Equal
  1805.  
  1806.           Interface:
  1807.  
  1808.               function Is_Equal (Pattern1, Pattern2 : in Pattern)
  1809.                  return Boolean;
  1810.  
  1811.  
  1812.           Description:
  1813.                Determines if Pattern1 is equal to Pattern2.  Two pat-
  1814.                terns are equal if their instantiated templates match.
  1815.                An instantiated template is a symbolic expression in
  1816.                which all variables in the template have been replaced
  1817.                by the values to which they are bound in variable bind-
  1818.                ing context. (See the description for function Instan-
  1819.                tiate below.)
  1820.  
  1821.           Examples:
  1822.  
  1823.                Bind (P1, Create_Pattern ( (?x, b, ?z) ))
  1824.                Bind (P2, Create_Pattern ( (?x, b, ?z) ))
  1825.                Is_Equal (P1, P2)  ==> TRUE
  1826.                Bind (P1, Create_Pattern ( (a, b, c) ))
  1827.                Bind (P2, Create_Pattern ( (?x, b, ?z) ))
  1828.                Is_Equal (P1, P2)  ==> FALSE
  1829.                Bind (P1, Create_Pattern ( (a, b, c) ))
  1830.                Bind (P2, Create_Pattern ( (?x, b, ?z),
  1831.                                           ((?x, a), (?z, c)) ))
  1832.                Is_Equal (P1, P2)  ==> TRUE
  1833.  
  1834.  
  1835.  
  1836.           3.2.3.  Create Pattern
  1837.  
  1838.           Interface:
  1839.  
  1840.               function Create_Pattern (Template : in S_Expr;
  1841.                                        Bindings : in S_Expr := Null_S_Expr)
  1842.                  return Pattern;
  1843.  
  1844.  
  1845.                                        27
  1846.  
  1847.  
  1848.  
  1849.  
  1850.  
  1851.  
  1852.  
  1853.  
  1854.  
  1855.  
  1856.           Description:
  1857.                Creates a pattern. The first argument represents the
  1858.                pattern template while the second forms the variable
  1859.                binding context.
  1860.  
  1861.           Examples:
  1862.  
  1863.                Bind (P, Create_Pattern ( (?x, b, ?z) ))
  1864.                Get_Template (P) ==> (?x, b, ?z)
  1865.                Get_Bindings (P) ==> ()
  1866.  
  1867.                Bind (P, Create_Pattern ( (?x, b, ?z),
  1868.                                          ((?x, a), (?z, c)) ))
  1869.                Get_Template (P) ==> (?x, b, ?z)
  1870.                Get_Bindings (P) ==> ((?x, a), (?z, c))
  1871.  
  1872.  
  1873.  
  1874.           3.2.4.  Tag_Variables
  1875.  
  1876.           Interface:
  1877.  
  1878.               procedure Tag_Variables (Pattern_Arg : in Pattern;
  1879.                                        Tag : in Natural);
  1880.  
  1881.  
  1882.           Description:
  1883.                Tags all variables within Pattern_Arg with the value of
  1884.                Tag thus providing a way of making patterns unique.
  1885.  
  1886.           Examples:
  1887.  
  1888.                Bind (P, Create_Pattern ( (?x, b, ?z) ))
  1889.                Tag_Variables (P, 1)
  1890.                Get_Template (P) ==> (?x1, b, ?z1)
  1891.                Get_Bindings (P) ==> ()
  1892.  
  1893.                Bind (P, Create_Pattern ( (?x, b, ?z), ((?x, a), (?z, c)) ))
  1894.                Tag_Variables (P, 1)
  1895.                Get_Template (P) ==> (?x1, b, ?z1)
  1896.                Get_Bindings (P) ==> ((?x1, a), (?z1, c))
  1897.  
  1898.  
  1899.  
  1900.           3.2.5.  Get_Template
  1901.  
  1902.           Interface:
  1903.  
  1904.               function Get_Template (Pattern_Arg : in Pattern)
  1905.                  return S_Expr;
  1906.  
  1907.  
  1908.  
  1909.  
  1910.  
  1911.                                        28
  1912.  
  1913.  
  1914.  
  1915.  
  1916.  
  1917.  
  1918.  
  1919.  
  1920.  
  1921.  
  1922.           Description:
  1923.                Returns the symbolic expression representing the pat-
  1924.                tern template for Pattern_Arg.
  1925.  
  1926.           Examples:
  1927.  
  1928.                Bind (P, Create_Pattern ( (?x, b, ?z) ))
  1929.                Get_Template (P) ==> (?x, b, ?z)
  1930.                Bind (P, Create_Pattern ( (?x, b, ?z), ((?x, a), (?z, c)) ))
  1931.                Get_Template (P) ==> (?x, b, ?z)
  1932.  
  1933.  
  1934.  
  1935.           3.2.6.  Get_Bindings
  1936.  
  1937.           Interface:
  1938.  
  1939.               function Get_Bindings (Pattern_Arg : in Pattern)
  1940.                  return S_Expr;
  1941.  
  1942.  
  1943.           Description:
  1944.                Returns the binding context for Pattern_Arg which is an
  1945.                S_Expr interpreted as a set of pairs, where each pair
  1946.                is an S_Expr whose First component is an atomic S_Expr
  1947.                such that Is_Variable is True, and whose Rest component
  1948.                is the value bound to the variable.
  1949.  
  1950.           Examples:
  1951.  
  1952.                Bind (P, Create_Pattern ( (?x, b, ?z) ))
  1953.                Get_Bindings (P) ==> ()
  1954.                Bind (P, Create_Pattern ( (?x, b, ?z), ((?x, a), (?z, c)) ))
  1955.                Get_Bindings (P) ==> ((?x, a), (?z, c))
  1956.  
  1957.  
  1958.  
  1959.           3.2.7.  Set_Bindings
  1960.  
  1961.           Interface:
  1962.  
  1963.               function Set_Bindings (Pattern_Arg : in Pattern;
  1964.                                      Bindings : in S_Expr)
  1965.                  return Pattern;
  1966.  
  1967.  
  1968.           Description:
  1969.                Sets the variable binding context for Pattern_Arg to
  1970.                Bindings.
  1971.  
  1972.           Examples:
  1973.  
  1974.                Bind (P, Create_Pattern ( (?x, b, ?z) ))
  1975.  
  1976.  
  1977.                                        29
  1978.  
  1979.  
  1980.  
  1981.  
  1982.  
  1983.  
  1984.  
  1985.  
  1986.  
  1987.  
  1988.                Get_Bindings (P) ==> ()
  1989.                Bind (P, Set_Bindings ( P, ((?x, a), (?z, c)) ))
  1990.                Get_Bindings (P) ==> ((?x, a), (?z, c))
  1991.  
  1992.  
  1993.  
  1994.           3.2.8.  Instantiate
  1995.  
  1996.           Interface:
  1997.  
  1998.               function Instantiate (Pattern_Arg : in Pattern)
  1999.                  return S_Expr;
  2000.  
  2001.  
  2002.           Description:
  2003.                Returns the symbolic expression representing the pat-
  2004.                tern template for Pattern_Arg with all occurrences of
  2005.                variables replaced by the values to which they are
  2006.                bound.
  2007.  
  2008.           Examples:
  2009.  
  2010.                Bind (P, Create_Pattern ( (?x, b, ?z) ))
  2011.                Instantiate (P)  ==> (?x, b, ?z)
  2012.                Bind (P, Set_Bindings ( P, ((?x, a), (?z, c)) ))
  2013.                Instantiate (P)  ==> (a, b, c)
  2014.  
  2015.  
  2016.  
  2017.           3.2.9.  Match
  2018.  
  2019.           Interface:
  2020.  
  2021.               procedure Match (Pattern1, Pattern2 : in out Pattern;
  2022.                                Is_Match : out Boolean);
  2023.  
  2024.  
  2025.           Description:
  2026.                If the patterns associated with Pattern1 and Pattern2
  2027.                can be made identical by variable substitution,
  2028.                Is_Match will be True and the variable binding contexts
  2029.                of Pattern1 and Pattern2 will contain the variable
  2030.                bindings; otherwise, the binding contexts will remain
  2031.                unchanged and Is_Match will be False.
  2032.  
  2033.           Examples:
  2034.  
  2035.                Bind (P1, Create_Pattern ( (a, b, c) ))
  2036.                Bind (P2, Create_Pattern ( (?x, ?y, ?z) ))
  2037.                Match (P1, P2, Is_Match)  ==> Is_Match = TRUE
  2038.                Get_Bindings (P1) ==> ()
  2039.                Get_Bindings (P2) ==> ((?x, a), (?y, b), (?z, c))
  2040.                Instantiate (P1) ==> (a, b, c)
  2041.  
  2042.  
  2043.                                        30
  2044.  
  2045.  
  2046.  
  2047.  
  2048.  
  2049.  
  2050.  
  2051.  
  2052.  
  2053.  
  2054.                Instantiate (P2) ==> (a, b, c)
  2055.  
  2056.                Bind (P1, Create_Pattern ( (?x, b, ?z) ))
  2057.                Bind (P2, Create_Pattern ( (a, ?y, b) ))
  2058.                Match (P1, P2, Is_Match)  ==> Is_Match = TRUE
  2059.                Get_Bindings (P1) ==> ((?x, a), (?z, c))
  2060.                Get_Bindings (P2) ==> ((?y, b))
  2061.                Instantiate (P1) ==> (a, b, c)
  2062.                Instantiate (P2) ==> (a, b, c)
  2063.  
  2064.                Bind (P1, Create_Pattern ( (?x, b, c) ))
  2065.                Bind (P2, Create_Pattern ( (a, ?y, d) ))
  2066.                Match (P1, P2, Is_Match)  ==> Is_Match = FALSE
  2067.                Get_Bindings (P1) ==> ()
  2068.                Get_Bindings (P2) ==> ()
  2069.                Instantiate (P1) ==> (?x, b, c)
  2070.                Instantiate (P2) ==> (a, ?y, d)
  2071.  
  2072.  
  2073.  
  2074.           3.2.10.  First
  2075.  
  2076.           Interface:
  2077.  
  2078.               function First (Pattern_Arg : in Pattern)
  2079.                  return Pattern;
  2080.  
  2081.  
  2082.           Description:
  2083.                Returns a pattern consisting of the first component of
  2084.                the template of Pattern_Arg along with its full vari-
  2085.                able binding context.
  2086.  
  2087.           Restrictions:
  2088.                The template for Pattern_Arg must be a non-null, non-
  2089.                atomic expression.  If not, the exception
  2090.                Atomic_Template is raised.
  2091.  
  2092.           Examples:
  2093.  
  2094.                Bind (P, Create_Pattern ( (?x, b, ?z) ))
  2095.                Get_Template (P) ==> (?x, b, ?z)
  2096.                Get_Bindings (P) ==> ()
  2097.                Bind (P, First (P))
  2098.                Get_Template (P) ==> ?x
  2099.                Get_Bindings (P) ==> ()
  2100.  
  2101.                Bind (P, Create_Pattern ( (?x, b, ?z), ((?x, a), (?z, b)) ))
  2102.                Get_Template (P) ==> (?x, b, ?z)
  2103.                Get_Bindings (P) ==> ((?x, a), (?z, b))
  2104.                Bind (P, First (P))
  2105.                Get_Template (P) ==> ?x
  2106.                Get_Bindings (P) ==> ((?x, a), (?z, b))
  2107.  
  2108.  
  2109.                                        31
  2110.  
  2111.  
  2112.  
  2113.  
  2114.  
  2115.  
  2116.  
  2117.  
  2118.  
  2119.  
  2120.           3.2.11.  Rest
  2121.  
  2122.           Interface:
  2123.  
  2124.               function Rest (Pattern_Arg : in Pattern)
  2125.                  return Pattern;
  2126.  
  2127.  
  2128.           Description:
  2129.                Returns a pattern consisting of the rest component of
  2130.                the template of Pattern_Arg along with its full vari-
  2131.                able binding context.
  2132.  
  2133.           Restrictions:
  2134.                The template for Pattern_Arg must be a non-null, non-
  2135.                atomic expression.  If not, the exception
  2136.                Atomic_Template is raised.
  2137.  
  2138.           Examples:
  2139.  
  2140.                Bind (P, Create_Pattern ( (?x, b, ?z) ))
  2141.                Get_Template (P) ==> (?x, b, ?z)
  2142.                Get_Bindings (P) ==> ()
  2143.                Bind (P, Rest (P))
  2144.                Get_Template (P) ==> (b, ?z)
  2145.                Get_Bindings (P) ==> ()
  2146.  
  2147.                Bind (P, Create_Pattern ( (?x, b, ?z), ((?x, a), (?z, b)) ))
  2148.                Get_Template (P) ==> (?x, b, ?z)
  2149.                Get_Bindings (P) ==> ((?x, a), (?z, b))
  2150.                Bind (P, Rest (P))
  2151.                Get_Template (P) ==> (b, ?z)
  2152.                Get_Bindings (P) ==> ((?x, a), (?z, b))
  2153.  
  2154.  
  2155.  
  2156.           3.2.12.  Bind
  2157.  
  2158.           Interface:
  2159.  
  2160.               procedure Bind (Current_Value : in out Pattern;
  2161.                               New_Value : in Pattern);
  2162.  
  2163.  
  2164.           Description:
  2165.                Assignment operation for patterns.
  2166.  
  2167.  
  2168.           3.2.13.  Free and Return_And_Free
  2169.  
  2170.           Interface:
  2171.  
  2172.               procedure Free (Pattern_Arg : in out Pattern);
  2173.  
  2174.  
  2175.                                        32
  2176.  
  2177.  
  2178.  
  2179.  
  2180.  
  2181.  
  2182.  
  2183.  
  2184.  
  2185.  
  2186.               function Return_And_Free (Pattern_Arg : in Pattern)
  2187.                  return Pattern;
  2188.  
  2189.  
  2190.           Description:
  2191.                Dynamic object deallocation operations for patterns.
  2192.                The conventions followed for deallocating symbolic
  2193.                expressions should also be followed when using pat-
  2194.                terns.
  2195.  
  2196.  
  2197.           3.2.14.  Get and Put
  2198.  
  2199.           Interface:
  2200.  
  2201.               procedure Get (Input_File : in File_Type;
  2202.                              Pattern_Result : in out Pattern);
  2203.               procedure Get (Pattern_Result : in out Pattern);
  2204.               procedure Put (Output_File : in File_Type;
  2205.                              Pattern_Arg : in Pattern);
  2206.               procedure Put (Pattern_Arg : in Pattern);
  2207.  
  2208.  
  2209.           Description:
  2210.                Input/output operations for patterns.  Get reads a pat-
  2211.                tern template (from the given input file or the current
  2212.                default input file) and creates a pattern with the tem-
  2213.                plate and a null binding context.  Put prints the
  2214.                instantiated pattern template for the given pattern to
  2215.                the given output file or the current default output
  2216.                file.
  2217.  
  2218.  
  2219.  
  2220.  
  2221.  
  2222.  
  2223.  
  2224.  
  2225.  
  2226.  
  2227.  
  2228.  
  2229.  
  2230.  
  2231.  
  2232.  
  2233.  
  2234.  
  2235.  
  2236.  
  2237.  
  2238.  
  2239.  
  2240.  
  2241.                                        33
  2242.  
  2243.  
  2244.  
  2245.  
  2246.  
  2247.  
  2248.  
  2249.  
  2250.  
  2251.  
  2252.           4.  Rules
  2253.  
  2254.           4.1.  Description of Rules
  2255.  
  2256.           A rule is a specific type of pattern.  Rules differ from
  2257.           general patterns in that a rule's template contains two sym-
  2258.           bolic expressions which represent the (possibly null)
  2259.           antecedent and (possibly null) consequent of a rule.   The
  2260.           variable binding contexts for rules take the same form as
  2261.           those for patterns.
  2262.  
  2263.           There are four types of rules: facts, queries, rules and the
  2264.           null rule.  A fact is a rule with a null antecedent and
  2265.           non-null consequent.  A query is a rule with a non-null
  2266.           antecedent and null consequent.  A rule has both a non-null
  2267.           antecedent and  non-null consequent.  The null rule has both
  2268.           a null template and null binding context and is represented
  2269.           by a defined constant, Null_Rule.  Examples of rule tem-
  2270.           plates:
  2271.  
  2272.               ((), ())                       -- null template
  2273.               ((), (hurt, ?z))               -- fact
  2274.               ((hit, ?x, ?z), ())            -- query
  2275.               ((hit, ?x, ?z), (hurt, ?z))    -- rule
  2276.  
  2277.  
  2278.           4.2.  Rule Routines
  2279.  
  2280.           4.2.1.  Create_Rule
  2281.  
  2282.           Interface:
  2283.  
  2284.               function Create_Rule (Antecedent,
  2285.                                     Consequent,
  2286.                                     Bindings : in S_Expr := Null_S_Expr)
  2287.                  return Rule;
  2288.  
  2289.  
  2290.           Description:
  2291.                Creates a rule composed of the given components.
  2292.  
  2293.           Examples:
  2294.  
  2295.                Bind (R, Create_Rule ( (hit, ?x, ?z), () ))
  2296.                Get_Template (R) ==> ((hit, ?x, ?z), ())
  2297.                Get_Bindings (R) ==> ()
  2298.  
  2299.                Bind (R, Create_Rule ( (), (hurt ?z), ((?z, John)) ))
  2300.                Get_Template (R) ==> ((), (hurt ?z))
  2301.                Get_Bindings (R) ==> ((?z, John))
  2302.  
  2303.                Bind (R, Create_Rule ( (hit, ?x, ?z), (hurt ?z),
  2304.                                       ((?z, John)) ))
  2305.  
  2306.  
  2307.                                        34
  2308.  
  2309.  
  2310.  
  2311.  
  2312.  
  2313.  
  2314.  
  2315.  
  2316.  
  2317.  
  2318.                Get_Template (R) ==> ((hit, ?x, ?z), (hurt ?z))
  2319.                Get_Bindings (R) ==> ((?z, John))
  2320.  
  2321.  
  2322.  
  2323.           4.2.2.  Tag_Variables
  2324.  
  2325.           Interface:
  2326.  
  2327.               procedure Tag_Variables (Rule_Arg : in Rule;
  2328.                                        Tag : in Natural);
  2329.  
  2330.  
  2331.           Description:
  2332.                Tags all variables within Rule_Arg with the value of
  2333.                Tag thus providing a way of making rules unique.
  2334.  
  2335.  
  2336.           4.2.3.  Antecedent
  2337.  
  2338.           Interface:
  2339.  
  2340.               function Antecedent (Rule_Arg : in Rule)
  2341.                  return Pattern;
  2342.  
  2343.  
  2344.           Description:
  2345.                Returns the antecedent of the given rule along with the
  2346.                complete binding context for the rule.
  2347.  
  2348.           Examples:
  2349.  
  2350.                Bind (R, Create_Rule ( (hit, ?x, ?z), () ))
  2351.                Bind (P, Antecedent (R))
  2352.                Get_Template (P) ==> (hit ?x, ?z)
  2353.                Get_Bindings (P) ==> ()
  2354.  
  2355.                Bind (R, Create_Rule ( (), (hurt ?z), ((?z, John)) ))
  2356.                Bind (P, Antecedent (R))
  2357.                Get_Template (P) ==> ()
  2358.                Get_Bindings (P) ==> ((?z, John))
  2359.  
  2360.                Bind (R, Create_Rule ( (hit, ?x, ?z), (hurt ?z),
  2361.                                       ((?z, John)) ))
  2362.                Bind (P, Antecedent (R))
  2363.                Get_Template (P) ==> (hit, ?x, ?z)
  2364.                Get_Bindings (P) ==> ((?z, John))
  2365.  
  2366.  
  2367.  
  2368.  
  2369.  
  2370.  
  2371.  
  2372.  
  2373.                                        35
  2374.  
  2375.  
  2376.  
  2377.  
  2378.  
  2379.  
  2380.  
  2381.  
  2382.  
  2383.  
  2384.           4.2.4.  Consequent
  2385.  
  2386.           Interface:
  2387.  
  2388.               function Consequent (Rule_Arg : in Rule)
  2389.                  return Pattern;
  2390.  
  2391.  
  2392.           Description:
  2393.                Returns the consequent of the given rule along with the
  2394.                complete binding context for the rule.
  2395.  
  2396.           Examples:
  2397.  
  2398.                Bind (R, Create_Rule ( (hit, ?x, ?z), () ))
  2399.                Bind (P, Consequent (R))
  2400.                Get_Template (P) ==> ()
  2401.                Get_Bindings (P) ==> ()
  2402.  
  2403.                Bind (R, Create_Rule ( (), (hurt ?z), ((?z, John)) ))
  2404.                Bind (P, Consequent (R))
  2405.                Get_Template (P) ==> (hurt ?z)
  2406.                Get_Bindings (P) ==> ((?z, John))
  2407.  
  2408.                Bind (R, Create_Rule ( (hit, ?x, ?z), (hurt ?z),
  2409.                                       ((?z, John)) ))
  2410.                Bind (P, Consequent (R))
  2411.                Get_Template (P) ==> (hurt ?z)
  2412.                Get_Bindings (P) ==> ((?z, John))
  2413.  
  2414.  
  2415.  
  2416.           4.2.5.  Is_Null
  2417.  
  2418.           Interface:
  2419.  
  2420.               function Is_Null (Rule_Arg : in Rule)
  2421.                  return Boolean;
  2422.  
  2423.  
  2424.           Description:
  2425.                Determines if Rule_Arg is a null rule.
  2426.  
  2427.  
  2428.           4.2.6.  Is_Equal
  2429.  
  2430.           Interface:
  2431.  
  2432.               function Is_Equal (Rule1, Rule2 : in Pattern)
  2433.                  return Boolean;
  2434.  
  2435.  
  2436.  
  2437.  
  2438.  
  2439.                                        36
  2440.  
  2441.  
  2442.  
  2443.  
  2444.  
  2445.  
  2446.  
  2447.  
  2448.  
  2449.  
  2450.           Description:
  2451.                Determines if Rule1 is equal to Rule2.  As in the Pat-
  2452.                terns package, two rules are considered equal if their
  2453.                instantiated templates are equivalent.
  2454.  
  2455.  
  2456.           4.2.7.  Is_Query
  2457.  
  2458.           Interface:
  2459.  
  2460.               function Is_Query (Rule_Arg : in Rule)
  2461.                  return Boolean;
  2462.  
  2463.  
  2464.           Description:
  2465.                Determines if the given rule is a query.  A query is a
  2466.                rule which has a non-null antecedent and null conse-
  2467.                quent.
  2468.  
  2469.           Examples:
  2470.  
  2471.                Bind (R, Create_Rule ( (hit, ?x, ?z), () ))
  2472.                Is_Query (R)  ==>  TRUE
  2473.                Bind (R, Create_Rule ( (), (hurt ?z), ((?z, John)) ))
  2474.                Is_Query (R)  ==>  FALSE
  2475.                Bind (R, Create_Rule ( (hit, ?x, ?z), (hurt ?z),
  2476.                                       ((?z, John)) ))
  2477.                Is_Query (R)  ==>  FALSE
  2478.  
  2479.  
  2480.  
  2481.           4.2.8.  Is_Fact
  2482.  
  2483.           Interface:
  2484.  
  2485.               function Is_Fact (Rule_Arg : in Rule)
  2486.                  return Boolean;
  2487.  
  2488.  
  2489.           Description:
  2490.                Determines if the given rule is a fact.  A fact is a
  2491.                rule which has a null antecedent and non-null conse-
  2492.                quent.
  2493.  
  2494.           Examples:
  2495.  
  2496.                Bind (R, Create_Rule ( (hit, ?x, ?z), () ))
  2497.                Is_Fact (R)  ==>  FALSE
  2498.                Bind (R, Create_Rule ( (), (hurt ?z), ((?z, John)) ))
  2499.                Is_Fact (R)  ==>  TRUE
  2500.                Bind (R, Create_Rule ( (hit, ?x, ?z), (hurt ?z),
  2501.                                       ((?z, John)) ))
  2502.                Is_Fact (R)  ==>  FALSE
  2503.  
  2504.  
  2505.                                        37
  2506.  
  2507.  
  2508.  
  2509.  
  2510.  
  2511.  
  2512.  
  2513.  
  2514.  
  2515.  
  2516.           4.2.9.  Is_Rule
  2517.  
  2518.               function Is_Rule (Rule_Arg : in Rule)
  2519.                  return Boolean;
  2520.  
  2521.  
  2522.           Description:
  2523.                Determines if the given rule is a general rule.  A gen-
  2524.                eral rule is a rule which has a non-null antecedent and
  2525.                a non-null consequent.
  2526.  
  2527.           Examples:
  2528.  
  2529.                Bind (R, Create_Rule ( (hit, ?x, ?z), () ))
  2530.                Is_Rule (R)  ==>  FALSE
  2531.                Bind (R, Create_Rule ( (), (hurt ?z), ((?z, John)) ))
  2532.                Is_Rule (R)  ==>  FALSE
  2533.                Bind (R, Create_Rule ( (hit, ?x, ?z), (hurt ?z),
  2534.                                       ((?z, John)) ))
  2535.                Is_Rule (R)  ==>  TRUE
  2536.  
  2537.  
  2538.  
  2539.           4.2.10.  Get_Template
  2540.  
  2541.           Interface:
  2542.  
  2543.               function Get_Template (Rule_Arg : in Rule)
  2544.                  return S_Expr;
  2545.  
  2546.  
  2547.           Description:
  2548.                Returns the symbolic expression representing the rule
  2549.                template for Rule_Arg.
  2550.  
  2551.  
  2552.           4.2.11.  Get_Bindings
  2553.  
  2554.           Interface:
  2555.  
  2556.               function Get_Bindings (Rule_Arg : in Rule)
  2557.                  return S_Expr;
  2558.  
  2559.  
  2560.           Description:
  2561.                Returns the binding context for Rule_Arg which is an
  2562.                S_Expr interpreted as a set of pairs, where each pair
  2563.                is an S_Expr whose First component is an atomic S_Expr
  2564.                such that Is_Variable is True, and whose Rest component
  2565.                is the value bound to the variable.
  2566.  
  2567.  
  2568.  
  2569.  
  2570.  
  2571.                                        38
  2572.  
  2573.  
  2574.  
  2575.  
  2576.  
  2577.  
  2578.  
  2579.  
  2580.  
  2581.  
  2582.           4.2.12.  Set_Bindings
  2583.  
  2584.           Interface:
  2585.  
  2586.               function Set_Bindings (Rule_Arg : in Rule;
  2587.                                      Bindings : in S_Expr)
  2588.                  return Rule;
  2589.  
  2590.  
  2591.           Description:
  2592.                Sets the variable binding context for Rule_Arg to Bind-
  2593.                ings.
  2594.  
  2595.  
  2596.           4.2.13.  Instantiate
  2597.  
  2598.           Interface:
  2599.  
  2600.               function Instantiate (Rule_Arg : in Rule)
  2601.                  return S_Expr;
  2602.  
  2603.  
  2604.           Description:
  2605.                Returns the symbolic expression representing the rule
  2606.                template for Rule_Arg with all occurrences of variables
  2607.                replaced by the values to which they are bound.
  2608.  
  2609.  
  2610.           4.2.14.  Match
  2611.  
  2612.           Interface:
  2613.  
  2614.               procedure Match (Rule1, Rule2 : in out Pattern;
  2615.                                Is_Match : out Boolean);
  2616.  
  2617.  
  2618.           Description:
  2619.                If the patterns associated with Rule1 and Rule2 can be
  2620.                made identical by variable substitution, Is_Match will
  2621.                be True and the variable binding contexts of Rule1 and
  2622.                Rule2 will contain the variable bindings; otherwise,
  2623.                the binding contexts will remain unchanged and Is_Match
  2624.                will be False.
  2625.  
  2626.  
  2627.           4.2.15.  Bind
  2628.  
  2629.           Interface:
  2630.  
  2631.               procedure Bind (Current_Value : in out Rule;
  2632.                               New_Value : in Rule);
  2633.  
  2634.  
  2635.  
  2636.  
  2637.                                        39
  2638.  
  2639.  
  2640.  
  2641.  
  2642.  
  2643.  
  2644.  
  2645.  
  2646.  
  2647.  
  2648.           Description:
  2649.                Assignment operation for rules.
  2650.  
  2651.  
  2652.           4.2.16.  Free and Return_And_Free
  2653.  
  2654.           Interface:
  2655.  
  2656.               procedure Free (Rule_Arg : in out Rule);
  2657.               function Return_And_Free (Rule_Arg : in Rule)
  2658.                  return Rule;
  2659.  
  2660.  
  2661.           Description:
  2662.                Dynamic object deallocation operations for rules.  The
  2663.                conventions followed for deallocating symbolic expres-
  2664.                sions should also be followed when using rules.
  2665.  
  2666.  
  2667.           4.2.17.  Get and Put
  2668.  
  2669.           Interface:
  2670.  
  2671.               procedure Get (Input_File : in File_Type;
  2672.                              Rule_Result : in out Rule);
  2673.               procedure Get (Rule_Result : in out Rule);
  2674.               procedure Put (Output_File : in File_Type;
  2675.                              Rule_Arg : in Rule);
  2676.               procedure Put (Rule_Arg : in Rule);
  2677.  
  2678.  
  2679.           Description:
  2680.                Input/output operations for rules.  Get reads a rule
  2681.                template from the given file or current default input
  2682.                file creating a rule with the read template and a null
  2683.                binding context.  Put prints the instantiated rule tem-
  2684.                plate to the given file or the current default output
  2685.                file.
  2686.  
  2687.           Restrictions:
  2688.                In the Get routines, the input template must contain
  2689.                exactly two components, one for the antecedent, the
  2690.                other for the consequent.  If not, the exception
  2691.                Invalid_Rule_Format is raised.
  2692.  
  2693.  
  2694.  
  2695.  
  2696.  
  2697.  
  2698.  
  2699.  
  2700.  
  2701.  
  2702.  
  2703.                                        40
  2704.  
  2705.  
  2706.  
  2707.  
  2708.  
  2709.  
  2710.  
  2711.  
  2712.  
  2713.  
  2714.           5.  Rulebases
  2715.  
  2716.           5.1.  Definition of Rulebase
  2717.  
  2718.           A rulebase is an indexed collection of rules representing
  2719.           facts and general rules.  A rulebase which has no rules is
  2720.           said to be null.  A constant, Null_Rulebase, represents the
  2721.           null rulebase.   A rulebase template is a symbolic expres-
  2722.           sion containing the templates of all rules in the rulebase.
  2723.           Examples of rulebase templates:
  2724.  
  2725.               (((), ()),
  2726.                ((), (hurt, John)),
  2727.                ((hit, ?x, ?z), (hurt, ?z))
  2728.               )
  2729.  
  2730.               (((loves, ?x1, ?y1), (friends, ?x1, ?y1)),
  2731.                ((wife, ?x2, ?y2), (loves, ?x2, ?y2)),
  2732.                ((), (wife, Mary, John)),
  2733.                ((), (loves, Mary, Joe)),
  2734.               )
  2735.  
  2736.  
  2737.           NOTE: Variable names are global to the entire rulebase.  If
  2738.           it is necessary to limit the scope of a variable to a single
  2739.           pattern, use the rule function Tag_Variables to make the
  2740.           rule unique with respect to other rules in the rulebase
  2741.           before adding the rule to the rulebase.
  2742.  
  2743.           The three primary operations performed on rulebases are
  2744.           assertion (adding a fact or general rule to a rulebase),
  2745.           retraction (deleting a fact or general rule from a rulebase)
  2746.           and deductive retrieval (examining the rules in a rulebase
  2747.           to determine the answer to a supplied query).
  2748.  
  2749.           The retrieval operation involves an operation known as back-
  2750.           ward chaining.  The antecedent of the supplied query is
  2751.           matched against the consequents of the entries in the
  2752.           rulebase.  If the entry is is a fact and the match succeeds,
  2753.           the instantiated query antecedent is added to the result.
  2754.           Otherwise, if the entry is a general rule and the match
  2755.           succeeds, the antecedent of the general rule involved in the
  2756.           match is recursively passed to another invocation of the
  2757.           retrieval operation.  This backward chain continues until a
  2758.           fact is found which matches the current query (in which case
  2759.           the bindings found during the chaining process are used to
  2760.           instantiate the original query which is then added to the
  2761.           result) or until a match cannot be found.  The symbolic
  2762.           expression containing the instantiated queries is then
  2763.           returned.
  2764.  
  2765.  
  2766.  
  2767.  
  2768.  
  2769.                                        41
  2770.  
  2771.  
  2772.  
  2773.  
  2774.  
  2775.  
  2776.  
  2777.  
  2778.  
  2779.  
  2780.           5.2.  Rulebase Routines
  2781.  
  2782.           5.2.1.  Is_Null
  2783.  
  2784.           Interface:
  2785.  
  2786.               function Is_Null (Rulebase_Arg : in Rulebase)
  2787.                  return Boolean;
  2788.  
  2789.  
  2790.           Description:
  2791.                Determines if the given rulebase is empty (contains no
  2792.                rules).
  2793.  
  2794.  
  2795.           5.2.2.  Is_Equal
  2796.  
  2797.           Interface:
  2798.  
  2799.               function Is_Equal (Rulebase1, Rulebase2 : in Rulebase)
  2800.                  return Boolean;
  2801.  
  2802.  
  2803.           Description:
  2804.                Determines if two rulebases are equivalent.   Two rule-
  2805.                bases are equivalent if they contain the same set of
  2806.                rules.  NOTE:  The rules in the two rulebases do not
  2807.                have to be in the same order to be considered
  2808.                equivalent.
  2809.  
  2810.  
  2811.           5.2.3.  Create_Rulebase
  2812.  
  2813.           Interface:
  2814.  
  2815.               function Create_Rulebase (Template : in S_Expr)
  2816.                  return Rulebase;
  2817.  
  2818.  
  2819.           Description:
  2820.                Creates a rulebase with a template based on the given
  2821.                symbolic expression.
  2822.  
  2823.  
  2824.           5.2.4.  Get_Template
  2825.  
  2826.           Interface:
  2827.  
  2828.               function Get_Template (Rulebase_Arg : in Rulebase)
  2829.                  return S_Expr;
  2830.  
  2831.  
  2832.  
  2833.  
  2834.  
  2835.                                        42
  2836.  
  2837.  
  2838.  
  2839.  
  2840.  
  2841.  
  2842.  
  2843.  
  2844.  
  2845.  
  2846.           Description:
  2847.                Returns a symbolic expression representing the template
  2848.                for the given rulebase.
  2849.  
  2850.  
  2851.           5.2.5.  Assert
  2852.  
  2853.           Interface:
  2854.  
  2855.               procedure Assert (Rule_Arg : in Rule;
  2856.                                 Rulebase_Arg : in out Rulebase);
  2857.  
  2858.  
  2859.           Description:
  2860.                Adds a rule to the specified rulebase.
  2861.  
  2862.           Example:
  2863.  
  2864.                Bind (RB, Null_Rulebase)
  2865.                Get_Template (RB) ==> ()
  2866.                Assert ( RB, ((), (wife, Mary, John)) )
  2867.                Get_Template (RB) ==> (((), (wife, Mary, John)))
  2868.                Assert ( RB, ((wife, ?x2, ?y2), (loves, ?x2, ?y2)) )
  2869.                Get_Template (RB) ==> (((), (wife, Mary, John))
  2870.                                       ((wife, ?x2, ?y2), (loves, ?x2, ?y2)))
  2871.  
  2872.  
  2873.  
  2874.           5.2.6.  Retract
  2875.  
  2876.           Interface:
  2877.  
  2878.               procedure Retract (Rule_Arg : in Rule;
  2879.                                  Rulebase_Arg : in out Rulebase);
  2880.  
  2881.  
  2882.           Description:
  2883.                Deletes a rule (if it exists) from the specified
  2884.                rulebase.
  2885.  
  2886.           Example:
  2887.  
  2888.                Bind (RB, Null_Rulebase)
  2889.                Get_Template (RB) ==> ()
  2890.                Assert ( RB, ((), (wife, Mary, John)) )
  2891.                Get_Template (RB) ==> (((), (wife, Mary, John)))
  2892.                Assert ( RB, ((wife, ?x2, ?y2), (loves, ?x2, ?y2)) )
  2893.                Get_Template (RB) ==> (((), (wife, Mary, John))
  2894.                                       ((wife, ?x2, ?y2), (loves, ?x2, ?y2)))
  2895.                Retract ( RB, ((), (wife, Mary, John)) )
  2896.                Get_Template (RB) ==> (((wife, ?x2, ?y2), (loves, ?x2, ?y2)))
  2897.  
  2898.  
  2899.  
  2900.  
  2901.                                        43
  2902.  
  2903.  
  2904.  
  2905.  
  2906.  
  2907.  
  2908.  
  2909.  
  2910.  
  2911.  
  2912.           5.2.7.  Retrieve
  2913.  
  2914.           Interface:
  2915.  
  2916.               function Retrieve (Rule_Arg : in Rule;
  2917.                                  Rulebase_Arg : in Rulebase)
  2918.                  return S_Expr;
  2919.  
  2920.  
  2921.           Description:
  2922.                Returns a symbolic expression containing instantiated
  2923.                versions of the rules which matched the input Rule_Arg.
  2924.  
  2925.           Example:
  2926.  
  2927.                Create_Rulebase (RB,
  2928.                                 (
  2929.                                  (((loves, ?x1, ?y1), (friends, ?x1, ?y1)),
  2930.                                   ((wife, ?x2, ?y2), (loves, ?x2, ?y2)),
  2931.                                   ((), (wife, Mary, John)),
  2932.                                   ((), (loves, Mary, Joe)),
  2933.                                  )
  2934.                                 ))
  2935.                Retrieve (RB, ((friends, Mary, ?x), ()) )  ==>
  2936.                   ((friends, Mary, Joe), (friends, Mary, John))
  2937.  
  2938.  
  2939.  
  2940.           5.2.8.  And (Intersection), Or (Union), - (Difference) and
  2941.           Xor (Excluded Union)
  2942.  
  2943.           Interface:
  2944.  
  2945.               function "And" (Rulebase1, Rulebase2 : in Rulebase)
  2946.                  return Rulebase;
  2947.               function "Or"  (Rulebase1, Rulebase2 : in Rulebase)
  2948.                  return Rulebase;
  2949.               function "-"   (Rulebase1, Rulebase2 : in Rulebase)
  2950.                  return Rulebase;
  2951.               function "Xor" (Rulebase1, Rulebase2 : in Rulebase)
  2952.                  return Rulebase;
  2953.  
  2954.  
  2955.           Description:
  2956.                These operations treat rulebases as sets returning the
  2957.                appropriate combination of rules.
  2958.  
  2959.  
  2960.           5.2.9.  Bind
  2961.  
  2962.           Interface:
  2963.  
  2964.               procedure Bind (Current_Value : in out Rulebase;
  2965.  
  2966.  
  2967.                                        44
  2968.  
  2969.  
  2970.  
  2971.  
  2972.  
  2973.  
  2974.  
  2975.  
  2976.  
  2977.  
  2978.                               New_Value : in Rulebase);
  2979.  
  2980.  
  2981.           Description:
  2982.                Assignment operation for rulebases.
  2983.  
  2984.  
  2985.           5.2.10.  Free and Return_And_Free
  2986.  
  2987.           Interface:
  2988.  
  2989.               procedure Free (Rule_Arg : in out Rulebase);
  2990.               function Return_And_Free (Rule_Arg : in Rulebase)
  2991.                  return Rule;
  2992.  
  2993.  
  2994.           Description:
  2995.                Dynamic object deallocation operations for rulebases.
  2996.                The conventions followed for deallocating symbolic
  2997.                expressions should also be followed when using rule-
  2998.                bases.
  2999.  
  3000.  
  3001.           5.2.11.  Get and Put
  3002.  
  3003.           Interface:
  3004.  
  3005.               procedure Get (Input_File : in File_Type;
  3006.                              Rule_Result : in out Rulebase);
  3007.               procedure Get (Rule_Result : in out Rulebase);
  3008.               procedure Put (Output_File : in File_Type;
  3009.                              Rule_Arg : in Rulebase);
  3010.               procedure Put (Rule_Arg : in Rulebase);
  3011.  
  3012.  
  3013.           Description:
  3014.                Input/output operations for rulebases.   The Get rou-
  3015.                tines create a rulebase with a rulebase template based
  3016.                upon the symbolic expression read from the given or
  3017.                current default input file.  The Put routines print the
  3018.                rulebase template for the rulebase out to the given or
  3019.                current default output file.
  3020.  
  3021.  
  3022.  
  3023.  
  3024.  
  3025.  
  3026.  
  3027.  
  3028.  
  3029.  
  3030.  
  3031.  
  3032.  
  3033.                                        45
  3034.  
  3035.  
  3036.  
  3037.  
  3038.  
  3039.  
  3040.  
  3041.  
  3042.  
  3043.  
  3044.           6.  Using the AI Data Types Package
  3045.  
  3046.           6.1.  Instantiating the Package
  3047.  
  3048.           In order to use the AI Data Types package, it must first be
  3049.           instantiated with five parameters.  The first parameter is
  3050.           the type which defines the possible values of the atomic
  3051.           expressions.  This may be any predefined or user-defined Ada
  3052.           type with the exception of limited private and task types.
  3053.           Note: The atomic expression type can be defined as a
  3054.           discriminated record type to allow the use of different
  3055.           types within one symbolic expression.  This user-supplied
  3056.           type will be referred to as type Atomic_Literal within the
  3057.           package and will be treated as a private type.
  3058.  
  3059.           The second parameter, Is_Equal, is a function which defines
  3060.           equality between two values of type Atomic_Literal.
  3061.  
  3062.           The third parameter, Lookahead, is a character which is used
  3063.           to communicate between the input routine provided by the
  3064.           user when instantiating the package and the input routine
  3065.           used to read the AI data types.  A specific protocol must be
  3066.           used when accessing the Lookahead character.
  3067.  
  3068.           (1)  The Lookahead character must be the first character
  3069.                examinined by any Get routine using it.
  3070.  
  3071.           (2)  After reading it, the Lookahead character must be set
  3072.                to a blank.
  3073.  
  3074.           The fourth parameter, Get, is a function which will allow
  3075.           input of type Atomic_Literal to be read from a specified
  3076.           input file.  This routine must follow the above protocol
  3077.           when accessing the Lookahead character and must stop reading
  3078.           input if a non-atomic suffix or separator character and set
  3079.           the value of Lookahead with this character.
  3080.  
  3081.           The fifth parameter, Put, is a procedure which will accept
  3082.           values of type Atomic_Literal and write them to a specified
  3083.           output file.
  3084.  
  3085.           6.2.  Accessing the Various Packages
  3086.  
  3087.           Once the AI Data Types package is instantiated all data
  3088.           objects and functions of all packages except the Rulebase
  3089.           package are available via a with/use rule for the appropri-
  3090.           ate package.  The Rulebase package is a generic package
  3091.           requiring two parameters:
  3092.  
  3093.           (1)  An enumerated type by which the database may be indexed
  3094.                for efficient access.
  3095.  
  3096.  
  3097.  
  3098.  
  3099.                                        46
  3100.  
  3101.  
  3102.  
  3103.  
  3104.  
  3105.  
  3106.  
  3107.  
  3108.  
  3109.  
  3110.           (2)  A function which accepts a parameter of type Rule and
  3111.                returns a unique value of the enumerated type used to
  3112.                index the database.
  3113.  
  3114.  
  3115.  
  3116.  
  3117.  
  3118.  
  3119.  
  3120.  
  3121.  
  3122.  
  3123.  
  3124.  
  3125.  
  3126.  
  3127.  
  3128.  
  3129.  
  3130.  
  3131.  
  3132.  
  3133.  
  3134.  
  3135.  
  3136.  
  3137.  
  3138.  
  3139.  
  3140.  
  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.                                        47
  3166.  
  3167.  
  3168.  
  3169.  
  3170.  
  3171.  
  3172.  
  3173.  
  3174.  
  3175.  
  3176.           7.  The AI Data Types Demonstration
  3177.  
  3178.           Because it is helpful to experiment with the functions in
  3179.           the AI Data Types package, a demonstration program has been
  3180.           provided.  This program effectively tests and demonstrates a
  3181.           large number of functions from each of the packages in the
  3182.           AI_Data_Types package.  It is hoped that this program will
  3183.           help programmers to resolve questions about the facilities
  3184.           and become familiar and proficient with the subprograms
  3185.           found in these packages.
  3186.  
  3187.           7.1.  Compiling the AI Data Types Demonstration   To create
  3188.           the AI Data Types Demonstration, five files are needed.
  3189.           These are:
  3190.  
  3191.              aitypesdemo.ada  -- The demonstration program, AITypesdemo.
  3192.              aitypesimp.ada   -- The generic package implementation for
  3193.                                  the AI_Data_Types package.
  3194.              aitypesspc.ada   -- The generic package specification for
  3195.                                  the AI_Data_Types package.
  3196.              instimp.ada      -- The package implementation for the
  3197.                                  Inst_Facilities package, a collection
  3198.                                  of facilities needed to instantiate
  3199.                                  the AI_Data_Types package for use by
  3200.                                  the demonstration program.
  3201.              instspc.ada      -- The package specification for the
  3202.                                  Inst_Facilities package.
  3203.  
  3204.  
  3205.           Creating the demonstration simply involves compiling the
  3206.           files in the following order:
  3207.  
  3208.              1. aitypesspc.ada
  3209.              2. aitypesimp.ada
  3210.              3. instspc.ada
  3211.              4. instimp.ada
  3212.              5. aitypesdemo.ada
  3213.  
  3214.  
  3215.           and then invoking the appropriate object code linker to
  3216.           create the executable program, which should be named
  3217.           aitypesdemo.
  3218.  
  3219.           Upon running the program, the user will be prompted with a
  3220.           menu requesting which package of the AI_Data_Types package
  3221.           the user would like to demonstrate.  Choosing the appropri-
  3222.           ate number will start the demonstration program for that
  3223.           package.
  3224.  
  3225.           After choosing the AI package to be demonstrated, the names
  3226.           of subprograms specific to the current AI package and their
  3227.           arguments can be entered at the prompt.  After hitting
  3228.           <RETURN>, the given arguments will be processed by the
  3229.  
  3230.  
  3231.                                        48
  3232.  
  3233.  
  3234.  
  3235.  
  3236.  
  3237.  
  3238.  
  3239.  
  3240.  
  3241.  
  3242.           chosen subprogram and the result displayed on the following
  3243.           line.  The user will then be prompted for the next input.
  3244.  
  3245.           A few general notes will be helpful here.
  3246.  
  3247.           (1)  A list of programs provided by the current AI package
  3248.                demonstration can be obtained by entering "help" at the
  3249.                prompt.
  3250.  
  3251.           (2)  To terminate the current demonstration, enter "quit".
  3252.                Upon leaving the current demonstration, the user will
  3253.                be asked if another demonstration is desired.  Answer-
  3254.                ing "y" will cause the initial menu to be redisplayed,
  3255.                answering "n" will terminate the program completely.
  3256.  
  3257.           (3)  The names of the subprograms do not have to be in any
  3258.                specific case.  Entering the subprogram name in all
  3259.                lower-case letters will suffice.
  3260.  
  3261.           (4)  The parameters to the subprograms should be separated
  3262.                by blanks, no commas are needed or allowed between
  3263.                parameters.
  3264.  
  3265.           (5)  Extra input on the command line will be ignored.
  3266.  
  3267.           (6)  If the program seems to be waiting, chances are that a
  3268.                parameter or a closing parenthesis has been omitted.
  3269.                Consulting the user's manual will help solve the first
  3270.                problem, counting parentheses will help solve the
  3271.                second.
  3272.  
  3273.           The following sections will describe the specifics of each
  3274.           of the AI package demonstrations.
  3275.  
  3276.           7.2.  Using the Symbolic Expressions Demonstration   The
  3277.           following operations are available for testing in the Sym-
  3278.           bolic Expressions demonstration:
  3279.  
  3280.           Append         Help           Is_Variable  Prefix         Set_Differ
  3281.           Associate      Is_Atomic      Last         Quit           Set_Or
  3282.           Associate_All  Is_Equal       Length       Replace        Set_Xor
  3283.           First          Is_Non_Atomic  Nth_First    Reverse_S_Expr
  3284.           Flatten        Is_Null        Nth_Rest     Set_And
  3285.  
  3286.  
  3287.           Please note the difference in names between those facilities
  3288.           represented by a single character operator in the User's
  3289.           Manual (e.g "&") and the name used for this subprogram in
  3290.           the demonstration (e.g Append).  Another point of note is
  3291.           that default parameters are not supported in this demonstra-
  3292.           tion, all parameters for functions such as Prefix (both sym-
  3293.           bolic expressions) and the Associate functions (two symbolic
  3294.           expressions and a numeric search position) are required to
  3295.  
  3296.  
  3297.                                        49
  3298.  
  3299.  
  3300.  
  3301.  
  3302.  
  3303.  
  3304.  
  3305.  
  3306.  
  3307.  
  3308.           be entered by the user.  A helpful starting point for using
  3309.           this demonstration would be to enter those examples provided
  3310.           in the User's Manual and verifying the result.  The demons-
  3311.           tration would take the following form:
  3312.  
  3313.                  ...
  3314.  
  3315.           -> first (a, b, c)
  3316.              a
  3317.           -> rest (a, b, c)
  3318.              (b, c)
  3319.           -> append (a, b) (c, d)
  3320.              (a, b, c, d)
  3321.           -> prefix (a) (b)
  3322.              ((a), b)
  3323.  
  3324.                  ...
  3325.  
  3326.  
  3327.           7.3.  Using the Patterns Demonstration   The following
  3328.           operations are available for testing in the Patterns demons-
  3329.           tration:
  3330.  
  3331.           Create_Pattern1  Free2          Help          Is_Null2  Set_Bindings1
  3332.           Create_Pattern2  Get_Bindings1  Instantiate1  Match     Set_Bindings2
  3333.           First1           Get_Bindings2  Instantiate2  Quit      Tag_Variables1
  3334.           First2           Get_Template1  Is_Equal      Rest1     Tag_Variables2
  3335.           Free1            Get_Template2  Is_Null1      Rest2
  3336.  
  3337.  
  3338.           In the patterns demonstration, two patterns are declared.
  3339.           These can be operated upon by using the appropriate subpro-
  3340.           gram suffixed by the number of the patttern to be manipu-
  3341.           lated.  All subprograms suffixed by a "1" operate on pattern
  3342.           one, while those suffixed by a "2" operate on pattern two.
  3343.           Those subprograms without numeric suffixes (with the excep-
  3344.           tion of Help and Quit) are binary operations with operate on
  3345.           both patterns (inputs after these subprogram names will be
  3346.           ignored).  The best way to start this demonstration is to
  3347.           create two patterns and then match them.  The output of the
  3348.           match routine will help to show the operation of a number of
  3349.           the Patterns subprograms.  The following is an example:
  3350.  
  3351.                ...
  3352.  
  3353.           -> create_pattern1 (?x, b, ?z)
  3354.              (?x, b, ?z)
  3355.           -> create_pattern2 (a, ?y, c)
  3356.              (a, ?y, c)
  3357.           -> match
  3358.              Initial Template of Pattern1: (?x, b, ?z)
  3359.              Initial Bindings of Pattern1: ()
  3360.              Initial Template of Pattern2: (a, ?y, c)
  3361.  
  3362.  
  3363.                                        50
  3364.  
  3365.  
  3366.  
  3367.  
  3368.  
  3369.  
  3370.  
  3371.  
  3372.  
  3373.  
  3374.              Initial Bindings of Pattern1: ()
  3375.              Result of Match:  TRUE
  3376.              Final Template of Pattern1:   (?x, b, ?z)
  3377.              Final Bindings of Pattern1:   ((?z, c), (?x, a))
  3378.              Final Template of Pattern2:   (a, ?y, c)
  3379.              Final Bindings of Pattern2:   ((?y, b))
  3380.              Instantiation of Pattern1:    (a, b, c)
  3381.              Instantiation of Pattern2:    (a, b, c)
  3382.  
  3383.                ...
  3384.  
  3385.  
  3386.           Please note that a variable binding context cannot be asso-
  3387.           ciated with patterns when calling Create_Patterns functions
  3388.           in this demonstration.  The bindings can only be set by
  3389.           calls to the Set_Bindings functions.
  3390.  
  3391.           7.4.  Using the Rules Demonstration   The following opera-
  3392.           tions are available for testing in the Rules demonstration:
  3393.  
  3394.           Antecedent1   Free1          Help          Is_Null1   Match
  3395.           Antecedent2   Free2          Instantiate1  Is_Null2   Quit
  3396.           Consequent1   Get_Bindings1  Instantiate2  Is_Query1  Set_Bindings1
  3397.           Consequent2   Get_Bindings2  Is_Equal      Is_Query2  Set_Bindings2
  3398.           Create_Rule1  Get_Template1  Is_Fact1      Is_Rule1   Tag_Variables1
  3399.           Create_Rule2  Get_Template2  Is_Fact2      Is_Rule2   Tag_Variables2
  3400.  
  3401.  
  3402.           The Rules demonstration is similar to the Patterns demons-
  3403.           tration.  Two rules have been declared and can be operated
  3404.           upon by calling the appropriately numbered facilities.  The
  3405.           notes regarding the matching process and the association of
  3406.           binding lists mentioned for the Patterns demonstration
  3407.           applies equally to the Rules demonstration.
  3408.  
  3409.           7.5.  Using the Rulebase Demonstration   The following
  3410.           operations are available for testing in the Rulebase demons-
  3411.           tration:
  3412.  
  3413.           Assert1           Get_Template1  Quit       Retract2
  3414.           Assert2           Get_Template2  Rb_And     Retrieve1
  3415.           Create_Rulebase1  Help           Rb_Differ  Retrieve2
  3416.           Create_Rulebase2  Is_Equal       Rb_Or
  3417.           Free1             Is_Null1       Rb_Xor
  3418.           Free2             Is_Null2       Retract1
  3419.  
  3420.  
  3421.           Two rulebases have been declared in the Rulebase demonstra-
  3422.           tion and, as in the other demonstrations, can be operated
  3423.           upon by calling the appropriately numbered facilities.
  3424.           Functions without numeric suffixes (with the exception of
  3425.           Help and Quit) are binary operations which operate upon the
  3426.           current contents of the two rulebases.  Rulebases may be
  3427.  
  3428.  
  3429.                                        51
  3430.  
  3431.  
  3432.  
  3433.  
  3434.  
  3435.  
  3436.  
  3437.  
  3438.  
  3439.  
  3440.           constructed by calling the Create_Rulebase routines with a
  3441.           rulebase template, by using the Assert routines to incremen-
  3442.           tally add facts and rules or by a combination of the two
  3443.           methods.  After constructing the appropriate rulebases, the
  3444.           rulebases can be queried by calling the appropriate Retrieve
  3445.           function with an applicable query.  The following example
  3446.           demonstrates the incremental construction of a rulebase and
  3447.           the retrieval of the results of a query:
  3448.  
  3449.                ...
  3450.  
  3451.           -> assert1 ((loves ?x1, ?y1), (friends, ?x1, ?y1))
  3452.              (((loves ?x1, ?y1), (friends, ?x1, ?y1)))
  3453.           -> assert1 ((wife ?x2, ?y2), (loves, ?x2, ?y2))
  3454.              (((loves ?x1, ?y1), (friends, ?x1, ?y1))
  3455.               ((wife ?x2, ?y2), (loves, ?x2, ?y2)))
  3456.           -> assert1 ((), (wife, Mary, John))
  3457.              (((loves ?x1, ?y1), (friends, ?x1, ?y1))
  3458.               ((wife ?x2, ?y2), (loves, ?x2, ?y2))
  3459.               ((), (wife, Mary, John)))
  3460.           -> assert1 ((), (loves, Mary, Joe))
  3461.              (((loves ?x1, ?y1), (friends, ?x1, ?y1))
  3462.               ((wife ?x2, ?y2), (loves, ?x2, ?y2))
  3463.               ((), (wife, Mary, John))
  3464.               ((), (loves, Mary, Joe)))
  3465.           -> retrieve1 ((friends, Mary, ?x), ())
  3466.              ((friends, Mary, Joe),
  3467.               (friends, Mary, John))
  3468.  
  3469.                ...
  3470.  
  3471.  
  3472.  
  3473.  
  3474.  
  3475.  
  3476.  
  3477.  
  3478.  
  3479.  
  3480.  
  3481.  
  3482.  
  3483.  
  3484.  
  3485.  
  3486.  
  3487.  
  3488.  
  3489.  
  3490.  
  3491.  
  3492.  
  3493.  
  3494.  
  3495.                                        52
  3496.  
  3497.  
  3498.  
  3499.