www.RuleWorks.co.uk

RuleWorks Reference Dictionary

This chapter contains complete descriptions of all constructs in the RuleWorks language, including tables and complete descriptions. The following tables, presented at the beginning of this chapter, summarize the RuleWorks language constructs by category:

Many of the constructs described in this Reference Dictionary can be specified with arguments. When you specify argument values, separate the categories with any combination of spaces, tabs, and carriage returns.

The descriptions of all constructs are presented after the tables, alphabetically by name, with the non-alphabetic operators and predicates at the beginning. The descriptions include:

Note: you cannot use expressions that contain variables or function calls (except the COMPOUND function) as argument values for commands.

The RuleWorks run-time library routines are described in Appendix A.

Summary of Operators

Table 1 Summary of Operators - Arithmetic Operators

OperatorDescription
+Performs addition on numeric values
-Performs subtraction on numeric values
*Performs multiplication on numeric values
/Performs division on numeric values
\Performs the modulus operation on integer values

 

Table 2 Summary of Operators - Match Operators

OperatorDescription
^Specifies an attribute of an object
{ }Specifies a conjunction (logical AND) of values
<< >>Specifies a disjunction (logical OR) between values

 

Table 3 Summary of Operators - Logical Operators*

OperatorDescription
ANDPerforms a conjunction on two relational expressions
NOTNegates a relational expression
ORPerforms an inclusive disjunction on two relational expressions

Note: Logical operators can be used only within the context of IF ... THEN ... ELSE ... and WHILE ... DO ... actions.

Summary of Predicates and Relational Operators

