![]() |
|
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 OperatorsTable 1 Summary of Operators - Arithmetic Operators
Table 2 Summary of Operators - Match Operators
Table 3 Summary of Operators - Logical Operators*
Note: Logical operators can be used only within the context of IF ... THEN ... ELSE ... and WHILE ... DO ... actions. Summary of Predicates and Relational OperatorsScalar 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
Table 5. Summary of Compound Predicates and Relational Operators
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
Summary of Actions Table 7. Summary of Actions
Summary of Functions Table 8. Summary of Functions
Summary of Commands Table 9. Summary of Commands
Summary of Declarations Table 10. Summary of Declarations
Summary of SQL Actions Table 11. Summary of SQL Actions
Operator Descriptions This section contains a description of the RuleWorks operators, in alphabetical order. + (Addition) Performs arithmetic addition on numeric values.
numeric-expression + numeric-expression 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. 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).
- condition-element condition-element The CE that is to be negated. Performs arithmetic subtraction on numeric values.
- numeric-expression numeric-expression - numeric-expression 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. 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.
numeric-expression * numeric-expression 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. 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.
numeric-expression / numeric-expression 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. 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.
integer-expression \ integer-expression 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. 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: 13There are 1 dozen in 13 and there are 1 left over Enter an integer: 39There 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.
^ attribute-nameattribute-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. 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 PredicateIn 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.
^attribute= = value-expression ^attribute value-expression
In a relational expression on the RHS, the identity operator is required. There is no default or implied operator inside relational expressions.
Value-expression = = value-expression
^attribute An attribute of a WMO whose value is to be tested value-expression Any RuleWorks expression, whose value is to be tested
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))
Produces a match when the identity predicate (see previous fails to match; evaluates to true when the identity operator evaluates to false.
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.
^ attribute = value-expression^attribute An attribute of a WMO whose value is to be tested value-expression Any RuleWorks expression, whose value is to be tested 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.
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:
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.
^$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. ^ attribute ~= value-expressionvalue-expression ~= value-expression ^attribute An attribute of a WMO whose value is to be tested. value-expression Any RuleWorks expression, whose value is to be tested. The first table shows the results of several similarity test on numbers: Table 12. Similarity Testing
The next table shows the SOUNDEX codes of several symbols. Note that the last three codes match exactly: Table 13. SOUNDEX Codes and Symbols
-~= (Dissimilarity) Produces a match, or evaluates to true, when the similarity predicate (see previous fails to match, or evaluates to false.
The table below shows the results of several dissimilarity tests: Table 14. Dissimilarity Testing
> (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.
^ attribute > value-expressionvalue-expression > value-expression ^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. The following table shows the results of several greater-than tests Table 15. Greater-than Testing
>= (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.
^ attribute >= value-expressionvalue-expression >= value-expression ^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. The following table shows the results of several greater-than-or-equal tests: Table 16. Greater-than-or-Equal Testing
The aardvarks match because they are equal, which is a case insensitive comparison, not because the first value is greater than the second. 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.
^ attribute < value-expressionvalue-expression < value-expression ^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. The following table shows the results of several less-than tests: Table 17. Less-than Testing
<= (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.
^attribute <= value-expression value-expression <= value-expression
^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.
The following table shows the results of several less-than-or equal tests: Table 18 Less-than-or-equal Testing
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.
(^attribute <=> value-expression) (value-expression <=> value-expression) An attribute of a WMO whose value is to be tested. value-expression Any RuleWorks expression, whose value is to be tested. The following CE matches an object of class INPUT-THING whose ^ITEM attribute has a symbolic value: (input-thing ^item <=> symbol )
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.
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.
^compound-attr [+] [predicate] scalar-value ^scalar-attr [predicate] [+] compound-value compound-value [+] [predicate] scalar-value scalar-value [predicate] [+] compound-value
^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
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.
Produces a match when the containment predicate (see previous page) fails to match; evaluates to true when the containment operator evaluates to false.
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.
^compound-attr [=] integer-value compound-value [=] integer-value
^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.
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.
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.
^compound-attr [>] integer-value compound-value [>] integer-value ^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.
^compound-attr [>=] integer-value compound-value [>=] integer-value ^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.
^ compound-attr [<] integer-value)compound-value [<] integer-value ^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. 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.
^ compound-attr [<=] integer-valuecompound-value [<=] integer-value ^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. 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.
{ conditional-test ... }conditional-test One or more conditional tests that the value of an attribute in an object is to satisfy. 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).
<< value-expression.>> 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. 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
@ filespecfilespec 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. The first command illustrates a simple file specification: RuleWorks> @ init-mem.wmThe 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.
ACCEPT-ATOM [ file-id ]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. 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))
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.
ACCEPTLINE-COMPOUND [file-id [default-compound-value]] 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. 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. 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>))
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.
(ADDSTATE filespec) filespec A file specification for a file previously produced by the SAVESTATE action or command. See Section C.1 for restrictions on file names. 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.datOn 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.
AFTER cycles catcher-namecycles 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. 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-CYCLESThe 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.
rel-expr AND rel-expr rel-expr The relational expressions to be combined. These arguments must evaluate to either true or false. 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.
BIND variable value-expressionvariable 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.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.
CATCH catcher-name action.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. 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.
CLOSEFILE file-id ...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. 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.
COMPOUND [ element ] ...element Any valid scalar or compound value expression. A compound value that contains all the elements of the specified arguments. 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.
CONCAT [value-expr]...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. 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. 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.
COPY ID-variable [{^attribute value-expression}...] COPY instance-id [ {^attribute value}...] 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. The COPY action returns the INSTANCE-ID atom that identifies the new WMO. 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 #31RuleWorks> 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.
CRLF None 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:
CS The following command displays the contents of the conflict set: RuleWorks> csPOP-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.
DEBUG None 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.
(DECLARATION-BLOCK block-name) block-name A symbol that names the block. This name must be distinct from all other block names in your program. 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.)
DEFAULT file-id io-typefile-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
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 inRuleWorks> default infil acceptThe 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
DISABLE keywordkeyword 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
The following command disables the WMHISTORY command: RuleWorks> disable wmhEBREAK 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.
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.
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.
ENABLE keywordkeyword A keyword that specifies the feature to be enabled. Table 22. ENABLE Keywords
The following command enables run-time messages. RuleWorks>
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.
(END-BLOCK [block-name])block-name The symbol that names the block being terminated. This argument is optional, but if you provide it the compiler checks it. 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. (END-GROUP [group-name])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.
(ENTRY-BLOCK block-name[(ACCEPTS {<f-param-name> [ [(RETURNS {<f-param-name> [[[size]]] ext-type [passing-mech]}.)] [(ACTIVATES rule-block-name.)} [(USES decl-block-name.)] [(STRATEGY|MEA|)]) |LEX| )]) 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. 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.
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.
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.
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.
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.
EVERY class-nameArgument Class-name A symbolic atom that names an object class visible to the active entry block. 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)). 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.
EXIT 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.
(EXTERNAL-ROUTINE) routine-name [(ALIAS [(ACCEPTS { [<f-param-name> [ [ [size] ] ] ] ext-type [passing-mech] }.)] [(RETURNS { [<f-param-name> [ [size] ] ] ext-type [passing-mech] }.)] 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 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:
RETURNS Also an optional clause, this describes the external routine's return value. Arguments for the RETURNS clause are as follows:
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))
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. (FOR-EACH <element> IN compound-value <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. 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 ) ) ) )
Converts a numeric value into a floating-point number. FLOAT is a stateless function and can be used on either the LHS or RHS. (FLOAT numeric-expr ) 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
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. (GENATOM [prefix])prefix A RuleWorks expression, the print form of which will be the first part of the return value. The default prefix is G:
A symbol that consists of the prefix you specify (if any) with an integer appended to it. The following BIND action binds the variable <TRANSACTION-ID> to the atom produced by the GENATOM function: (bind <transaction-id> (genatom trans-)) Returns a system-generated INTEGER. See GENATOM for details on the RuleWorks atom generator.
(GENINT)
An INTEGER value.
The following BIND action binds the variable <TRANSACTION-ID> to the atom produced by the GENINT function: (bind <transaction-id> (genint)) 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.
(GET object-id ^attribute-name)
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.
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))) 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.
(IF (rel-expr) THEN RHS-action. [ELSE RHS-action..])
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.
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. Converts a numeric atom into an integer. INTEGER is a stateless function and can be used on either the LHS or RHS. (INTEGER numeric-expr ) 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.
The nearest integer (by rounding) that corresponds to the specified value.
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
Tests whether a file has already been opened. IS-OPEN is valid on the RHS only.
(IS-OPEN file-id)
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.)
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.)
The following IF.THEN.ELSE. action uses the IS-OPEN function:
(if ((is-open infil) <> nil) then (closefile infil)) Returns the number of elements in a compound value. LENGTH is a stateless function and can be used on either the LHS or RHS.
LENGTH compound-val
Compound-val The compound value to be counted. This argument can be a bound compound variable or a function that returns a compound value.
An integer that specifies the number of elements in the compound value.
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.|) 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. (MAKE class-name [ { ^attribute value-expression }... ] ) MAKE class-name [ { ^attribute value }... ] ) 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. The MAKE action returns the INSTANCE-ID atom that identifies the new WMO. |