RuleWorks
Google
 
ruleworks.co.uk tu12.com Web

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:

  • Operators
  • Predicates and Relational Operators
  • Statements
  • Actions
  • Functions
  • Commands
  • Declarations
  • SQL Interface routines

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:

  • usage details
  • syntax
  • format
  • arguments
  • examples

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.

  • Format
  • numeric-expression + numeric-expression

  • Operands
  • numeric-expression

    The numeric expressions to be added. These may be numeric constants, arithmetic expressions, variables bound to numeric values, or functions that return numeric values.

  • Example
  • The following action shows addition of a bound variable and a constant.

    (modify <the-counter> ^count ( <c> + 1 ) )

 

- (Negation and Subtraction)

As a Match Operator

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

  • Format
  • - condition-element

  • Operand
  • condition-element

    The CE that is to be negated.

As an Arithmetic Operator

Performs arithmetic subtraction on numeric values.

  • Format
  • - numeric-expression

    numeric-expression - numeric-expression

  • Operands
  • numeric-expression

    The numeric expressions to be subtracted. These arguments may be numeric constants, arithmetic expressions, variables bound to numeric values, or functions that return numeric values.

  • Example
  • The following two CEs test for the existence of one and only one object of class MEMORY:

    (memory ^$ID <the-mem>)

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

    The following action shows subtraction of a bound variable and a constant:

    (write (crlf) |Read| ( <c> - 1 ) |items from input.| (crlf) )

 

* (Multiplication)

Performs arithmetic multiplication on numeric values.

  • Format
  • numeric-expression * numeric-expression

  • Operands
  • numeric-expression

    The numeric expressions to be multiplied. These may be numeric constants, arithmetic expressions, variables bound to numeric values, or functions that return numeric values.

  • Example
  • If the KIWI.RUL program calculates sales tax, it can use the following action:

    (modify <the-total> ^cost (<cost> + (<cost> * <tax>)))

 

/ (Division)

Performs arithmetic division on numeric values.

  • Format
  • numeric-expression / numeric-expression

  • Operands
  • numeric-expression

    The numeric expressions to be divided. These may be numeric constants, arithmetic expressions, variables bound to numeric values, or functions that return numeric values.

    The second operand must not evaluate to zero, or a warning is generated and the result is zero. The result is an integer only when both operands are integers.

  • Example
  • The following action converts degrees Fahrenheit to degrees Celsius:

    (bind <degrees-c> ((<degrees-f> - 32) * 5 / 9))

    Note that the entire arithmetic expression must be enclosed in parentheses.

 

\ (Modulus)