Scalar predicates are those that are valid only for scalar attributes. The exceptions are identity and nonidentity (== and <>, which are also valid for comparing a compound attribute to a compound value. Compound predicates are those that are valid for compound attributes.

Table 4. Summary of Scalar Predicates and Relational Operators

DomainPredicateValue DomainTest
ANY==ANYIdentity: Same type as and equal to
This predicate is optional in LHS attribute-value tests. It is required in RHS relational expressions.
ANY<>ANYNonidentity; converse of identity
ANY=ANYEquality: Identical or equivalent numbers; identical symbols except for case; identical values of all other data types
ANY-=ANYInequality; converse of equality
ANY~=ANYSimilarity: Equal or phonetically similar symbols; equal or approximately equal numbers; identical values of all other data types
ANY-~=ANYDissimilarity; converse of similarity
NUMBER>NUMBERGreater than
SYMBOL>SYMBOLLexicographically after
ANY>=ANYGreater than or equal numbers; lexicographically after or equal symbols; identical values for all other data types
NUMBER<NUMBERLess than
SYMBOL<SYMBOLLexicographically before
ANY<=ANYLess than or equal numbers; lexicographically before or equal symbols; identical values for all other data types
ANY<=>ANYSame type
ANY<->ANYDifferent type

 

Table 5. Summary of Compound Predicates and Relational Operators

DomainPredicateValue DomainTest
COMPOUND[+]ATOMContainment; compound contains atom;
COMPOUND[-]ATOMNon-containment; converse of containment
COMPOUND[=]INTEGERLength equal
COMPOUND[<>]INTEGERLength not equal
COMPOUND[>]INTEGERLength greater
COMPOUND[>=]INTEGERLength greater than or equal
COMPOUND[<]INTEGERLength less than
COMPOUND[<=]INTEGERLength less than or equal

 

Summary of Statements

Rules and catchers may be contained in either an entry block or a rule block, but ON- statements must be contained in an entry block.

Table 6. Summary of Statements

StatementDescription
CATCHContains actions that are executed after a specified number of recognize-act cycles (see also the AFTER action)
ON-EMPTYContains actions that are executed when the conflict set is empty
ON-ENTRYContains actions that are executed when the entry block is called, before the first recognize-act cycle
ON-EVERYContains actions that are executed after the act phase of each recognize-act cycle except the last
ON-EXITContains actions that are executed after the act phase of the last recognize-act cycle, except when a QUIT action is performed
RULEContains actions that are executed when left-hand-side conditions are met and the instantiation wins conflict resolution

 

Summary of Actions

Table 7. Summary of Actions

ActionDescription
ADDSTATEAdds the contents of a file produced by the SAVESTATE action or command to the current state of working memory and the conflict set
AFTERSpecifies the number of recognize-act cycles that must be executed before a specified catcher is executed
BINDBinds a variable to a value
CLOSEFILECloses the open files associated with specified file identifiers and dissociates the identifiers from the files
COPYCopies a new copy of an existing object
DEFAULTSets the terminal or a file as the default input source for the ACCEPT-ATOM and ACCEPTLINE-COMPOUND functions, or the default output destination for the WRITE action or for trace output
FOR-EACHIterates over a compound value, executing the specified actions
IF ...
THEN ...
ELSE...
Provides a branch in the flow of control, as in procedural languages
MAKECreates an object
MODIFYChanges one or more values in an existing object
OPENFILEOpens a file and associates it with a file identifier
QUITStops execution of the active entry block and passes control back to the operating system, optionally returning a value
REMOVEDeletes one or more objects
REMOVE-EVERYDeletes all the working memory objects that are instances of the specified class or its subclasses
RESTORESTATEClears and then restores working memory and the conflict set to the state recorded in a file produced by the SAVESTATE action or command
RETURNStops execution of the active entry block, executes the ON-EXIT actions (if any), and passes control back to the caller of the entry block. May also pass a return value.
SAVESTATECopies the state of working memory and the conflict set to a file
SPECIALIZEConverts an instance of one class to an instance of a descendent class
TRACEDisplays or sets the run-time system's trace setting
WHILE ...
DO ...
Provides a loop in the flow of control, as in procedural languages
WRITESends output from a program to the terminal or a file

 

Summary of Functions

Table 8. Summary of Functions

FunctionOK on LHS?Description
ACCEPT-ATOMNoReads an atom from the terminal or a file
ACCEPTLINE-COMPOUNDNoReads a line of input from the terminal or file into a compound value
COMPOUNDYesCreates a new compound value from any number of arguments, scalar or compound
CONCATYesConcatenates the print forms of its arguments
CRLFNoCauses the WRITE action to produce output on a new line
EVERYNoReturns a compound value that contains the IDs of all instances of the specified class
FLOATYesConverts a numeric value into a floating-point number
GENATOMNoReturns a system-generated atom
GETNoGiven a variable bound to an object identifier and an attribute name, returns the value of that object's attribute
INTEGERYesConverts a numeric value into an integer
IS-OPENNoTests whether a file is open
LENGTHYesReturns the number of elements in a compound value
MAXYesReturns the largest of its arguments
MINYesReturns the smallest of its arguments
NTHYesReturns the value of a specified element in a compound value
POSITIONYesFinds the first occurrence of an element in a compound value
RJUSTNoCauses the WRITE action to right justify output in a field of specified width
SUBCOMPOUNDYesReturns a subrange of a compound value
SUBSYMBOLYesReturns a fragment of a symbolic value
SYMBOLYesConverts any atom into a symbol
TABTONoCauses the WRITE action to put output in a specified column

 

Summary of Commands

Table 9. Summary of Commands

CommandDescription
@Opens a file containing RuleWorks commands and executes the commands.
ADDSTATE Adds the contents of a file produced by the SAVESTATE action or command to the current state of working memory.
AFTERSpecifies the number of recognize-act cycles that must be executed before a specified catcher is executed.
CLOSEFILECloses the open files associated with specified file identifiers and dissociates the identifiers from the files.
COPYMakes a new copy of an existing object.
CSDisplays the current contents of the conflict set.
DEFAULTSets the terminal or a file as the default input source for the ACCEPT-ATOM and ACCEPTLINE-COMPOUND functions, or the default output destination for the WRITE action or trace output.
DISABLE Disables the WMHISTORY command and the display of block names.
EBREAKDisplays entry blocks that have breakpoints set, sets breakpoints for entry blocks, or deletes breakpoints from entry blocks.
ENABLEEnables the WMHISTORY command and the display of block names.
EXITSynonym for QUIT command
MAKECreates a working-memory object.
MATCHESDisplays the identifiers and time-tags of objects that match condition elements in a specified rule.
MODIFYChanges one or more values in an existing working-memory object.
NEXTDisplays the instantiation the run-time system will select from the conflict set for the act phase of the next recognize-act cycle.
OPENFILEOpens a file and associates it with a file identifier.
PPCLASSDisplays the ancestors of an object class.
PPWMDisplays working-memory objects that match a specified pattern.
QUITStops execution and returns control to the operating system; optionally returns an integer value.
RBREAKDisplays rules that have breakpoints set, sets breakpoints for rules, or deletes breakpoints from rules.
REMOVEDeletes objects from working memory.
REMOVE-EVERYDeletes all working-memory objects that are instances of a specified class or subclass.
RESTORESTATE Clears working memory and the conflict set, then loads them from a file produced by the SAVESTATE action or command.
RETURNPasses control back to the caller of the entry block; optionally returns a value.
RUNExecutes recognize-act cycles.
SAVESTATECopies the state of working memory and the conflict set to a file.
SPECIALIZEChanges a working-memory object from an instance of one class to an instance of a parent class.
TRACEDisplays or sets the amount of debugging information displayed by the run-time system.
WBREAKDisplays objects that have breakpoints set, sets breakpoints for objects, or deletes breakpoints from objects.
WMDisplays working-memory objects.
WMHISTORYDisplays the revision history of an object.

 

Summary of Declarations

Table 10. Summary of Declarations

DeclarationDescription
DECLARATION-BLOCK Begins a set of shareable object class and external routine declarations
END-BLOCKEnds an entry, declaration, or rule block
END-GROUPEnds a rule group
ENTRY-BLOCKBegins a callable RuleWorks routine
EXTERNAL-ROUTINEDeclares a routine written in a language other than RuleWorks, or another RuleWorks entry block
OBJECT-CLASS Defines a class name and its list of attribute names
RULE-BLOCK Begins a set of shareable rules and catchers
RULE-GROUPBegins a named set of rules and catchers

 

Summary of SQL Actions

Table 11. Summary of SQL Actions

ActionDescription
SQL-ATTACH Specifies the database that is to be accessed by the other RuleWorks SQL actions.
SQL-COMMIT Completes the current SQL transaction and makes permanent any changes made during the transaction.
SQL-DELETE Deletes specified records from the database.
SQL-DETACH Commits any outstanding transaction and detaches from the database.
SQL-FETCH-EACH Binds field values to RuleWorks variables and executes RuleWorks actions that can use those variables.
SQL-FETCH-AS-OBJECT Makes objects from database records.
SQL-INSERT Stores new records in the database.
SQL-INSERT-FROM-OBJECT Stores the contents of an object in a new database record.
SQL-ROLLBACK Completes the current SQL transaction and undoes any changes made during the transaction.
SQL-START Starts an SQL transaction and sets transaction options.
SQL-UPDATE Modifies existing database records.
SQL-UPDATE-FROM-OBJECT Modifies existing database records, using the contents of an object.

 

Operator Descriptions

This section contains a description of the RuleWorks operators, in alphabetical order.

 

+ (Addition)

Performs arithmetic addition on numeric values.

 

- (Negation and Subtraction)

As a Match Operator

Negates a condition element (see Chapter 3 for a discussion of negative CEs).

As an Arithmetic Operator

Performs arithmetic subtraction on numeric values.

 

* (Multiplication)

Performs arithmetic multiplication on numeric values.

 

/ (Division)

Performs arithmetic division on numeric values.

 

\ (Modulus)

Performs the arithmetic modulus operation on integer values.

 

^ (Attribute)

Specifies an attribute of an object. You must define all attributes in an OBJECT-CLASS declaration. For more information about attributes, see Chapter 2.

 

== (Identity)

Produces a match, or evaluates to true, when both its operands have the same type and the same value.

Two compound values are identical if they contain the same values in the same order.

As a Match Predicate

In an attribute-value test on the LHS, the identity predicate is optional.

If the value following the identity predicate is an unbound variable, that variable is bound to the value of the specified attribute. The identity and length-equal ([=]) predicates are the only predicates that can precede the first occurrence of a variable, because they are the only ones that can either bind a variable or compare its value.

As a Relational Operator

In a relational expression on the RHS, the identity operator is required. There is no default or implied operator inside relational expressions.

<> (Nonidentity)

Produces a match when the identity predicate (see previous fails to match; evaluates to true when the identity operator evaluates to false.

 

= (Equality)

Produces a match, or evaluates to true, when its operands are identical or have equal values.

The equality predicate and operator performs automatic type conversion between INTEGER and FLOAT values. For example, 2 is equal to 2.0, but 2 is not identical to 2.0.

The equality predicate and operator ignores case when comparing SYMBOL values. For example, |cat | is equal to CAT, but |cat | is not identical to CAT.

You cannot use the equality predicate with the binding instance of a variable. You must use the identity predicate.

 

-= (Inequality)

Produces a match when the equality predicate (see previous page) fails to match; evaluates to true when the equality operator evaluates to false.

 

~= (Similarity)

Produces a match, or evaluates to true, when its arguments are either both numbers or the same type, and are similar to each other. Similarity is defined as follows:

 

-~= (Dissimilarity)

Produces a match, or evaluates to true, when the similarity predicate (see previous fails to match, or evaluates to false.

 

> (Greater-than)

Produces a match, or evaluates to true, when its first operand is greater than its second. The operands must be either both numbers or both symbols.

See appendix E for information on the collating sequences used by RuleWorks to compare symbolic values.

  • Format
  • ^attribute > value-expression

    value-expression > value-expression

  • Operands
  • ^attribute

    An attribute of a WMO whose value is to be tested.

    value-expression

    Any RuleWorks expression that evaluates to a symbol or a number.

  • Example
  • The following table shows the results of several greater-than tests

    Table 15. Greater-than Testing

    First Value Second ValueMatch or True?
    4.0>3Yes
    4>5.0No
    aardwolf>aardvarkYes
    | greater-than |>greater-thanNo

 

>= (Greater-than-or-equal)

Produces a match, or evaluates to true, when its first operand is greater than or equal to its second. The operands must be either both numbers or both symbols.

See Appendix E for information on the collating sequences used by RuleWorks to compare symbolic values.

  • Format
  • ^attribute >= value-expression

    value-expression >= value-expression

  • Operands
  • ^attribute

    An attribute of a WMO whose value is to be tested.

    value-expression

    Any RuleWorks expression that evaluates to a symbol or a number.

  • Example
  • The following table shows the results of several greater-than-or-equal tests:

    Table 16. Greater-than-or-Equal Testing

    First Value Second ValueMatch or True?
    5.0>=5Yes
    6>=7.0No
    aardvark>=AardvarkYes
    | greater-than |>=greater-thanYes

    The aardvarks match because they are equal, which is a case insensitive comparison, not because the first value is greater than the second.

< (Less-than)

Produces a match, or evaluates to true, when its first operand is less than its second. The operands must be either both numbers or both symbols.

See Appendix E for more information on the collating sequences used by RuleWorks to compare symbolic values.

  • Format
  • ^attribute < value-expression

    value-expression < value-expression

  • Operands
  • ^attribute

    An attribute of a WMO whose value is to be tested.

    value-expression

    Any RuleWorks expression that evaluates to a symbol or a number.

  • Example
  • The following table shows the results of several less-than tests:

    Table 17. Less-than Testing

    First ValueSecond ValueMatch or True?
    2.0<3Yes
    5<6.0Yes
    zygosis<zygoteYes
    zoology<ZoologyNo

 

<= (Less-than-or-equal)

Produces a match or evaluates to true, when its first operand is less than or equal to its second. The operands must be either both numbers or both symbols.

See Appendix E for information on the collating sequences used by RuleWorks to compare symbolic values.

  • Format
  • ^attribute <= value-expression

    value-expression <= value-expression

     

  • Operands
  • ^attribute

    An attribute of a WMO whose value is to be tested.

    value-expression

    Any RuleWorks expression that evaluates to a symbol or a number.

     

  • Examples
  • The following table shows the results of several less-than-or equal tests:

    Table 18 Less-than-or-equal Testing

    First ValueSecond ValueMatch or True?
    2.0<=3Yes
    5<=5.0Yes
    zygosis<=zygoteYes
    zoology<=ZoologyYes

    The symbols match because they are equal, which is a case insensitive comparison, not because the first value is less than the second.

 

<=> (Same Type)

Produces a match, or evaluates to true, when both its operands are the same type. The RuleWorks data types are INTEGER, FLOAT, SYMBOL, INSTANCE-ID, and OPAQUE.

For example, if you specify this predicate with a symbol or a variable bound to a symbol, a match is produced when the atom in the WMO is a symbol.

The same-type predicate can be applied to scalar values only.

  • Format
  • (^attribute <=> value-expression)

    (value-expression <=> value-expression)

    An attribute of a WMO whose value is to be tested.

  • Arguments(Operands)
  • value-expression

    Any RuleWorks expression, whose value is to be tested.

  • Example
  • The following CE matches an object of class INPUT-THING whose ^ITEM attribute has a symbolic value:

    (input-thing ^item <=> symbol )

     

<-> (Different-type)

Produces a match when the same-type predicate (see previous page) fails to match; evaluates to true when the same-type operator evaluates to false.

This predicate can be applied to scalar values only.

  • Example
  • This CE is the converse of the previous example:

    (input-thing ^item <-> symbol)

 

[+] (Containment)

Produces a match, or evaluates to true, when its scalar operand is an element of its compound operand. That is, you can test whether a compound contains a scalar value, or you can test whether a scalar value is contained in a compound.

By default, the containment predicate tests for identity; you can specify a different test with an optional scalar predicate. The scalar predicate must appear next to the scalar argument.

  • Format
  • ^compound-attr [+] [predicate] scalar-value

    ^scalar-attr [predicate] [+] compound-value

    compound-value [+] [predicate] scalar-value

    scalar-value [predicate] [+] compound-value

     

  • Operands
  • ^compound-attr

    The compound attribute whose value is to be searched for a scalar value.

    Predicate

    A predicate that specifies the comparison between elements of the compound value and the scalar value. This argument is optional; if you do not specify a predicate, RuleWorks uses the default identity predicate.

    You can use any scalar predicate except containment and non-containment (see Table 4)

    scalar-value

    The scalar value for which a compound attribute is to be searched.

    ^scalar-attr

    The scalar attribute for whose value a compound is to be searched.

    compound-value

    The compound value which is to be searched for a scalar value

     

  • Examples
  • The following CE matches an object class BOX whose ^CARD-IN-SLOT attribute contains at least one MEMORY element:

     

    (box ^card-in-slot <cards> [+] memory)

    The condition shown below is true when MEMORY is contained by <CARDS>:

     

    (memory [+] <cards>)

    The following attribute-value test uses the similarity predicate in conjunction with the containment predicate:

    ^list [+] ~= color

    This test matches when the compound value of the ^LIST attribute contains an element similar to COLOR, such as COLOUR or COULEUR.

     

[-] (Non-containment)

Produces a match when the containment predicate (see previous page) fails to match; evaluates to true when the containment operator evaluates to false.

 

  • Example
  • The following two CEs match a WMO of class BOX whose ^CARD-IN-SLOT-OBJ-ID attribute does not contain the object whose ID is bound to <THE-MEM>:

    (memory ^$ID <the-mem>)

    (box ^card-in-slot-obj-id [-] <the mem>)

 

[=] (Length-equal)

Produces a match, or evaluates to true, when the number of elements in its compound operand is identical to its numeric operand.

As with identity predicate, the length-equal predicate can be used with the first appearance of a variable. This binds the variable to the actual number of elements in the compound attribute.

 

  • Format
  • ^compound-attr [=] integer-value

    compound-value [=] integer-value

     

  • Operands
  • ^compound-attr

    The compound attribute whose length is to be tested.

    Integer-value

    The integer value to which the length of a compound value is to be compared. This operand may be any expression that evaluates to an integer greater than or equal to zero.

    Compound-value

    The compound value whose length is to be tested. This operand may be any expression that evaluates to a compound value.

     

  • Examples
  • The CE below matches an object of class BOX whose ^CARD-IN-SLOT attribute is empty:

    (box ^card-in-slot [=] 0)

    This CE shows the syntax for testing the compound and binding a variable:

    (box ^card-in-slot {[=] 0 [=] <cards>})

     

 

[<>] (Length-not-equal)

Produces a match when the length-equal predicate (see previous page) fails to match; evaluates to true when the length-equal operator evaluates to false.

  • Example
  • The following CE matches an object of class BOX whose ^CARD-IN-SLOT attribute is not empty:

    (box ^card-in-slot [<>] 0)

 

[>] (Length-greater-than)

Produces a match, or evaluates to true, if the number of elements in its compound operand is greater than its integer operand.

  • Format
  • ^compound-attr [>] integer-value

    compound-value [>] integer-value

  • Operands
  • ^compound-attr

    The compound attribute whose length is to be tested.

    Integer-value

    The integer value to which the length of a compound value is to be compared. This operand may be any expression that evaluates to an integer greater than or equal to zero.

    Compound-value

    The compound value whose length is to be tested. This operand may be any expression that evaluates to compound value.

    Example

    The following CE matches an object of class BOX whose ^CARD-In-SLOT attribute has more than two elements:

    (box ^card-in-slot [>] 2)

     

 

[>=] (Length-greater-than-or-equal)

Produces a match, or evaluates to true, if the number of elements in its compound operand is greater than or equal to its integer operand.

  • Format
  • ^compound-attr [>=] integer-value

    compound-value [>=] integer-value

  • Operands
  • ^compound-attr

    The compound attribute whose length is to be tested.

    Integer-value

    The integer value to which the length is to be tested. This operand may be any expression that evaluates to an integer greater than or equal to zero.

    Compound-value

    The compound value whose length is to be tested. This operand may be any expression that evaluates to a compound value.

    Example

    The following CE matches an object of class BOX whose ^CARD-IN-SLOT attribute has two or more elements:

    (box ^card-in-slot [>=] 2)

 

[<] (Length-less-than)

Produces a match, or evaluates to true, if the number of elements in its compound operand is less than its integer operand.

  • Format
  • ^compound-attr [<] integer-value)

    compound-value [<] integer-value

  • Operands
  • ^compound-attr

    The compound attribute whose length is to be tested.

    integer-value

    The integer value to which the length of a compound value is to be compared. This operand may be any expression that evaluates to an integer greater than or equal to zero.

    compound-value

    The compound value whose length is to be tested. This operand may be any expression that evaluates to a compound value.

  • Example
  • The following CE matches an object of class BOX whose ^CARD-IN-SLOT attribute has fewer than two elements:

    (box ^card-in-slot [<] 2 )

 

[<=] (Length-less-than-or-equal)

Produces a match, or evaluates to true, if the number of elements in its compound operand is less than or equal to its integer operand.

  • Format
  • ^compound-attr [<=] integer-value

    compound-value [<=] integer-value

  • Operands
  • ^compound-attr

    The compound attribute whose length is to be tested.

    integer-value

    The integer value to which the length of a compound value is to be compared. This operand may be any expression that evaluates to an integer greater than or equal to zero.

    compound-value

    This operand may be any expression that evaluates to a compound value.

  • Example
  • The following CE matches an object of class BOX whose ^CARD-IN-SLOT attribute has two or fewer elements.

    (box ^card-in-slot [<=] 2 )

     

{ } (Conjunction)

Specifies a conjunction. A conjunction is similar to a logical AND. It is a left-hand-side pattern containing one or more conditional tests, all of which a single attribute in an object must satisfy.

For more information about conjunctions, see Chapter 3.

  • Format
  • { conditional-test ... }

  • Operands
  • conditional-test

    One or more conditional tests that the value of an attribute in an object is to satisfy.

  • Example
  • The following CE matches teenagers by testing for age greater than or equal to 13 AND less than 20:

    (person ^age { >= 13 < 20})

    The next CE contains a conjunction of two tests on the length of the compound attribute ^CARD-IN-SLOT. The first binds the length to the variable <LEN>. The second tests that the length is less than 6:

    (box ^$ID <the-box> ^card-in-slot <{> [=] <len> [<] 6})

    You can use a conjunction when you want to bind as well as test an attribute. For example:

    (hardware-option ^in-slot { <slot-num> <> NIL})

 

<<>> (Disjunction)

Specifies a disjunction of values, similar to a logical inclusive OR. An attribute that matches any one of the values satisfies the disjunction (see also Chapter 3).

  • Format
  • << value-expression…>>

  • Operands
  • Value-expression

    The value that an attribute value in an object is to match. This argument can be a constant, a bound variable, an arithmetic expression, or a function call. It must have the same structure as the attribute, either scalar or compound. You can specify one or more values.

    A disjunction of values is implicitly preceded by the identity predicate (= =). You cannot use any other predicate with a disjunction of values.

  • Examples
  • The following CE contains a disjunction of values:

    (input-thing ^item << NIL EOF END-OF-FILE >>)

    The next example shows the syntax for a compound attribute:

    (object ^$id <object-1>

    ^ integer-attr <I> ^symbol-attr <s> ^compound-attr <c>)

    (object ^$id {<object-2> <> <object-1>}

    ^compound-attr << <c>

    (compound a <s> c)

    (subcompound <c> 1 ((length <c>) - <I>)) >>)

 

@ (At)

Opens a file containing RuleWorks commands and executes the commands. The file must contain only RuleWorks commands. If the file cannot be opened, the run-time system displays the following message:

<FAC>-W-CANTOPEN, @ - Unable to open file filename for reading

  • Format
  • @ filespec

  • Argument
  • filespec

    The file specification for a file containing RuleWorks commands to be executed. The restrictions on file specifications vary according to operating system; see Section C.1 for details.

  • Example
  • The first command illustrates a simple file specification:

    RuleWorks> @ init-mem.wm

    The command below shows a file specification that includes a pathname, and must be quoted:

    RuleWorks> @ |C:%MEM.COM|

 

ACCEPT-ATOM

Reads an atom from the keyboard or a file. Ignores values after a semicolon (;) until the end of the line.

By default, the ACCEPT-ATOM function reads input from the keyboard. If you want the function to read input from a file, call the function with the file identifier of an open input file, or change the default for input.

  • Format
  • ACCEPT-ATOM [ file-id ]

  • Argument
  • file-id

    The file identifier of the file from which input is to be read. The file must have been opened and associated with the identifier in a previous OPENFILE action or command.

    This argument is optional. If you do not specify a file identifier, input is read from the current default for the ACCEPT-ATOM function (set with the DEFAULT action or command).

    Return Value

    If the argument you specify is not associated with an open file, the run-time system issues a warning and the function returns the symbol NIL.

    When the function reads past the end of a file, it returns the symbol END-OF-FILE.

  • Example
  • The following MAKE action uses the ACCEPT-ATOM function to create a Working Memory Object (WMO) that contains an atom read from the file associated with the file identifier INFIL.

    (make input-thing ^item (accept-atom infil))

     

ACCEPTLINE-COMPOUND

Reads a line of input from the keyboard or a file and returns a compound value that contains the values read. Ignores values after a semicolon (;) until the end of the line.

If some of the atoms in the current line have already been read, the input line is defined as all the remaining atoms on the current line. If all the atoms on the current line have been read, the input line is the next. If the input line contains no atoms, the function returns the specified default compound value.

By default, the ACCEPTLINE-COMPOUND function reads input from the keyboard. If you want the function to read input from a file, call the function with the file identifier of an open input file, or change the default for input.

  • Format
  • ACCEPTLINE-COMPOUND [file-id [default-compound-value]]

  • Arguments
  • File-id

    The file identifier of the file from which input is to be read. The file must have been opened and associated with the identifier in a previous OPENFILE action or command.

    This argument is optional. If you do not specify a file identifier, input is read from the current default for the ACCEPTLINE-COMPOUND function (set with the DEFAULT action or command).

    Default-compound-value

    The compound value to be returned when the function reads a blank line. This argument may be a bound compound variable or a function call that returns a compound value.

    If you want to specify a default compound value, you must also specify a file identifier. If you want to specify a default compound value when reading from the default input source, use the symbol NIL for the file identifier.

  • Return Value
  • A compound value that contains all the atoms on the current input line. If the input line contains no atoms, the function returns the specified default compound value.

    If the first argument you specify is not associated with an open file, the run-time system issues a warning and the function returns the empty compound value.

    When the function reads past the end of a file, it returns a compound value that contains the single element END-OF-FILE.

  • Example
  • The following actions read a line of input as a compound variable, and write it one element at a time:

    (bind <my-compound> (acceptline-compound))

    (for-each <x> in <my-compound>

    (write (crlf) <x>))

     

ADDSTATE

Adds the objects in a file produced by the SAVESTATE action or command to working memory.

The added objects have new INSTANCE-IDs and new time-tags. Any attributes in the added objects that have INSTANCE-ID values that point to other added objects are automatically updated so that the references remain consistent.

The ADDSTATE action and command is scoped to the entry block; it creates visible objects only. Trying to add objects whose class declarations are not visible to the entry block causes a run-time warning, and the WMOs are not made.

  • Format
  • (ADDSTATE filespec)

  • Argument
  • filespec

    A file specification for a file previously produced by the SAVESTATE action or command. See Section C.1 for restrictions on file names.

  • Example
  • Suppose you use the SAVESTATE action or command to create the file CONFIG.DAT. The following action adds the objects in the file to working memory.

    (addstate config.dat)

    The equivalent command is:

    RuleWorks> addstate config.dat

    On ULTRIX and Digital UNIX systems, the command could be:

    RuleWorks> addstate | config.dat |

 

AFTER

Specifies the number of recognize-act cycles that must be executed before a specified catcher is executed (see also Chapter 5).

Only one catcher can be active. Thus, the AFTER action and command disables the current catcher, if any, before it enables the new one.

The rule-firing counter is local to the current invocation of the active entry block. Recognize-act cycles executed by an entry block called from the entry block that contains the AFTER and CATCH actions are not counted.

  • Format
  • AFTER cycles catcher-name

  • Arguments
  • cycles

    A positive integer that specifies the number of recognize-act cycles that are to be executed before the specified catcher is executed. If this number of cycles is never reached, the catcher is not executed.

    catcher-name

    A symbol that names a catcher.

    If the catcher executes another AFTER, the counter restarts.

  • Example
  • The following command specifies that the catcher named TOO-MANY-CYCLES is to be executed after 100 recognize-act cycles have been executed:

    RuleWorks> AFTER 100 TOO-MANY-CYCLES

    The equivalent action is:

    (AFTER 100 TOO-MANY-CYCLES)

 

AND

Performs a logical conjunction on its two operands, that is, returns true only when both of its operands are true.

Note: This is a relational operator only, not a match predicate. AND may be used only in relational expressions within IF...THEN...ELSE or WHILE...DO... actions.

  • Format
  • rel-expr AND rel-expr

  • Operands
  • rel-expr

    The relational expressions to be combined. These arguments must evaluate to either true or false.

  • Example
  • The following code fragment shows the AND operator in a WHILE...DO...action:

    (while ((<cards-dealt> < 5) AND (<dealing> == true)) do

    (deal-a-card))

 

BIND

Binds a variable to a value.

The scope of the variable binding depends on the construct that contains the BIND action. Variables bound in rules, catchers, and methods are local. Variables bound to the input arguments of an entry block, and variables bound in any ON- statement, are visible to all subsequent ON- statements.

  • Format
  • BIND variable value-expression

  • Arguments
  • variable

    The variable to which a value is to be bound.

    value-expression

    An expression that can evaluate to either a scalar or compound value. The action binds the specified variable to the value that results from the evaluation.

    Note: MAKE, COPY, MODIFY, and SPECIALIZE actions return a value of type INSTANCE-ID. You can use them as the second argument to the BIND action, as well as anywhere else a value expression is permitted.

  • Example
  • The following action binds the variable <NEW-OBJECT> to the INSTANCE-ID returned by a MAKE action. (See Chapter 3-3 for an example of a complete program):

    (bind <new-object>

    (make example-object ^next <first-object> ^last <instance-id>^value (<val> + 1)))

 

CATCH

Creates a catcher, which is a list of actions that are executed after a specified number of recognize-act cycles have been executed. An AFTER action or command specifies the number of recognize-act cycles to be executed before the catcher is executed.

The AFTER and the CATCH must be contained in the same block. The recognize-act cycles count includes only rule firings in the entry block that contains or activates the AFTER and the CATCH.

  • Format
  • CATCH catcher-name action…

  • Arguments
  • catcher-name

    A symbol that names the catcher being created. The symbol cannot be the name of another catcher, a rule, a rule group that already exits in the entry block.

    action

    Any RHS action. You can specify one or more actions.

  • Example
  • The following CATCH statement creates a catcher named TOO-MANY-CYCLES, which displays a message after the number of recognize-act cycles specified in an AFTER action or command have been executed, and stops execution:

    (catch too-many-cycles

    (write (crlf) |Program appears to be looping.|)

    (quit))

 

CLOSEFILE

Closes the open files associated with specified file identifiers and dissociates the identifiers from the files.

  • Format
  • CLOSEFILE file-id ...

  • Argument
  • file-id

    The file identifier of the file to be closed. The file must have been opened and associated with the identifier in a previous OPENFILE action or command.

    You can specify one or more file identifiers.

  • Example
  • The following command closes the open files associated with the file identifiers INFIL and OUTFIL:

    RuleWorks> CLOSEFILE INFIL OUTFIL

    The equivalent action is:

    (CLOSEFILE INFIL OUTFIL)

 

COMPOUND

Creates a new compound value from an arbitrary number of elements. If no elements are specified, the function returns the empty list.

COMPOUND is a stateless function and can be used on either the LHS or RHS.

  • Format
  • COMPOUND [ element ] ...

  • Argument
  • element

    Any valid scalar or compound value expression.

  • Return Value
  • A compound value that contains all the elements of the specified arguments.

  • Example
  • The following rule pushes a new value onto a stack by creating a new compound value from the new scalar value plus the current compound value.

    (rule push-stack

    (agenda ^$ID <Agenda-object> ^tasks <task-list>)

    -->

    (modify <Agenda-object> ^tasks (compound new-task <task-list>)))

    Note: RuleWorks does not support multilevel lists; the value returned above is a compound value whose elements are all scalar, not a compound value with one scalar element and a nested compound value.

    COMPOUND is the only function you can use in commands to the RuleWorks interpreter:

    RuleWorks> make box ^card-in-slot (compound memory keyboard)

 

CONCAT

Concatenates (splices) the print forms of its arguments.

  • Format
  • CONCAT [value-expr]...

  • Arguments
  • value-expr

    A RuleWorks expression that evaluates to a value to be concatenated. You can specify any number of values.

    If you specify a compound value, RuleWorks treats each element as a separate argument.

  • Return Value
  • A single scalar symbolic atom whose print name is the result of splicing together all of its arguments without inserting any spaces. If the result is too big to fit in a single atom, the function truncates it at the maximum symbol size (see chapter 2) and issues a warning.

  • Example
  • The following table shows three calls to the CONCAT function and their results:

    Table 18 CONCAT Function Calls and Results

    Function Call Print Form of Return Value

    (CONCAT a b c) ABC

    (CONCAT A | b | c) AbC

    (bind <x> | Fast | )
    (bind <y> | program! | )
    (CONCAT <x> || <y>) Fast program!

 

COPY

Makes a new object from an existing object. The existing object remains unchanged as a result of this operation. If you specify one or more attributes and values in the COPY, the new object is created with the new values you supply. In any case, the new object has a new $ID and a new time-tag. For more information about objects, see Section 2.2.

Note that the first argument to the COPY action must be a variable, while the first argument to the COPY command must be a constant.

You can also use COPY as a function with the BIND action.

  • Format (for action)
  • COPY ID-variable [{^attribute value-expression}...]

  • Format (for command)
  • COPY instance-id [ {^attribute value}...]

  • Arguments
  • ID-variable

    A variable bound to a value of type INSTANCE-ID, indicating the object to be duplicated. The object must be visible to the active entry block. This argument can be used only in source code.

    instance-id

    A constant of type INSTANCE-ID, indicating the object to be duplicated. The object must be visible to the active entry block. This argument can be used only at the command interpreter level.

    attribute

    An optional argument, this represents an attribute whose value is to be changed during the copy operation. You must specify a value with each attribute; you can specify any number of attribute-value pairs.

    value-expression

    Any scalar or compound value (if you specify a compound attribute) is a valid argument to the COPY action, including function calls and arithmetic expressions.

    value

    A scalar or compound value (if you specify a compound attribute). You cannot use expressions or call functions (except the COMPOUND function) in an argument to the COPY command.

  • Return Value
  • The COPY action returns the INSTANCE-ID atom that identifies the new WMO.

  • Example
  • The following example shows a rule from the sample program, KIWI.OPS, rewritten to use a COPY action.

    (rule verify-configuration:kiwindows-needs-2-memory-cards-found-one

    (active-context ^name verify-configuration)

    (kiwindows)

    (memory ^$ID <mem-id>)

    - (memory ^$ID <> <mem-id>)

    -->

    (make error ^severity warning ^message |Insufficient memory|)

    (write (crlf) |Caution: KiWindows requires two memory cards,|

    (crlf) | but you have only one memory card.|

    (crlf) | Fixup: adding another memory card to your order.|

    (crlf) )

    (copy <mem-id>))

    The following example shows the equivalent COPY command and its results:

    RuleWorks> PPWM MEMORY

    #31 [CONVERT-SINGLE-ITEM-INPUT-THING-TO-PARTS:MEMORY] (MEMORY)

    RuleWorks> COPY #31

    RuleWorks> PPWM MEMORY

    #31 [CONVERT-SINGLE-ITEM-INPUT-THING-TO-PARTS:MEMORY] (MEMORY)

    #32 [| main |] (MEMORY)

 

CRLF

Causes the WRITE action to move to the next line. Valid inside a WRITE action only.

  • Format
  • CRLF

  • Arguments
  • None

  • Example
  • The following WRITE action:

    (write (crlf) |Caution: You need to buy the base CPU unit.|

    (crlf) | Fixup: adding a CPU BOX to your order.|

    (crlf) )

    produces the following output:

    Caution: You need to buy the base CPU unit.

    Fixup: adding a CPU BOX to your order.

 

CS

Displays the active contents of the conflict set, that is, instantiations of rules contained in or activated by the active entry block.

The command displays instantiations in the following format:

rule-name #instance-id-1 time-tag-1 #instance-id-2 time-tag-2 ...

where:

  • #instance-id-1 is the INSTANCE-ID of an object that matches the first CE on the left-hand side and time-tag-1 is its time-tag,
  • #instance-id-2 matches the second CE, and so on.
  • Format
  • CS

  • Example
  • The following command displays the contents of the conflict set:

    RuleWorks> cs

    POP-ACTIVE-CONTEXT #35 40

    VERIFY-CONFIGURATION:APPLICATION-NEEDS-KIWOS #35 40 #32 37

    VERIFY-CONFIGURATION:APPLICATION-NEEDS-KIWOS #35 40 #29 34

    VERIFY-CONFIGURATION:NEED-DISK #35 40

    VERIFY-CONFIGURATION:NEED-OUTPUT #35 40

    MAKE-CONTEXT-ACTIVE #6 6

    MAKE-CONTEXT-ACTIVE #5 5

    MAKE-CONTEXT-ACTIVE #4 4

    MAKE-CONTEXT-ACTIVE #3 3

 

DEBUG

Pauses execution after the current rule or ON- construct and invokes the RuleWorks command interpreter.

This action is effective only when contained in an entry or rule block that was compiled with the Debug qualifier set to YES or MAYBE (see Chapter 8 for more information on compiling RuleWorks programs). If the block was compiled with Debug NO, the DEBUG action is a no-op.

When you compile an entry block with Debug set to YES, the command interpreter automatically appears when the entry block begins executing and when it ends. To achieve this effect with Debug set to MAYBE, put a DEBUG action in your ON-ENTRY and ON-EXIT statements. Other good places to put DEBUG actions are in error-checking rules (rules that match when your program is not running correctly) and catchers.

  • Format
  • DEBUG

  • Arguments
  • None

  • Example
  • RuleWorks debugging commands are allowed after the DEBUG action, and will be executed by the command interpreter. For example:

    (on-entry

    (make agenda ^tasks (compound start work stoop)

    (debug)

    (watch rules)

    (make control ^name print-err-messages))

 

DECLARATION-BLOCK

Names a group of object class, method, or external routine declarations so that they can be shared among multiple entry block or rule blocks.

Declaration blocks are optional; both object classes and external routines can be declared inside entry blocks or rule blocks. However, if a declaration is inside an entry block or rule block, that declaration is private and cannot be shared. Instances of objects declared privately are not visible to any other block.

All object classes that are related by inheritance must be contained in the same block. A subclass cannot inherit from a parent class declared in a different block. Similarly, methods must be declared in the same block as the class to which they are attached.

A declaration block must not contain any executable program statements (that is, rules, catchers, or ON-constructs). It must be entirely contained in a single source file.

The block must be terminated with an END-BLOCK declaration.

  • Format
  • (DECLARATION-BLOCK block-name)

  • Argument
  • block-name

    A symbol that names the block. This name must be distinct from all other block names in your program.

  • Example
  • This example shows a block of two OBJECT-CLASS declarations:

    (DECLARATION-BLOCK line-items)

    (OBJECT-class item

    ^item-code

    ^item-name

    ^quantity

    ^price-per

    ^item-total)

    (OBJECT-CLASS shippable-item

    (INHERITS-FROM item)

    ^part-number)

    (END-BLOCK line-items) ; the block name is optional here,

    ; but is checked if supplied

 

DEFAULT

Sets the default input source for the ACCEPT-ATOM and ACCEPT-LINE COMPOUND functions, or the default output destination for the WRITE action or trace output. If you do not use the DEFAULT command or action to specify otherwise, RuleWorks reads input from the keyboard and sends output to the screen (see chapter 2 for platform-specific details.)

  • Format
  • DEFAULT file-id io-type

  • Arguments
  • file-id

    The source from which input is to be read or the destination to which output is to be written. The value can be either a file identifier or the symbol NIL. If you specify a file identifier, DEFAULT sets the source or destination to the open file associated with that name. If you specify NIL, the input is read from the keyboard or output is sent to the screen.

    Use the OPENFILE action or command to open a file for access in a specified mode and create a file identifier.

    io-type

    A keyword that specifies whether the default is to be set for input, debugging output, or program output. The following table lists the keywords you can specify.

    Table 19. DEFAULT Keywords

    I/O TypeModeDescription
    ACCEPTINInput read by the ACCEPT-ATOM and ACCEPT-LINE-COMPOUND functions.
    TRACEOUT, APPENDOutput generated by the TRACE debugging command.
    WRITEOUT, APPENDOutput produced by the WRITE action.

     

  • Example
  • The following commands open a file for input, associate it with a file identifier INFIL, and set it to be the default source for the ACCEPT-ATOM and ACCEPTLINE-COMPOUND functions:

    RuleWorks> openfile infil order.dat in

    RuleWorks> default infil accept

    The equivalent actions are:

    (openfile infil order.dat in)

    (default infil accept)

 

DISABLE

Revokes a run-time feature that you had previously set with an ENABLE command. To disable a feature, specify the appropriate keyword.

 

    Table 20. DEFAULT Keywords

    KEYWORDFeature
    BLOCK-NAMESBlock names displayed with rule names
    WARNINGRun-time warning and error messages
    WMHISTORYWMHISTORY command

     

  • Format
  • DISABLE keyword

  • Argument
  • keyword

    A keyword that specifies the feature to be disabled. The keywords and the features they disable are listed in DISABLE Keywords table.

    Table 21. DISABLE Keywords

    KeywordFeature
    BACKBACK command
    TIMINGPME package
    BLOCK-NAMESBlock names displayed with rule names
    WARNINGRun-time warning and error messages
    WMHISTORYWMHISTORY command

     

  • Example
  • The following command disables the WMHISTORY command:

    RuleWorks> disable wmh

 

EBREAK

Controls breakpoints on entry blocks.

When used with no arguments, the command displays a numbered list of the entry blocks that have breakpoints set. When used with the ON and OFF keywords, respectively, EBREAK sets and clears breakpoints for entry blocks. Breakpoints are set or cleared on both the ON-ENTRY and ON-EXIT clauses by a single command.

When the run-time system encounters a breakpoint on an entry block, it finishes the ON-ENTRY or ON-EXIT construct (if-any), displays a message in the following format, and invokes the command interpreter:

%RUL-I-BREAKNOTED, Execution paused by break

EBREAK entering entry-block-name

Or

EBREAK exiting entry-block-name

Note that the block name is always displayed in EBREAK messages, whether BLOCK-NAMES is enabled or disabled.

 

  • Format
  • EBREAK
  • Arguments
  • entry-block-name

    The name of an entry block. You can specify one or more entry block names.

    number

    An integer displayed with the list of entry blocks when you give an EBREAK command with no argument. This argument is valid with the OFF keyword only.
    *
    All entry blocks.

 

ENABLE

Enables the run-time feature specified by a keyword argument (see ENABLE Keywords). The default state for all features is disabled.

Giving an ENABLE command with no argument results in a display of the features that are currently enabled. You can revoke a feature with the DISABLE command.

  • Format
  • ENABLE keyword

  • Argument
  • keyword

    A keyword that specifies the feature to be enabled.

    Table 22. ENABLE Keywords

    KeywordFeature
    BACK [n]BACK command. The optional argument, n, is an integer that specifies the number of cycles that may be backed over. The default is 64.
    TIMINGPME package.
    BLOCK-NAMESBlock names displayed with rule names
    WARNINGRun-time warning and error messages.
    WMHISTORYWMHISTORY command.

  • Example
  • The following command enables run-time messages.

    RuleWorks> enable war

 

END-BLOCK

Closes a block construct. Each DECLARATION-BLOCK, ENTRY-BLOCK, and RULE-BLOCK declaration must end with an END-BLOCK. If you want, you can repeat the name of the block in the END-BLOCK declaration.

  • Format
  • (END-BLOCK [block-name])

  • Argument
  • block-name

    The symbol that names the block being terminated. This argument is optional, but if you provide it the compiler checks it.

  • Example
  • This example shows a simple DECLARATION-BLOCK with a matching END-BLOCK:

    (DECLARATION-BLOCK line-items)

    (OBJECT-CLASS item

      ^item-code

      ^item-name

      ^quantity

      ^price-per

      ^item-total)

    (OBJECT-CLASS shippable-item

      (INHERITS-FROM item)

      ^part-number)

    (END-BLOCK line-items) ; the block name is optional here,

    ; but is checked if supplied

 

END-GROUP

Closes a rule group. Each RULE_GROUP declaration must end with an END-GROUP. If you want, you can repeat the name of the group in the END-GROUP declaration.

  • Format
  • (END-GROUP [group-name])

  • Argument
  • Group-name

    The symbol that names the group being terminated. This argument is optional, but if you provide it the compiler checks it.

 

ENTRY-BLOCK

Defines an entry point that is visible to the system linker and is callable by RuleWorks and other languages.

At least one ENTRY-BLOCK declaration is required for each RuleWorks routine. To make a RuleWorks program that you can run, at least one entry block must be named MAIN (or |main|).

RuleWorks entry blocks can accept arguments and return a value. You declare arguments with an ACCEPTS clause and the return value with a RETURNS clause.

An entry block can contain object class, and external routine declarations, and executable RuleWorks statements (that is, ON-statements, rules and catchers). It must be entirely contained in a single source file. However, an entry block can invoke rule blocks and declaration blocks that are contained in other files.

The entry block must close with an END-BLOCK declaration.

This example produces the following output, when compiled with DEBUG yes:

System> count 5

ArgC is 2 argV is $1$dua0:[williams.ruleworks]count.exe;4 5

%RUL-I-EBREAK, EBREAK encountered on |main| &ON-ENTRY

RuleWorks> run

1

2

3

4

5

%RUL-I-EBREAK, EBREAK encountered on |main| &On-EXIT

RuleWorks> run

System>

 

EVERY

Finds all instances of a specific class, including descendents of that class.

 

EXIT

An obsolescent synonym for the QUIT command.

 

EXTERNAL-ROUTINE

Declares a function or subroutine written in a language other than RuleWorks. Defines the data types and passing mechanisms of the arguments needed to call the external routine. (See Chapter 6.1 for information on data types and passing mechanisms.)

Other RuleWorks entry blocks must also be declared as external routines. However, an entry block can call itself recursively with no external routine declaration.