Performs the arithmetic modulus operation on integer values.

  • Format
  • integer-expression \ integer-expression

  • Operands
  • integer-expression

    The dividend and divisor for the modulus operation. These may be integers, arithmetic expressions that evaluate to integers, variables bound to integers, or functions that return integers.

  • Example
  • The following rule uses both division and modules on integers:

    (rule find-dozens

    (start ^$ID <start>)

    -->

    (write (crlf) |Enter an integer: | )

    (bind <eggs> (accept-atom)

    (write (crlf) |There are| (<eggs> / 12) |dozen in|<eggs>); division

    (write (crlf) | and there are| (<eggs> 12) |left over|) ; modulus

    (modify <start>))

    This example produces the following output:

    Enter an integer: 13

    There are 1 dozen in 13

    and there are 1 left over

    Enter an integer: 39

    There are 3 dozen in 39

    and there are 3 left over

    Enter an integer:

 

^ (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.

  • Format
  • ^attribute-name

  • Argument
  • attribute-name

    The name of a declared attribute.

    In condition elements on the LHS, this argument must be a symbolic atom. In actions on the RHS, this argument can be a symbol or a variable that is bound to a declared attribute name.

  • Example
  • The following OBJECT-CLASS declaration defines the attribute ^ITEM for the class INPUT-THING:

    (OBJECT-CLASS input-thing

    ^item)

    The following CE matches objects of class INPUT-THING whose ^ITEM attribute has the value HOME-KIWI. It also uses the built-in attribute ^$ID to bind an object variable:

    (input-thing ^item home-kiwi ^$ID <my-input-thing>)

     

 

== (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.

  • Format
  • ^attribute= = value-expression

    ^attribute value-expression

     

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.

  • Format
  • Value-expression = = value-expression

     

  • operands
  • ^attribute

    An attribute of a WMO whose value is to be tested

    value-expression

    Any RuleWorks expression, whose value is to be tested

     

  • Examples
  • The following CE uses the implied identity predicate:

    (active-context ^name verify-configuration)

    The relational expression below, of necessity, uses the explicit identity predicate:

    (if ((is-open infile) = = nil)

    then (openfile infile orders.dat in))

     

<> (Nonidentity)

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

  • Example
  • The following two Ces test for the existence of one and only one object of class MEMORY:

    (memory ^$ID <the-mem>)

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

 

= (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.

  • Format
  • ^attribute = value-expression

  • Operands
  • ^attribute

    An attribute of a WMO whose value is to be tested

    value-expression

    Any RuleWorks expression, whose value is to be tested

  • Example
  • The following CE uses the less restrictive equality predicate:

    (active-context ^name = verify-configuration)

 

-= (Inequality)

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

  • Example
  • This attribute-value test is the converse of the previous example:

    (active-context ^name -= verify-configuration)

 

~= (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:

  • Two numbers are considered to be similar when the difference between their values is less than or equal to 1 percent of the larger absolute value. Like the equality predicate, the similarity predicate automatically converts between the INTEGER and FLOAT data types.
  • Two symbols are similar when one of the following is true:
    • they are identical or equal (equality is independent of case)
    • Both symbols are at least three characters long, and adding a single character to one symbol makes it equal to the other
    • Both symbols are at least three characters long, and transposing two characters in one symbol makes it equal to the other
    • they have identical SOUNDEX values
    • SOUNDEX values are calculated according to an algorithm similar to that published in The Art of Computer Programming, Volume 3, pages 391-392, by Donald Knuth. The English-language rules are as follows:

      1. Find the first alphabetic character in the symbol, and convert it to uppercase.

      2. Convert all non-alphabetic characters to a code of 0.

      3. Ignoring case, replace each consonant (after the first alphabetic character), except H's and W's, with its corresponding consonant group code number:

      B, F, P, V 1

      C, G, J, K, Q, S, X, Z 2

      D, T 3

      L 4

      M, N 5

      R 6

      4. If two or more adjacent characters contain the same code, remove all but the first.

      5. Ignoring case and leaving the first alphabetic character, remove all the vowels (including Y), H's, and W's, and all remaining zeroes and spaces.

  • For all other data types, similarity is the same as identity. For example, assuming <the-id> is already bound, the two attribute-value tests shown below match under the same circumstances:
  • ^$ID == <the-id>

    ^$ID ~= <the-id>

    The identity predicate is more efficient.

    You cannot use the similarity predicate with the binding instance of a variable.

  • 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, whose value is to be tested.

  • Examples
  • The first table shows the results of several similarity test on numbers:

    Table 12. Similarity Testing

    First ValueSecond ValueSimilar?
    4.04Yes
    4.54No
    9.910Yes
    -9.9-10Yes

    The next table shows the SOUNDEX codes of several symbols. Note that the last three codes match exactly:

    Table 13. SOUNDEX Codes and Symbols

    SymbolSOUNDEX Code
    TracyT62
    LarryL6
    St. LaurentS34653
    StevenS315
    StephenS315
    StefanoS315

 

-~= (Dissimilarity)

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

  • Examples
  • The table below shows the results of several dissimilarity tests:

    Table 14. Dissimilarity Testing

    First ValueSecond ValueDissimilar?
    4.04No
    4.54Yes
    9.910No
    -9.9-10No

 

> (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.

  • Format
  • (ENTRY-BLOCK block-name

      [(ACCEPTS {<f-param-name> [[[size]]] ext-type [passing-mech]}.)]

      [(RETURNS {<f-param-name> [[[size]]] ext-type [passing-mech]}.)]

      [(ACTIVATES rule-block-name.)}

      [(USES decl-block-name.)]

      [(STRATEGY|MEA|)])

      |LEX| )])

  • Argument
  • block-name

    A symbol that names the block. This name must be distinct from all routine names and other block names in your program and must conform to any restrictions imposed by your platform's linker. It must also satisfy the C language requirements for a function name:

      cannot contain the characters "<>[]%^-

      less than 32 characters long

      different from all C keywords

    Note: Naming an entry block MAIN (or |main|), with no ACCEPTS or RETURNS clause, generates a C-compliant "main function". RuleWorks automatically adds a return value of type LONG.

    The RuleWorks compiler generates a warning if an entry block named MAIN violates the C language restrictions on passing parameters to the main function: either zero or two parameters, one SHORT and one array of strings.

  • Clauses
  • Accepts

    Defines the input argument list of the entry block. Note that the name and data type are required for each argument; the size (of an array) and passing mechanism are optional.

    f-param-nameA RuleWorks variable name for the formal parameter.
    Variables bound to input arguments are visible to the entry block's ON-statements. They are not visible to rules unless you put them in working memory in your ON-ENTRY or ON-EVERY statement.
    [[size]]If a parameter is an array, you can indicate its expected size with either an integer or a variable bound to a previous parameter. The size is optional; the brackets are not.

    ext-type

    The external data type of input argument is passed. This argument is optional; the default mechanism is determined by the argument's external data type (see Table 6-1)

    passing-mech

    The mechanism by which the argument is passed. This arument is optional; the default mechanism is determined by the arguments external data type.

  • RETURNS
  • Specifies the external data type and passing mechanism information for the entry block's return value, if any. This clause is optional, but if you provide one RuleWorks checks that you also provide at least one RETURN action.

    f-param-name

    A variable name for the return value. This argument is optional; you can use a name to make your code easier to read.

    [size]

    If the return value is compound, you must indicate its expected size. You can use either an input parameter of an integer type (byte, short long, and so on; see Table 6-2), or an integer constant.

    Ext-type

    The external data type of the return value. See Table 6-1 for RuleWorks external data types.

    Passing-mech

    The passing mechanism by which the value is returned. This argument is optional; the default mechanism is determined by the value's external data type (see Table 6-1)

  • ACTIVATES
  • Indicates which rule blocks are eligible to fire. This clause is optional.

    Rule-block-name. A symbol that names a rule block. You specify one or more rule blocks.

    All rule blocks activated by an entry block are enabled automatically when the entry block is called. They must all use the same conflict-resolution strategy as the entry block that invoke them.

     

  • USES
  • Indicates which declaration blocks are shared by the entry block. This clause is optional.

    Declaration

    decl-block-name. A symbol that names a declaration block. You can specify one or more declaration blocks.

    The declaration block(s) used by an entry block must be compiled before the entry block itself can be compiled.

     

  • STRATEGY
  • Specifies the conflict-resolution strategy (see section 1.5). This clause is optional. If you do not declare a strategy, the default MEA is used.

    LEX The lexicographic-sort strategy.

    MEA The means-end analysis strategy

    Example

    This example shows a simple counting program:

     

    (entry-block |main|

      (accepts <argc> long

        <argv> [2] asciz)

      (returns long))

     

    (object-class iterator ^count)

    (object-class limit ^value)

     

    (on-entry

      (write |argC is| <argc> |argV is| <argv> (crlf))

      (bind <num-arg> (integer (nth <argv> 2)))

      (make limit ^value <num-arg>)

      (make iterator ^count 1))

     

    (on-exit (return 0))

     

    (rule increment-rule

      (limit ^value <lim>)

      (iterator ^$id <it> ^count {<num> < <lim> })

      à

      (write <num> (crlf))

      (modify <it> ^count (<num> +1)))

     

    (rule now-done

      (limit ^$id <limit-id> ^value <lim>)

      (iterator ^$id <it> ^count <lim>)

      à

      (write <lim> (crlf))

      (remove <it>)

      (remove <limit-id))

       

    (end-block |main|)

     

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.

  • Format
  • EVERY class-name

    Argument

    Class-name

    A symbolic atom that names an object class visible to the active entry block.

  • Return Value
  • A compound value whose elements are the INSTANCE-Ids of all WMOs that belong to class-name. If class-name has children, instances of those children are included in the returned compound.

    The INSTANCE-Ids are returned in no particular order.

    If the specified class is not visible, returns the empty list ((COMPOUND)).

  • Example
  • The following uses the value returned by the EVERY function in a FOR-EACH action:

      (bind <dogs> (every dog))

      (for-each <dog> in <dogs>

        (wash-pet <dog>)

        (pet-to-vet <dog>)

        (pet-gets-treat <dog>))

    (Wash -pet, pet-to-vet, and pet-gets-treat are hypothetical external routines. Their definitions are left as an exercise for the reader.)

 

EXIT

An obsolescent synonym for the QUIT command.

  • Format
  • EXIT

  • Example
  • The following command exits from the command interpreter and returns control to the operating system:

    RuleWorks> EXIT

    System>

 

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.

  • Format
  • (EXTERNAL-ROUTINE) routine-name

      [(ALIAS actual-routine-name)]

      [(ACCEPTS { [<f-param-name> [ [ [size] ] ] ] ext-type [passing-mech] }.)]

      [(RETURNS { [<f-param-name> [ [size] ] ] ext-type [passing-mech] }.)]

  • Argument
  • routine-name

    The name of the external routine. This must be a symbol that is different from all other routine names and all block names in the program. It must also be different from all RuleWorks actions, built-in functions, and relational operators (AND, NOT, and OR). These restrictions are enforced by the RuleWorks compiler.

    The routine name must also satisfy the C language requirements for a function name:

      cannot contain the characters "<>[]%^-

      less than 32 characters long

      different from all C keywords

  • Clauses
  • ALIAS

    Declares that the external routine's name is not the actual name against which it is to be linked. The most common use of this clause is to map a case-sensitive routine name to a RuleWorks symbol.

    actual-routine-name The real name of the external routine.

    ACCEPTS

    Specifies the name, data type and passing mechanism of the arguments to be passed out to the external routine. The ACCEPTS clause is optional. If you declare any arguments you must also declare the data type of each argument; the name and passing mechanism are optional. Arguments for the ACCEPTS clause are as follows:

    f-param-name

    A formal parameter name for an argument to be passed out, for documentation purposes.

    [ [size] ]

    If included, this declares the argument to be an array. The size of the array is optional; the brackets are not. The size may be an integer or a variable previously bound to an integer in this ACCEPTS clause.

    ext-type

    The name of the external data type. Valid external types are: BYTE, SHORT, LONG, UNSIGNED-BYTE, UNSIGNED-SHORT, UNSIGNED-LONG, SINGLE-FLOAT, DOUBLE-FLOAT, ASCIZ, ASCID, and ATOM.

    passing-mech

    Valid passing mechanisms are: BY REFERENCE READ-ONLY, BY REFERENCE READ-WRITE, and BY VALUE.

    RETURNS

    Also an optional clause, this describes the external routine's return value. Arguments for the RETURNS clause are as follows:

    f-param-name

    A formal parameter name for the return value, for documentation purposes.

    [size]

    If the return value is an array, you must declare its size. You can use a constant or a variable.

    ext-type

    The name of the external data type. Valid external types are: BYTE, SHORT, LONG, UNSIGNED-BYTE, UNSIGNED-SHORT, UNSIGNED-LONG, SINGLE-FLOAT, DOUBLE-FLOAT, ASCIZ, ASCID, and ATOM.

    passing-mech

    Valid passing mechanisms are BY REFERENCE and BY VALUE.

  • Examples
  • The following example declares a VMS routine that returns a random number:

      (EXTERNAL-ROUTINE mth$random

        (ACCEPTS <seed> LONG BY REFERENCE)

        (RETURNS LONG BY VALUE)

    The next example maps the case-sensitive name XtParent to the RuleWorks symbol XT_PARENT:

      (EXTERNAL-ROUTINE xt_parent

        (ACCEPTS <param1> INTEGER)

        (RETURNS <param2> INTEGER)

        (ALIAS "XtParent"))

    The following example declares the ULTRIX routine that returns an environment variable:

      (EXTERNAL-ROUTINE getenv__; from the POSIX library

        (ACCEPTS <env-name> ASCIZ BY REFERENCE READ-ONLY)

        (RETURNS <env-value> ASCIZ BY REFERENCE))

     

  • FOR-EACH
  • Allows iteration over each element in a compound <CONDITION>(TIN) or table value. The index variable is bound and the specified RHS actions are executed once for each iteration.

  • Format (for a compound)
  • (FOR-EACH <element> IN compound-value
    RHS-action ... )

  • Arguments
  • <element>

    The index variable that is bound to each element of the compound value.

    compound-value

    The compound value to be acted upon. This argument may be a bound compound variable or an expression that returns a compound value.

    RHS-action

    Any valid RHS action. You can specify any number of actions.

    <data-value>

    The index variable that is bound to each data value in the table value.

    <key-name>

    The index variable that is bound to each key value in the table value.

    table-value

    The table value to be acted upon. This argument may be a bound table variable or an expression that returns a table value.

  • Examples
  • The following examples uses the FOR-EACH action to print out the names of all the cards in a Kiwi-9200 computer card cage. Note that this also shows how to bind an index variable.

    (rule print-out-cage:do-it

    (active-context ^name print-out-cage)

    (box ^cards-in-slot <cards> )

    -->

    (write (crlf) |The card cage will contain: |)

    (bind <slot-counter> 1)

    (for-each <card> in <cards>

    (write (crlf) (tabto 20) |Slot number| <slot-counter>

    |contains a| <card>)

    (bind <slot-counter> ( <slot-counter> + 1 ) ) ) )

     

  • FLOAT
  • Converts a numeric value into a floating-point number. FLOAT is a stateless function and can be used on either the LHS or RHS.

  • Format
  • (FLOAT numeric-expr )

  • Argument
  • numeric-expr

    An expression that evaluates to an INTEGER or FLOAT. If supplied with a SYMBOL, the FLOAT function converts the first white space delimited token, if possible. If not, or if the argument is an OPAQUE or INSTANCE-ID, the function issues a warning message and returns the floating-point number zero.

    Table 23. FLOAT Calls and their Return Values

    Function Call Return Value Warning Message?

    (FLOAT 3) 3.0 No

    (FLOAT 3.2) 3.2 No

    (FLOAT |3.2|) 3.2 No

    (FLOAT |76 trombones|) 76.0 No

    (FLOAT 2+2) 0.0 Yes

    (FLOAT #32) 0.0 Yes

     

  • GENATOM
  • Returns a system-generated atom, with an optional prefix.

    The RuleWorks atom generator is used by the GENATOM and GENINT actions, and by the rul_genint, rul_gensym, and rul_gensymp routines. Every atom generated for any of these routines is unique while the program is running. The atom generator is global, so that all entry blocks called in a program have unique generated atoms.

    The generated atoms consist of an integer and an optional prefix. Within a program run, the first use of the atom generator returns 1, the second 2, and so on. The rul_genint routine and the GENINT action return an integer with no prefix. The rul_gensymp routine and the GENATOM action return an integer with a prefix that you can specify, or use the default prefix G:. The rul_gensym routine returns an integer prefixed by G:. The table below shows several uses of the atom generator and the atoms it returns:

    Table -24. Atom Generator and Returns

    Routine Call or RHS Action Atom Generated

    rul_genint 1

    rul_gensymp(R:) R:2

    (GENATOM) G:3

    (GENINT) 4

    rul_gensym G:5

     

    The atom generator is reset by the RESTORESTATE action and command.

  • Format
  • (GENATOM [prefix])

  • Argument
  • prefix

    A RuleWorks expression, the print form of which will be the first part of the return value. The default prefix is G:

     

  • Return Value
  • A symbol that consists of the prefix you specify (if any) with an integer appended to it.

  • Example
  • The following BIND action binds the variable <TRANSACTION-ID> to the atom produced by the GENATOM function:

    (bind <transaction-id> (genatom trans-))

  • GENINT
  • Returns a system-generated INTEGER. See GENATOM for details on the RuleWorks atom generator.

     

  • Format
  • (GENINT)

     

  • Return Value
  • An INTEGER value.

     

  • Example
  • The following BIND action binds the variable <TRANSACTION-ID> to the atom produced by the GENINT function:

    (bind <transaction-id> (genint))

  • GET
  • Given a variable bound to an object identifier and an attribute name, returns the value of that attribute of that object. The variable can be bound on either the LHS or the RHS, but GET is allowed on the RHS only.

    The GET function lets you access attribute values on the RHS that you did not bind to variables on the LHS. You can bind the identifier of the object on the LHS, and then use the GET function to return the value of any attribute in that object. You do not need to bind each attribute value separately, only the INSTANCE-ID.

     

  • Format
  • (GET object-id ^attribute-name)

     

  • Arguments
  • Object-id

    A variable bound to, or an expression that evaluates to, an INSTANCE_ID value. Variables can be bound on either the LHS or the RHS of the rule. The class of the object must be visible to the active entry block.

    The RuleWorks compiler issues a warning if it is unable to verify that this argument is an INSTANCE-ID.

    attribute-name

    A symbolic expression that names an attribute in the specified object. It is a run-time warning to use an attribute that is not declared for the specified class.

    Return Value

    The value of the specified attribute in the specified instance; or NIL if the arguments are not correct.

     

  • Example
  • The following example shows one use of the GET function:

    (OBJECT-CLASS fruit

    ^fruit-name

    ^color)

     

    (rule make-a-similar-one

    (fruit ^$ID <The-fruit> ^fruit-name apple)

    à

    (MAKE fruit ^fruit-name apple ^color (GET <The-fruit> ^color)))

  • IF.THEN.ELSE.
  • Executes one or more RHS actions when a relational expression is true, or executes one or more different RHS actions when the expression is false. In other words, provides a branch in the flow of control.

     

  • Format
  • (IF (rel-expr)

    THEN RHS-action.

    [ELSE RHS-action..])

     

  • Arguments
  • rel-expr

    A relational expression that determines which RHS actions are to be executed. This argument must evaluate to either true or false. It may not contain any SQL functions.

    Note: RuleWorks does not have Boolean values. Therefore, this argument must be a comparison of two expressions. It must not be a single value. For example, RuleWorks does not allow (IF (TRUE) THEN.).

    RHS-action

    Any RuleWorks action. You can specify any number of actions.

     

  • Clauses
  • THEN

    Specifies the actions that are to be executed when the relational expression is true. This clause is required.

    ELSE

    Specifies the actions that are to be executed when the relational expression is false. This clause is optional.

  • INTEGER
  • Converts a numeric atom into an integer. INTEGER is a stateless function and can be used on either the LHS or RHS.

  • Format
  • (INTEGER numeric-expr )

  • Argument
  • numeric-expr

    An expression that evaluates to an INTEGER or FLOAT. If supplied with a SYMBOL, the INTEGER function converts the firs-t white space delimited token, if possible. If not, or if the Argument is an OPAQUE or INSTANCE-ID, the function issues a warning message and returns the integer zero.

     

  • Return Value
  • The nearest integer (by rounding) that corresponds to the specified value.

     

  • Examples
  • The following table shows several calls to the INTEGER function and their results:

    Table 25. INTEGER Return Values

    Function Call Return Value Warning Message?

    (INTEGER 3) 3 No

    (INTEGER 3.5) 4 No

    (INTEGER 3.5e4) 35000 No

    (INTEGER |3.2|) 3 No

    (INTEGER |110 cornets|) 110 No

    (INTEGER 2+2) 0 Yes

    (INTEGER #12) 0 Yes

  • IS-OPEN
  • Tests whether a file has already been opened. IS-OPEN is valid on the RHS only.

     

  • Format
  • (IS-OPEN file-id)

     

  • Argument
  • File-id

    A symbolic atom that was associated with a filespec in an OPENFILE action. (See Section 4.5 for more information on input and output.)

     

  • Return Value
  • The mode (IN or OUT) if the file is open; NIL if it is not. If the file is open in mode APPEND, the function returns OUT. (See the OPENFILE action for more information on I/O mode.)

     

  • Example
  • The following IF.THEN.ELSE. action uses the IS-OPEN function:

     

    (if ((is-open infil) <> nil)

    then

    (closefile infil))

  • LENGTH
  • Returns the number of elements in a compound value. LENGTH is a stateless function and can be used on either the LHS or RHS.

     

  • Format
  • LENGTH compound-val

     

  • Argument
  • Compound-val

    The compound value to be counted. This argument can be a bound compound variable or a function that returns a compound value.

     

  • Return Value
  • An integer that specifies the number of elements in the compound value.

     

  • Examples
  • The following condition element shows the LENGTH function used on the LHS:

     

    (box ^card-in-slot <cards> ^max-cards <= (length <cards>))

    The following action shows the LENGTH function used on the RHS:

    (write |The card cage contains| (length <cards> ) |cards.|)

  • MAKE
  • Creates a working-memory object of the specified class, with the specified attribute values (if any). RuleWorks uses the default values for attributes you do not specify (see Chapter 2).

    Note: When you create WMOs at the command interpreter prompt, the first Argument to the MAKE command must be a constant. In contrast, when you create WMOs in source code, the first Argument to the MAKE action can be a variable or a call to the GET function.

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

  • Format (for action)
  • (MAKE class-name [ { ^attribute value-expression }... ] )

  • Format (for command)
  • MAKE class-name [ { ^attribute value }... ] )

  • Arguments(Arguments)
  • class-name

    A symbol or variable that names the class of the object to be created; it must be visible to the active entry block.

    attribute

    A symbol that names an attribute declared in the specified class. This Argument is optional, but if you specify any attributes, you must specify a value with each attribute.

    value-expression

    Any scalar or compound expression (if you specify a compound attribute) is a valid Argument to the MAKE 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 MAKE command.

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