home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / misc / demo / clips.sit / CLIPS.HLP < prev    next >
Encoding:
Text File  |  1988-03-03  |  98.3 KB  |  3,204 lines

  1. /*  CLIPS Version 4.20C-Beta 2/12/88 */
  2. 0MBEGIN-ENTRY-MAIN
  3.  
  4. HELP_USAGE       RHS_SYNTAX
  5. LIST_OF_TOPICS   USING_CLIPS
  6. CLIPS_OVERVIEW   APPENDICES
  7. LHS_SYNTAX       TEXT_PROCESSING
  8.  
  9. END-ENTRY
  10.  
  11. 1IBEGIN-ENTRY-HELP_USAGE
  12.  
  13. HELP_USAGE
  14.  
  15. H.2 Using the Help Facility
  16. The first call to the help facility will take longer than successive calls,
  17. for the system is loading the help information into an internal lookup
  18. table.  All later lookups will be virtually instantaneous (unless the help file
  19. is unloaded - see Text Processing - Toss).
  20.  
  21. The help facility displays menus of topics and prompts the user for a choice.
  22. It then references the file named in CLIPS.H for that information.  The help
  23. facility can be called with or without a command-line topic.
  24.  
  25. Syntax :
  26.   
  27.   (help [<path>])
  28.  
  29. where <path> is the full path leading to a topic in the help tree.
  30. For example, to access the entry on run-time error messages, you would
  31. type : (help appendices error_messages run-time_errors).
  32.  
  33. Each element or field in the path is delimited by white-space, and the help
  34. facility is not case sensitive.  In addition, the entire name of a field need
  35. not be specified. Only enough characters to distinguish the field from other
  36. choices in the menu are necessary (if there is a conflict, the help facility
  37. will pick the first one in the list).  For instance, (help app err run) would
  38. be sufficient for the above example.
  39.  
  40. There are a few special fields that can be specified :
  41.   ^    -  Branch up one level.
  42.   ?    -  When specified at the end of a path, this forces a display of
  43.           the current menu, even on branch-ups.
  44. <nil>  -  Giving no topic field will branch up one level.
  45.  
  46. A branch-up from the MAIN topic root node implies an exit from help.
  47.  
  48. By default, the help facility comes up in the MAIN topic root menu, and the
  49. user may make a choice as described above.  The prompt line always displays
  50. the name of the current menu.  The help facility will branch through the
  51. help-tree until instructed to exit by a branch-up from the top level (see
  52. above).
  53.  
  54. The level of the help-tree does not remain constant between calls to the help
  55. facility.  The level is alawys reset to MAIN upon exit.
  56.  
  57. END-ENTRY
  58.  
  59. 1IBEGIN-ENTRY-LIST_OF_TOPICS
  60.  
  61. HELP
  62. CLIPS_OVERVIEW
  63.   RULES
  64.   FACTS
  65.   BASIC_CYCLE_OF_EXECUTION
  66.   REFERENCE_MANUAL_SYNTAX
  67.   DEFINING_CONSTRUCTS
  68.     DEFINING_RULES
  69.     DEFINING_INITIAL_FACTS
  70.   COMMENTING_CLIPS_RULES
  71.   INTEGRATION_WITH_OTHER_LANGUAGES
  72.  
  73. LHS_SYNTAX
  74.   LITERAL_PATTERNS
  75.   WILDCARDS
  76.   VARIABLES
  77.   CONSTRAINING_FIELDS
  78.     LOGICAL_OPERATORS
  79.     PREDICATE_FUNCTIONS
  80.     CONSTRAINING_FIELDS_THROUGH_PATTERN_EXPANSION
  81.   USING_TEST_TO_CONSTRAIN_VARIABLES
  82.   CONSTRAINING_PATTERNS
  83.     INCLUSIVE_OR
  84.     EXPLICIT_AND
  85.     PATTERN_NEGATION
  86.   PATTERN_BINDINGS
  87.   DECLARING_RULE_PROPERTIES
  88.     ASSIGNING_RULE_PRIORITY
  89.  
  90. RHS_SYNTAX
  91.   BASIC_ACTIONS
  92.     CREATING_NEW_FACTS
  93.        CALLING_EXTERNAL_FUNCTIONS
  94.     REMOVING_FACTS_FROM_THE_FACT-LIST
  95.     ASSERTING_A_STRING
  96.     BINDING_VARIABLES
  97.     STOPPING_CLIPS
  98.   MULTI-FIELD_FUNCTIONS
  99.     NUMBER_OF_ELEMENTS
  100.     SPECIFYING_AN_ELEMENT
  101.     FINDING_AN_ELEMENT
  102.   CLIPS_I/O_SYSTEM
  103.     LOGICAL_NAMES
  104.     COMMON_I/O_FUNCTIONS
  105.       OPEN
  106.       CLOSE
  107.       READ
  108.       READLINE
  109.       PRINTOUT
  110.       FPRINTOUT
  111.       FORMAT
  112.   MATH_FUNCTIONS
  113.     STANDARD_MATH_FUNCTIONS
  114.     EXTENDED_MATH_FUNCTIONS
  115.   ADDITIONAL_FUNCTIONS
  116.     SYSTEM
  117.     GENSYM
  118.     SETGEN
  119.     CALL
  120.     IF...THEN...ELSE
  121.     WHILE
  122.     STRING_CONCATENATION
  123.     USING_CLIPS_INTERFACE_COMMANDS
  124.  
  125. USING_CLIPS
  126.   ENVIRONMENT_COMMANDS
  127.   SYSTEM_STATUS_COMMANDS
  128.   DEBUGGING_COMMANDS
  129.   MEMORY_MANAGEMENT_COMMANDS
  130.   ADDITIONAL_COMMANDS
  131.  
  132. APPENDICES
  133.   DEFINED_FUNCTIONS
  134.   VERSION_DIFFERENCES
  135.   GLOSSARY
  136.   ERROR_MESSAGES
  137.     RUN-TIME_ERRORS
  138.     RULE_PARSING_ERRORS
  139.  
  140. TEXT_PROCESSING
  141.   ENTRY_FILE_FORMAT
  142.   FETCH
  143.   PRINT-REGION
  144.   TOSS
  145.  
  146. END-ENTRY
  147.  
  148. 1MBEGIN-ENTRY-CLIPS_OVERVIEW
  149.  
  150. CLIPS_OVERVIEW
  151.  
  152. 2.0 CLIPS Overview
  153. This section gives a general overview of CLIPS and the basic concepts used 
  154. throughout this manual.
  155.  
  156. Subtopics :
  157.  
  158.   RULES                     DEFINING_CONSTRUCTS
  159.   FACTS                     COMMENTING_CLIPS_RULES
  160.   BASIC_CYCLE_OF_EXECUTION  INTEGRATION_WITH_OTHER_LANGUAGES
  161.   REFERENCE_MANUAL_SYNTAX
  162.  
  163. END-ENTRY
  164.  
  165. 2IBEGIN-ENTRY-RULES
  166.  
  167. CLIPS_OVERVIEW
  168.   RULES
  169.   
  170. 2.1 Rules
  171. The primary method of representing knowledge in CLIPS is a rule. A rule is a 
  172. collection of conditions and the actions to be taken if the conditions are
  173. met. The developer of an expert system defines the rules which describe howto
  174. solve a problem. The entire set of rules in an expert system is called
  175. knowledge base. CLIPS provides the mechanism (the inference engine) which
  176. attempts to match the rules to the current state of the system and applies
  177. the actions. The current state is represented by a list of facts.
  178.  
  179. END-ENTRY
  180.  
  181. 2IBEGIN-ENTRY-FACTS
  182.  
  183. CLIPS_OVERVIEW
  184.   FACTS
  185.  
  186. 2.2 Facts
  187. Facts are the basic form of data in a CLIPS system. Each fact represents a 
  188. piece of information which has been placed in the current list of facts, 
  189. called the fact-list. Rules execute (or fire) based on the existence or 
  190. non-existence of facts. A fact is constructed of several fields separated 
  191. by spaces. Any number of fields may be stored in a fact, and the number of 
  192. facts in the fact-list is limited only by the amount of memory in the 
  193. computer. Facts may be asserted into the fact-list prior to starting 
  194. execution and may be added (asserted) or removed (retracted) as the action 
  195. of a rule firing.  If a fact is asserted into the fact-list that exactly 
  196. matches a fact that already exists, then the new assertion will be ignored.
  197.  
  198. Each field within a fact can be one of three things: a number, a word, or a
  199. string. A number is any field which consists only of numbers (0-9), a 
  200. decimal point (.), a sign (+ or -), and optionally, an (e) for exponential 
  201. notation with it's corresponding sign. Some examples are:
  202.  
  203.    237   15.09   +12.9   -32.3e-7
  204.  
  205. All numbers are stored as single precision floating point values, regardless
  206. of whether or not a decimal point was included. The number of significant 
  207. digits will depend upon the machine implementation. Roundoff errors may also
  208. occur, again depending on the machine implementation.
  209.  
  210. A word in CLIPS is any set of characters that starts with an alphabetic 
  211. character and is followed by zero or more letters (A-z), numbers (0-9), 
  212. underscores(_), or dashes (-). The word is ended by a space. Some examples 
  213. are:
  214.  
  215.    foo   Hello   B76-HI   bad_value
  216.  
  217. Spaces or other special characters may not be included within a word. CLIPS
  218. is case sensitive, i.e. uppercase letters will only match with uppercase
  219. letters.
  220.  
  221. A string is a set of characters that starts with a double quotes (") and is
  222. followed by one or more letters (A-z), numbers (0-9), underscores(_), dashes
  223. (-), spaces, or special characters (any printable character). A string ends
  224. with double quotes. Double quotes or other special characters may be 
  225. embedded within a field by placing a backslash (\) in front of the 
  226. character. Some examples are:
  227.  
  228.    "foo"   "a and b"   "1 number"   "a\"quote"
  229.  
  230. Note that a string surrounded by double quotes will only match another 
  231. string. Strings will not match a word or vice versa. Strings are sometimes
  232. referred to as quoted strings.
  233.  
  234. CLIPS facts are free form, which means there are no reserved words. All 
  235. fields may be of any allowed type, and there is no restriction on the 
  236. ordering of fields. 
  237.  
  238. The first fact in the fact-list is automatically asserted by the system
  239. during a reset. This fact, (initial-fact), can be treated like any other 
  240. fact and may be matched or retracted.
  241.  
  242. END-ENTRY
  243.  
  244. 2IBEGIN-ENTRY-BASIC_CYCLE_OF_EXECUTION
  245.  
  246. CLIPS_OVERVIEW
  247.   BASIC_CYCLE_OF_EXECUTION
  248.  
  249. 2.3 Basic Cycle of Execution
  250. Once a knowledge base (in the form of rules) is built, and the fact-list is
  251. prepared, CLIPS is ready to execute rules. In a conventional language, the
  252. starting point, the stop point and the sequence of operations are explicitly
  253. defined by the programmer. With CLIPS, the program flow does not need to be
  254. defined quite so explicitly. The knowledge (rules) and the data (facts) are
  255. separated and the inference engine provided by CLIPS is used to apply the
  256. knowledge to the data. The basic execution cycle is:
  257.  
  258. 1)   the knowledge base is examined to see if any rule's conditions have 
  259.      been met,
  260.  
  261. 2)   all rules whose conditions are currently met are activated and placed 
  262. on the agenda. The agenda is essentially a stack. Rules are pushed onto the
  263. stack when they are activated. If the priority of the new rule is less than
  264. the rule currently on top of the stack, the new rule is pushed down the 
  265. stack until all rules of higher priority are above it. Rules of equal or 
  266. lower priority will remain below the new rule.
  267.  
  268. 3)   the top rule on the agenda is selected and it's right hand side actions
  269.      executed.
  270.  
  271. As a result of right-hand side actions, new rules can be activated or 
  272. deactivated. This cycle is repeated until all rules that can fire have done
  273. so, or until the rule limit is reached. The number of rule firings allowed 
  274. in a cycle may be set by the programmer, and rule priorities can be assigned 
  275. (see LHS_SYNTAX DECLARING_RULE_PROPERTIES ASSIGNING_RULE_PRIORITY).
  276.  
  277. END-ENTRY
  278.  
  279. 2IBEGIN-ENTRY-REFERENCE_MANUAL_SYNTAX
  280.  
  281. CLIPS_OVERVIEW
  282.   REFERENCE_MANUAL_SYNTAX
  283.  
  284. 2.4 Reference Manual Syntax
  285. The terminology used throughout this manual to describe CLIPS syntax is 
  286. fairly common to computer reference manuals. Plain words or symbols are to 
  287. be typed exactly as they appear, particularly parentheses. Symbols enclosed
  288. in single angle brackets, such as <name>, represent a single field to be
  289. defined by the user. Symbols enclosed in double angle brackets, such as 
  290. <<pattern>>, represent one or more fields which must be defined by the user.
  291. Symbols enclosed within square brackets, such as [<<comment>>] are optional
  292. parameters. White spaces (tabs, spaces, carriage returns) are used by CLIPS
  293. only as delimiters between fields and are otherwise ignored (unless inside
  294. double quotes). Examples in this manual show recommended indentation style. 
  295.  
  296. Small pieces of C code are also used in this manual. The syntax used for C 
  297. code is slightly different and is more in keeping with the convention used 
  298. in standard C manuals.
  299.  
  300. END-ENTRY
  301.  
  302. 2MBEGIN-ENTRY-DEFINING_CONSTRUCTS
  303.  
  304. CLIPS_OVERVIEW
  305.   DEFINING_CONSTRUCTS
  306.  
  307. 2.5 Defining Constructs
  308. There are two defining constructs in CLIPS, defrule, and deffacts. All 
  309. constructs in CLIPS are surrounded by parentheses. The construct opens with
  310. a left parenthesis, and closes with a right parenthesis. Each pattern or
  311. block within a construct also opens and closes with parentheses.
  312.  
  313. Subtopics :
  314.  
  315.     DEFINING_RULES    DEFINING_INITIAL_FACTS
  316.  
  317. END-ENTRY
  318.  
  319. 3IBEGIN-ENTRY-DEFINING_RULES
  320.  
  321. CLIPS_OVERVIEW
  322.   DEFINING_CONSTRUCTS
  323.     DEFINING_RULES
  324.  
  325. 2.5.1 Defining Rules
  326. Rules are defined using the defrule construct. Each rule in CLIPS must have
  327. at least one condition and one action. There is no limit to the number of
  328. conditions or actions a rule may have (other than the limitation of actual
  329. available memory).
  330.  
  331. Syntax:
  332.  
  333.       (defrule <name> ["<comment>"]
  334.       (<<first pattern>>)
  335.       [   
  336.                 ; Left-Hand Side
  337.                 ;       (LHS)
  338.        (<<nth pattern>>)]
  339.       =>
  340.        (<<first action>>)
  341.       [   
  342.                 ; Right-Hand Side
  343.                 ;       (RHS)
  344.        (<<mth action>>)])    
  345.  
  346. where <name> is the name of the rule and is a word. The comment is optional
  347. and can be any string enclosed within double quotes.  The Left-Hand side
  348. (LHS) is made up of a series of one or more patterns which represent the
  349. condition elements for the rule. There is always an implicit and surrounding
  350. all the patterns on the LHS. On the Right-hand side (RHS) we have a list of
  351. one or more actions to be performed when the LHS of the rule is satisfied.
  352. The arrow (=>) separates the LHS from the RHS. Actions are performed
  353. sequentially if and only if all condition elements on the LHS are satisfied.
  354.  
  355. Example:
  356.  
  357.    (defrule example-rule   "This is an example of a simple rule"
  358.       (refrigerator light on)
  359.       (refrigerator door open)
  360.       =>
  361.       (assert (refrigerator food spoiled)))
  362.  
  363. END-ENTRY
  364.  
  365. 3IBEGIN-ENTRY-DEFINING_INITIAL_FACTS
  366.  
  367. CLIPS_OVERVIEW
  368.   DEFINING_CONSTRUCTS
  369.     DEFINING_INITIAL_FACTS
  370.  
  371. 2.5.2 Defining Initial Facts
  372. With the deffacts construct, facts can be added to the initial fact-list.
  373. Facts asserted through deffacts may be retracted or pattern matched like any 
  374. other fact. The initial fact-list, including any defined deffacts, is
  375. reconstructed after a reset.
  376. Syntax:
  377.  
  378.    (deffacts <name> ["<comment>"]
  379.       (<<fact 1>>)
  380.       [   
  381.           
  382.           
  383.       (<<fact n>>)]) 
  384.  
  385. where <name> is a word used to identify the set of facts. An optional
  386. comment may also be included. There may be multiple deffacts constructs.
  387. Any number of facts may be asserted into the initial fact-list in each
  388. deffacts statement.
  389.  
  390. Example:
  391.  
  392.    (deffacts initial-facts
  393.       "This is a set of facts needed prior to execution"
  394.       (refrigerator light on)
  395.       (refrigerator door open)
  396.  
  397. END-ENTRY
  398.  
  399. 2IBEGIN-ENTRY-COMMENTING_CLIPS_RULES
  400.  
  401. CLIPS_OVERVIEW
  402.   COMMENTING_CLIPS_RULES
  403.  
  404. 2.6 Commenting CLIPS Rules
  405. As with any programming language, it is highly beneficial to comment the
  406. code. Both defrule and deffacts allow a comment directly following the
  407. construct name. Comments can also be placed within CLIPS code by using a
  408. semicolon (;). Everything from the semicolon until the next return character
  409. will be ignored by the CLIPS reader. If the semicolon is the first character
  410. in the line, the entire line will be treated as a comment. Examples of 
  411. commented code will be provided throughout the reference manual.
  412.  
  413. END-ENTRY
  414.  
  415. 2IBEGIN-ENTRY-INTEGRATION_WITH_OTHER_LANGUAGES
  416.  
  417. CLIPS_OVERVIEW
  418.   INTEGRATION_WITH_OTHER_LANGUAGES
  419.  
  420. 2.7 Integration with Other Languages
  421. When using an expert system, two kinds of integration are important; 
  422. embedding CLIPS in other systems, and calling external functions from the
  423. right or left hand side of a CLIPS rules. CLIPS was designed to allow both
  424. kinds of integration.  
  425.  
  426. Using CLIPS as an embedded application allows the easy integration of CLIPS
  427. with existing systems. It is useful in cases where the expert system is a
  428. small part of a larger task, or needs to share data with other functions.
  429. In these situations, CLIPS can be called as a subroutine and information 
  430. may be passed both to and from CLIPS. Embedded applications are discussed 
  431. in the Advanced Programming Guide.
  432.  
  433. It may also be useful to call external functions while executing a CLIPS
  434. rule. CLIPS allows external function calls on both the LHS and RHS of a 
  435. rule. On the LHS they can be called as predicate functions to allow 
  436. specialized testing of a rule's conditions. On the RHS of a rule, they can 
  437. be called for a number of reasons, such as a function to alert the user when
  438. an error condition is detected. User defined external functions may also be
  439. called from the top level of the interactive interface. CLIPS variables or 
  440. literal values may be passed to an external function, and functions may
  441. return values to CLIPS. The easy addition of external functions allows CLIPS
  442. to be extended or customized in almost any way. The Advanced Programming 
  443. Guide describes how to integrate CLIPS with functions or systems written in
  444. C as well as other languages.
  445.  
  446. END-ENTRY
  447.  
  448. 1MBEGIN-ENTRY-LHS_SYNTAX
  449.  
  450. LHS_SYNTAX
  451.  
  452. 3.0 LHS Syntax- Conditions
  453. This section describes the syntax of pattern on the LHS of a rule. These 
  454. patterns represent the conditions that must be satisfied before a rule can
  455. fire.
  456.  
  457. Subtopics :
  458.  
  459.   LITERAL_PATTERNS       USING_TEST_TO_CONSTRAIN_VARIABLES
  460.   WILDCARDS              CONSTRAINING_PATTERNS    
  461.   VARIABLES              PATTERN_BINDINGS
  462.   CONSTRAINING_FIELDS    DECLARING_RULE_PROPERTIES
  463.  
  464. END-ENTRY
  465.  
  466. 2IBEGIN-ENTRY-LITERAL_PATTERNS
  467.  
  468. LHS_SYNTAX
  469.   LITERAL_PATTERNS
  470.  
  471. 3.1 Literal Patterns
  472. The most basic pattern is one that precisely defines the exact fact that will
  473. match.  This is called a literal pattern All fields in a literal pattern must
  474. be matched by all fields in a pattern in the fact-list. There are no
  475. variables in a literal pattern.
  476.  
  477. Examples:
  478.  
  479.    Pattern on LHS of rule   Fact in the fact-list        Matches?
  480.    (group left town)        (group left town)               Y
  481.    (group left town)        (group in town)                 N
  482.    (group in Houston)       (group in Houston)              Y
  483.    (group in Houston)       (group in HOUSTON)              N
  484.    (group in my home state) (group in "my home state")      N
  485.    (data "a red flag")      (data "a red flag")             Y
  486.    (data 1)                 (data 1.0)                      Y
  487.    (data 100.321)           (data 100.3)                    N
  488.  
  489. Note that space or control characters inside double quotes (i.e in a string)
  490. could cause problems. Also, roundoff errors could make it difficult to match
  491. numerical values to more than 3 or 4 decimal places.
  492.  
  493. END-ENTRY
  494.  
  495. 2IBEGIN-ENTRY-WILDCARDS
  496.  
  497. LHS_SYNTAX
  498.   WILDCARDS
  499.  
  500. 3.2 Wildcards- Single and Multi-field
  501. CLIPS has two kinds of wildcard symbols that may be used to represent fields
  502. in a pattern. These are the question, "?" and dollar-question, "$?" 
  503. wildcards.  CLIPS interprets these wildcard symbols as standing in place of
  504. some part of a fact. The question wildcard matches any value (number, word
  505. or string) stored in exactly one field in the fact. It is a wildcard : 
  506. single-field wildcard symbol. The dollar-question wildcard matches any value
  507. in zero or more fields in a fact. It is a wildcard : multi-field wildcard
  508. symbol, standing in the place of multiple fields. Single and multi-field
  509. wildcards may be combined in a single pattern in any combination.
  510.  
  511. Examples:
  512.  
  513.    Pattern on LHS of rule   Fact in the fact-list   Matches?
  514.    (data red ?)             (data red)                 N
  515.    (data red ?)             (data red green)           Y
  516.    (data red ?)             (data red "green")         Y
  517.    (data red ?)             (data red green green)     N
  518.    (data red ?)             (data green red)           N
  519.  
  520.    (data red $?)            (data red)                 Y
  521.    (data red $?)            (data red green)           Y
  522.    (data red $?)            (data red "green")         Y
  523.    (data red $?)            (data red green green)     Y
  524.    (data red $?)            (data green red)           N
  525.  
  526.    (data ? ?)               (data red)                 N
  527.    (data ? ?)               (data red green)           Y
  528.    (data ? ?)               (data red "green")         Y
  529.    (data ? ?)               (data red green green)     N
  530.    (data ? ?)               (data green red)           Y
  531.  
  532.    (data ? $?)              (data red)                 Y
  533.    (data ? $?)              (data red green)           Y
  534.    (data ? $?)              (data red "green")         Y
  535.    (data ? $?)              (data red green green)     Y
  536.    (data ? $?)              (data green red)           Y
  537.  
  538.    (data $? ?)              (data red)                 Y
  539.    (data $? ?)              (data red green)           Y
  540.    (data $? ?)              (data red "green")         Y
  541.    (data $? ?)              (data red green green)     Y
  542.    (data $? ?)              (data green red)           Y
  543.  
  544. Multi-field wildcard and literal fields can be combined to provide very
  545. powerful constructs. A pattern to match all the facts that have the word
  546. YELLOW in any field (other than the first) could be written as:
  547.  
  548.    (data $? YELLOW $?)
  549.  
  550. Some examples of what this pattern would match are:
  551.  
  552.    (data YELLOW blue red green)
  553.    (data YELLOW red)
  554.    (data red YELLOW)
  555.    (data YELLOW)
  556.    (data YELLOW data YELLOW)
  557.  
  558. The last fact will match twice, since YELLOW appears twice in the fact. The
  559. use of the multi-field wildcard should be confined to cases of patterns in
  560. which the single-field wildcard cannot create a pattern that satisfies the
  561. match required, since the multi-field wildcard produces every possible match
  562. combination that can be derived from a fact. This derivation of matches
  563. requires a significant amount of time to perform compared to the time needed
  564. to perform a single-field match.
  565.  
  566. END-ENTRY
  567.  
  568. 2IBEGIN-ENTRY-VARIABLES
  569.  
  570. LHS_SYNTAX
  571.   VARIABLES
  572.  
  573. 3.3 Variables- Single and Multi-field
  574. Wildcard symbols replace portions of a fact pattern and accept any value. The
  575. value of the field being replaced may be captured in a variable for
  576. comparison, display, or other manipulations. This is done by directly
  577. following the wildcard symbol with a variable name.
  578.  
  579. Syntax:
  580.  
  581.    ?<name>               ; a single value variable
  582.    $?<name>              ; a multi-value variable
  583.  
  584. where <name> is a word, i.e. it must start with an alphabetic character, and
  585. cannot include any spaces. Double quotes are not allowed as part of a
  586. variable name, i.e. a string cannot be used for a variable name. The rules
  587. for pattern matching are exactly the same as those for wildcard symbols. A
  588. variable will bind the field's value(s) to that name from its first binding
  589. until the end of all actions for that rule. The binding will only be true
  590. within the scope of the rule in which it occurs. Each rule has its own
  591. private list of variable names with their associated values: thus, variables
  592. are local to a rule. The variables can be passed to external functions.
  593.  
  594. Examples:
  595.    Pattern on LHS        Fact in the fact-list    ?x bound to:
  596.    (data red ?x)         (data red green)         green
  597.    (data red ?x)         (data red "green")       "green"
  598.  
  599.    Pattern on LHS        Fact in the fact-list   $?x bound to:      
  600.    (data red $?x)        (data red)              -- nothing --
  601.    (data red $?x)        (data red green)        (green)
  602.    (data red $?x)        (data red "green")      ("green")
  603.    (data red $?x)        (data red blue blue)    (blue blue)
  604.  
  605.    Pattern on LHS         Fact in the fact-list   ?x bound to:  ?y bound to: 
  606.    (data ?x ?y)           (data red green)        red           green
  607.    (data ?x ?y)           (data red "green")      red           "green"
  608.    (data ?x ?y)           (data red green green)      --No match!--
  609.    (data ?x ?y)           (data green red)        green         red
  610.  
  611.  
  612.    Pattern on LHS         Fact in the fact-list   ?x bound to:  ?y bound to:
  613.    (data ?x $?y)          (data red)              red           -nothing-
  614.    (data ?x $?y)          (data red green)        red           green
  615.    (data ?x $?y)          (data red "green")      red           "green"
  616.    (data ?x $?y)          (data red blue blue)    red           blue, blue
  617.    (data ?x $?y)          (data green red)        green         red
  618.  
  619.    Pattern on LHS         Fact in the fact-list    $?x bound to: ?y bound to:
  620.    (data $?x ?y)          (data red)               nothing!      red
  621.    (data $?x ?y)          (data red green)         red           green
  622.    (data $?x ?y)          (data red "green")       red           "green"
  623.    (data $?x ?y)          (data red blue blue)     red, blue     blue
  624.    (data $?x ?y)          (data green red)         green         red
  625.  
  626. Once the initial binding of a variable occurs, all references to that same
  627. variable have to match the same value that the first binding matched. This
  628. applies to both single and multi-field variables. It also applies across
  629. patterns.
  630.  
  631.  Single pattern examples:
  632.  
  633.    Pattern on LHS of rule Fact in the fact-list       Matches?
  634.    (data ?x red ?x)       (data blue red blue)           Y
  635.    (data ?x red ?x)       (data blue red get)            N
  636.    (data ?x red ?x)       (data blue blue blue)          N
  637.    (data ?x red ?x)       (data blue red "blue")         N
  638.  
  639. Multiple pattern examples:
  640.  
  641.    Patterns on LHS of rule Facts in the fact-list   Fires? 
  642.    (defrule ..........
  643.      (data red ?x)         (data red green)           Y
  644.      (data purple ?x)      (data purple green)   
  645.      => ......
  646.  
  647.    (defrule ..........
  648.      (data red ?x)         (data red green)           N
  649.      (data purple ?x)      (data purple blue)
  650.      => ......
  651.  
  652.    (defrule ..........
  653.      (data red $?x)        (data red blue green)      Y
  654.      (data purple $?x)     (data purple blue green)   
  655.       => ......
  656.  
  657.    (defrule ..........
  658.      (data red $?x)        (data red blue green)      N
  659.      (data purple $?x)     (data purple blue brown)
  660.      => ......
  661.  
  662. END-ENTRY
  663.  
  664. 2MBEGIN-ENTRY-CONSTRAINING_FIELDS
  665.  
  666. LHS_SYNTAX
  667.   CONSTRAINING FIELDS
  668.  
  669. 3.4 Constraining Fields
  670. ib.Field constraints; are functions which constrain the range of values a
  671. particular field within a pattern may have. There are two types of field
  672. constraints: logical operators and predicate functions.
  673.  
  674. Subtopics :
  675.  
  676.     LOGICAL_OPERATORS     CONSTRAINING_FIELDS_THROUGH_PATTERN_EXPANSION
  677.     PREDICATE_FUNCTIONS
  678.     
  679. END-ENTRY
  680.  
  681. 3IBEGIN-ENTRY-LOGICAL_OPERATORS
  682.  
  683. LHS_SYNTAX
  684.   CONSTRAINING FIELDS
  685.     LOGICAL_OPERATORS
  686.  
  687. 3.4.1 Logical Operators
  688. There are three logical operators available for constraining values inside a
  689. pattern. These are the logical operators:& (AND), logical operators:| (OR),
  690. and logical operators:~ (NOT) operators. The logical operators can be
  691. combined in almost any manner or number to constrain the value of specific
  692. fields while pattern matching. Evaluation of multiple constraints can be
  693. considered to occur from left to right.
  694.  
  695. Syntax:
  696.  
  697.    <value1>&<value2>   ; the AND operator
  698.    <value1>|<value2>   ; the OR operator
  699.    ~<value>            ; the NOT operator
  700.  
  701. The AND operator is typically used only in conjunction with the other logical
  702. operators or variable bindings. Logical operators may be used along with
  703. variable bindings.
  704.  
  705. More Syntax:
  706.  
  707.    ?x&<value1>|<value2>   ; the OR operator with variable
  708.    ?x&~<value>            ; the NOT operator with variable
  709.  
  710. If this is the first occurrence of the variable name, then the field will be
  711. constrained according to the logical operators only. The resulting value
  712. will be stored in the variable. If the variable has been previously bound,
  713. then it is considered an additional constraint along with the logical
  714. operators, i.e. the field must have the same value already bound to the
  715. variable and it must additionally match the constraints defined by the
  716. logical operators.
  717.  
  718. Examples:
  719.  
  720.    Pattern on LHS of rule     Fact in the fact-list      Matches?    
  721.    (data ~red)                (data red)                    N
  722.    (data ~red)                (data green)                  Y
  723.  
  724.    (data red|blue)            (data red)                    Y
  725.    (data red|blue)            (data blue)                   Y
  726.    (data red|blue)            (data green)                  N
  727.  
  728.    (data ~red&~blue)          (data red)                    N
  729.    (data ~red&~blue)          (data blue)                   N
  730.    (data ~red&~blue)          (data green)                  Y
  731.  
  732.    (data ~red&blue|get)       (data red)                    N
  733.    (data ~red&blue|get)       (data blue)                   Y
  734.    (data ~red&blue|get)       (data get)                    Y
  735.    (data ~red&blue|get)       (data green)                  N
  736.  
  737. Examples with variables/single patterns:
  738.  
  739.    Pattern on LHS     Fact in the fact-list   ?x bound to:    Matches?
  740.    (data ?x&~red)     (data red)              ---                N
  741.    (data ?x&~red)     (data green)            green              Y
  742.  
  743.    (data ?x&red|blue) (data red)              red                Y
  744.    (data ?x&red|blue) (data blue)             blue               Y
  745.    (data ?x&red|blue) (data green)            ---                N
  746.  
  747. Examples with variables/multiple patterns:
  748.  
  749.    Pattern on LHS     Fact in the fact-list   ?x bound to     Fires?
  750.    (defrule .......   
  751.      (data A ?x)      (data A red)            red                N
  752.      (data B ?x&~red) (data B red)
  753.      => ......
  754.  
  755.    (defrule .......   
  756.      (data A ?x)      (data A red)            red                N
  757.      (data B ?x&~red) (data B green) 
  758.      => ......
  759.  
  760.    (defrule .......   
  761.      (data A ?x)      (data A blue)           blue               Y
  762.      (data B ?x&~red) (data B blue)
  763.    => ......
  764.  
  765.    (defrule .......   
  766.      (data A ?x)          (data A red)        red                Y
  767.      (data B ?x&red|blue) (data B red)   
  768.      => ......
  769.  
  770.    (defrule .......   
  771.      (data A ?x)          (data A red)        red                N
  772.      (data B ?x&red|blue) (data B blue)
  773.      => ......
  774.  
  775.    (defrule .......   
  776.      (data A ?x)          (data A green)      green              N
  777.      (data B ?x&red|blue) (data B green)
  778.      => ......
  779.  
  780. END-ENTRY
  781.  
  782. 3IBEGIN-ENTRY-PREDICATE_FUNCTIONS
  783.  
  784. LHS_SYNTAX
  785.   CONSTRAINING_FIELDS
  786.     PREDICATE_FUNCTIONS
  787.  
  788. 3.4.2 Predicate Functions
  789. Sometimes it becomes necessary to constrain a field to more complex values
  790. than can be defined by logic operators. CLIPS allows the use of predicate
  791. functions to accomplish this. Predicate functions check to see if the value
  792. of the field meets the constraints defined in the function. If it does, the
  793. function returns true (non-zero) and pattern matching continues. Otherwise,
  794. it returns false (0) and the pattern fails to match. Predicate functions are
  795. called by combining the AND operator  with a colon (predicate functions:&:).
  796. The value of the field must be bound to a variable and passed to the
  797. function.
  798.  
  799. Syntax:
  800.  
  801.    ?x&:(<function> <<arguments>>)
  802.  
  803. Multiple predicate functions may be used to constrain a single field. They
  804. are evaluated from left to right, each separated by an &: operator. Several
  805. predicate functions are provided by CLIPS and users may also develop their
  806. own predicate functions. Predicate functions operate on the value attempting
  807. to be matched or may have arguments passed to them. The predicate functions
  808. provided by CLIPS are:
  809.  
  810.    Function          Purpose
  811.    (numberp <arg>)   Is the value a number?
  812.    (evenp<arg>)      Is the value an even number?
  813.    (oddp <arg>)      Is the value an odd number?
  814.    (stringp <arg>)   Is the value a string?
  815.    (wordp <arg>)     Is the value a word?
  816.  
  817. Examples:
  818.  
  819.    Pattern on LHS of rule               Fact in the fact-list   Matches?    
  820.    (data ?x&:(numberp ?x))              (data 2)                   Y
  821.    (data ?x&:(numberp ?x))              (data red)                 N
  822.  
  823.    (data ?x&:(numberp ?x)&:(oddp ?x))   (data 2)                   N
  824.  
  825.    (data ?x&:(stringp ?x))              (data 2)                   N
  826.    (data ?x&:(stringp ?x))              (data red)                 Y
  827.  
  828. END-ENTRY
  829.  
  830. 3IBEGIN-ENTRY-CONSTRAINING_FIELDS_THROUGH_PATTERN_EXPANSION
  831.  
  832. LHS_SYNTAX
  833.   CONSTRAINING_FIELDS
  834.     CONSTRAINING_FIELDS_THROUGH_PATTERN_EXPANSION
  835.  
  836. 3.4.3 Constraining Fields Through Pattern Expansion
  837. It is possible to use the return value of an external function to constrain
  838. the value of a field. The equals (=) operator allows you to call external
  839. functions from inside a pattern. The return value must be either a string, a
  840. word, or a number. It is incorporated directly into the pattern at the
  841. position the function was called, and any matching patterns must match this
  842. value as though the rule were typed with that value.
  843.  
  844. Syntax:
  845.  
  846.    =(<function> <<args...>>
  847.  
  848. Example:
  849.  
  850.    Pattern on LHS     Function returns:   fact-list   Matches? 
  851.    (data =(my_fun))   2                   (data 2)      Y
  852.    (data =(my_fun))   2                   (data red)    N
  853.    (data =(my_fun))   red                 (data 2)      N
  854.    (data =(my_fun))   red                 (data red)    Y
  855.  
  856. Pattern expansion can also be used within variable bindings and combined with
  857. other logical operators:
  858.  
  859. Pattern on LHS of rule            Facts in the fact-list      Matches? 
  860. (defrule .....   
  861.    (data ?y)                      (data 4)                      Y
  862.    (data ?x&=(+ 5 ?y)|=(- 12 ?y)) (data 9)
  863.    =>
  864.  
  865. END-ENTRY
  866.  
  867. 2IBEGIN-ENTRY-USING_TEST_TO_CONSTRAIN_VARIABLES
  868.  
  869. LHS_SYNTAX
  870.   USING_TEST_TO_CONSTRAIN_VARIABLES
  871.  
  872. 3.5 Using test to Constrain Variables
  873. The field constraint functions allow very descriptive constraints to be
  874. applied to pattern matching. An additional constraint capability is provided
  875. with the test function. As with predicate functions, you can compare the
  876. variable bindings that have already occurred in any manner. You can do
  877. mathematical comparisons on variables (e.g. is the difference between ?x and
  878. ?y greater than some value?), you can do complex logical or equality
  879. comparisons, or you can call external functions which compare variables in
  880. any way the user desires.
  881.  
  882. Any kind of external function may be embedded within a test operation (or
  883. within field constraints). User defined predicate functions must take
  884. arguments as defined in the Advanced Programming Guide and should return zero
  885. (0) for false and a non-zero number for true. All defined functions use the
  886. prefix notation, so the operands to a function always appear after the
  887. function name. Several logical, comparison, and arithmetic functions are
  888. provided by CLIPS. A complete list of CLIPS defined functions can be found in
  889. Appendix A. 
  890.  
  891. Syntax:
  892.  
  893.    (test (<defined-function> [<<arguments>>]))
  894.  
  895. Functions within a test can be nested and are evaluated from the inside out.
  896. The functions inherit their syntax and terminology from both LISP and C. The
  897. predefined ones are:
  898.  
  899. Symbol    Function                       Use                Means
  900.                             Logical
  901.   !       not (inverse)                  logical            -
  902.   &&      and                            logical            -
  903.   ||      or                             logical            -
  904.  
  905.                            Comparison
  906.   =       equal (numeric)                (test (= ?x ?y))   ?x = ?y
  907.   eq      equal (any)                    (test (eq ?x ?y))  ?x eq ?y
  908.   !=      not equal (numeric)            (test (!= ?x ?y))  ?x  ?y
  909.   neq     not equal (any)                (test (neq ?x ?y)) ?x neq ?y
  910.   >=      greater than or equal          (test (>= ?x ?y))  ?x >= ?y
  911.   >       greater than                   (test (> ?x ?y))   ?x > ?y
  912.   <=      less than or equal             (test (<= ?x ?y))  ?x <= ?y
  913.   <       less than                      (test (< ?x ?y))   ?x < ?y
  914.  
  915.                            Arithmetic
  916.   /       division                       (test (/ ?x ?y))   ?x / ?y
  917.   *       multiplication                 (test (* ?x ?y))   ?x * ?y
  918.   +       addition                       (test (+ ?x ?y))   ?x + ?y
  919.   -       subtraction                    (test (- ?x ?y))   ?x - ?y
  920.  
  921. The comparison functions (=, !=, >=, etc) are only valid for comparing
  922. numeric fields. When checking equality of strings, the eq and neq comparison
  923. function should be used. eq and neq can compare strings or numbers and will
  924. not produce an error when comparing a string to a number.
  925.  
  926. Examples:
  927.  
  928. The following example checks to see if the difference between ?y and ?x is
  929. greater than three.
  930.  
  931.  
  932. Patterns on LHS of rule    Fact in the fact-list    Fires? 
  933. (defrule .....
  934.    (data ?x)               (data 6)                  Y
  935.    (value ?y)              (value 9)
  936.    (test (>= (- ?y ?x) 3))
  937.    =>  .....
  938.  
  939. The next example checks to see if there is a positive slope between two
  940. points on a line.
  941.  
  942. Patterns on LHS of rule      Fact in the fact-list   Fires? 
  943. (defrule .....
  944.    (point ?a ?x1 ?y1)        (point 1 4.00 7.00)       Y
  945.    (point ?b&~?a ?x2 ?y2)    (point 2 5.00 9.00)   
  946.    (test (< 0 (/ (- ?y2 ?y1)
  947.               (- ?x2 ?x1))))
  948.    =>  .....
  949.  
  950. All defined functions may be used as predicates, although it is usually 
  951. meaningful only for the comparison functions.
  952.  
  953. Examples/multiple patterns:
  954.  
  955. Patterns on LHS of rule       Fact in the fact-list     Fires? 
  956. (defrule .....
  957.    (data1 ?y)                (data1 3)                    Y
  958.    (data2 ?x&:(> ?x ?y))     (data2 5)
  959.    =>  .....
  960.  
  961. (defrule .....
  962.    (data1 ?y)                (data1 9)                    N
  963.    (data2 ?x&:(> ?x ?y))     (data2 5)
  964.    =>  .....
  965.  
  966. (defrule .....
  967.    (data1 ?y)                (data1 4)                    Y
  968.    (data2 ?x&:(= ?y ?x))     (data2 4)   
  969.    =>  .....
  970.  
  971. (defrule .....
  972.    (data1 ?y)               (data1 red)                   N
  973.    (data2 ?x&:(= ?x ?y))    (data2 5)             (this is an error!)  
  974.    =>  .....
  975.  
  976.  
  977. (defrule .....
  978.    (data1 ?y)               (data1 "4")                   N
  979.    (data2 ?x&:(= ?y ?x))    (data2 4)              (also an error!)
  980.    =>  .....
  981.  
  982. These last two errors could be handled better as follows:
  983.  
  984. Patterns on LHS of rule      Fact in the fact-list      Fires? 
  985. (defrule .....
  986.    (data1 ?y&:(numberp ?y))  (data1 red)                  N
  987.    (data2 ?x&:(= ?x ?y))     (data2 5)             (not an error)
  988.    =>  .....
  989.  
  990. or, better still
  991.  
  992. (defrule .....
  993.    (data1 ?y)                (data1 red)                  N
  994.    (data2 ?x&:(eq ?x ?y))    (data2 5)             (not an error)
  995.    =>  .....
  996.  
  997. END-ENTRY
  998.  
  999. 2MBEGIN-ENTRY-CONSTRAINING_PATTERNS
  1000.  
  1001. LHS_SYNTAX
  1002.   CONSTRAINING_PATTERNS
  1003.  
  1004. 3.6 Constraining Patterns
  1005. The LHS of CLIPS rules are made up of a series of patterns that represent the
  1006. conditions that must be satisfied in order for the rule to be placed on the
  1007. agenda. Unless otherwise noted, CLIPS assumes that all rules have an implicit
  1008. and surrounding the patterns on the LHS. This means that all conditions on
  1009. the LHS must be met before the rule can be activated. There is no need to
  1010. explicitly define an implicit and condition. However, it is possible to
  1011. change this default and define other logical combinations of conditions which
  1012. would cause a rule to fire. 
  1013.  
  1014. Logical pattern blocks allow patterns to be combined using inclusive or, and 
  1015. explicit and logic. The entire block is treated as a single condition on the
  1016. LHS and must be satisfied along with all other conditions before the rule can
  1017. fire. Logical blocks may be mixed with other logical blocks in any order and
  1018. patterns within the logical block may use field constraints. As with all
  1019. CLIPS features, the blocks are marked by opening and closing parentheses. 
  1020.  
  1021. Subtopics :
  1022.  
  1023.     INCLUSIVE_OR   PATTERN_NEGATION
  1024.     EXPLICIT_AND
  1025.  
  1026. END-ENTRY
  1027.  
  1028. 3IBEGIN-ENTRY-INCLUSIVE_OR
  1029.  
  1030. LHS_SYNTAX
  1031.   CONSTRAINING_PATTERNS
  1032.     INCLUSIVE_OR
  1033.  
  1034. 3.6.1 Inclusive or
  1035. The or logical block allows any one of several patterns to trigger a rule
  1036. firing. If any of the patterns inside the or block exist, the constraint is
  1037. satisfied. If all other LHS conditions are true, the rule will be activated.
  1038. Any number of patterns may be within an or block. The exact same effect could
  1039. be accomplished by writing multiple rules with similar left and right hand
  1040. sides.
  1041.  
  1042. Syntax:
  1043.  
  1044.    (defrule <name>
  1045.        [(<<additional patterns>>)]          
  1046.       (or (<<pattern 1>>) 
  1047.                 .               
  1048.                 .
  1049.          (<<pattern n>>))    
  1050.        [(<<additional patterns>>)]          
  1051.       =>             
  1052.       (<<actions>>))                
  1053.  
  1054. If more than one of the patterns in the or block can be met, the rule will
  1055. fire multiple times, once for each satisfied combination of conditions.
  1056.  
  1057. Example:
  1058.  
  1059.    (defrule system-fault
  1060.       (error-status unknown)
  1061.       (or (temp high)
  1062.          (valve broken)
  1063.          (pump off))
  1064.       =>         
  1065.       (printout "The system has a fault." crlf))
  1066.  
  1067. Note, the above example is exactly equivalent to the following three
  1068. (separate) rules:
  1069.  
  1070.    (defrule system-fault
  1071.       (error-status unknown)
  1072.       (pump off)
  1073.       =>         
  1074.       (printout "The system has a fault." crlf))
  1075.  
  1076.     (defrule system-fault
  1077.       (error-status unknown)
  1078.       (valve broken)
  1079.       =>         
  1080.       (printout "The system has a fault." crlf))
  1081.  
  1082.    (defrule system-fault
  1083.       (error-status unknown)
  1084.       (temp high)
  1085.       =>         
  1086.       (printout "The system has a fault." crlf))
  1087.  
  1088. END-ENTRY
  1089.  
  1090. 3IBEGIN-ENTRY-EXPLICIT_AND
  1091.  
  1092. LHS_SYNTAX
  1093.   CONSTRAINING_PATTERNS
  1094.     EXPLICIT_AND
  1095.  
  1096. 3.6.2 Explicit and
  1097. An explicit and is provided to allow the mixing of and and or conditions.
  1098. This allows logical combinations of patterns within an or block. The
  1099. constraint will be satisfied when all the patterns inside the explicit and
  1100. block are satisfied. If all other LHS conditions are true, the rule will be
  1101. activated. Any number of patterns may be placed in an and block. Any number
  1102. of ands may be within an or block.
  1103.  
  1104. Syntax:
  1105.  
  1106.    (defrule <name>
  1107.        [(<<additional patterns>>)]          
  1108.       (or   (and   (<<pattern 1>>) 
  1109.                    .
  1110.                    .
  1111.               (<<pattern n>>))
  1112.          (<<other patterns>>))   
  1113.        [(<<additional patterns>>)]          
  1114.       =>             
  1115.       (<<actions>>))                
  1116.  
  1117. Example:
  1118.  
  1119.    (defrule system-flow
  1120.       (error-status confirmed)
  1121.       (or   (and   (temp high)
  1122.             (valve closed))
  1123.          (and   (temp low)
  1124.             (valve open)))
  1125.       =>         
  1126.       (printout "The system is having a flow problem." crlf))
  1127.  
  1128. END-ENTRY
  1129.  
  1130. 3IBEGIN-ENTRY-PATTERN_NEGATION
  1131.  
  1132. LHS_SYNTAX
  1133.   CONSTRAINING_PATTERNS
  1134.     PATTERN_NEGATION
  1135.  
  1136. 3.6.3 Pattern Negation
  1137. Sometimes, the lack of information is meaningful, i.e. you wish to fire a
  1138. rule if a fact does not exist in the fact-list. The not function provides
  1139. this capability. As with logic blocks, any number of additional patterns may
  1140. also be on the LHS of the rule, and field constraints may be used within the
  1141. negated pattern.
  1142.  
  1143. Syntax:
  1144.  
  1145.    (defrule <name>
  1146.       (<<pattern 1>>)
  1147.       (not (<<pattern 2>>))
  1148.        [(<<additional patterns>>)]          
  1149.       =>             
  1150.       (<<actions>>)) 
  1151.       
  1152. Only one pattern may be negated at a time. Multiple patterns may be negated
  1153. by using multiple not statements. And and or logic blocks may not be placed
  1154. inside a not pattern, although a not may be placed inside an and or or. Care
  1155. must be taken when combining not with or and and blocks; the results aren't
  1156. always obvious! The same is true for variable bindings within a negated
  1157. pattern. Variables that are previously bound may be used freely inside a
  1158. negated pattern. However, variables bound for the first time within a negated
  1159. pattern can only be used in that pattern. Since negated patterns are treated
  1160. differently by CLIPS, users should always perform a reset after creating or
  1161. loading rules which include negated patterns.
  1162.  
  1163. Examples:
  1164.  
  1165.    (defrule high-flow-rate
  1166.       (temp high)
  1167.       (valve open)
  1168.       (not (error-status confirmed))
  1169.       =>
  1170.       (printout "Recommend closing of valve due to high temp" crlf))
  1171.  
  1172.    (defrule check-valve
  1173.       (check-status ?valve)
  1174.       (not (valve-broken ?valve))
  1175.       =>
  1176.       (printout "Device " ?valve " is OK" crlf))
  1177.  
  1178.    (defrule double-pattern
  1179.       (data red)
  1180.       (not (data red ?x ?x))
  1181.       =>
  1182.       (printout "No patterns with red green green!" crlf ))
  1183.  
  1184. Negating a not is illegal, i.e.  (not (not (<<pattern>>))) is not allowed.
  1185.  
  1186. END-ENTRY
  1187.  
  1188. 2IBEGIN-ENTRY-PATTERN_BINDINGS
  1189.  
  1190. LHS_SYNTAX
  1191.   PATTERN_BINDINGS
  1192.  
  1193. 3.7 Pattern Bindings
  1194. Certain RHS actions, such as retract, operate on an entire fact. To signify
  1195. which fact they are to act upon, a variable can be bound to an entire fact.
  1196.  
  1197. Syntax:
  1198.  
  1199.    ?<var-name><-(<<fields>>)
  1200.  
  1201. The left arrow, "<-", is a required part of the syntax.
  1202.  
  1203. Example:
  1204.  
  1205.    (defrule dummy
  1206.       (data 1)
  1207.       ?fact<-(dummy pattern)
  1208.       =>
  1209.       (retract ?fact))
  1210.  
  1211. END-ENTRY
  1212.  
  1213. 2MBEGIN-ENTRY-DECLARING_RULE_PROPERTIES
  1214.  
  1215. LHS_SYNTAX
  1216.   DECLARING_RULE_PROPERTIES
  1217.  
  1218. 3.8 Declaring Rule Properties
  1219. This feature allows properties or characteristics of a rule to be defined.
  1220. The characteristics are declared on the LHS of a rule using the declare
  1221. construct. A rule may have multiple declare constructs, but all declare
  1222. statements must appear before the first pattern on the LHS. The general
  1223. syntax is:
  1224.  
  1225. Syntax:
  1226.  
  1227.    (declare (<something> [<<args>>]))
  1228.  
  1229. Currently, there is only one declarative feature allowed; salience. Future
  1230. versions of CLIPS may provide more declarative capabilities and functions to
  1231. allow users to define their own declarative properties.
  1232.  
  1233. Subtopics :
  1234.  
  1235.     ASSIGNING_RULE_PRIORITY
  1236.  
  1237. END-ENTRY
  1238.  
  1239. 3IBEGIN-ENTRY-ASSIGNING_RULE_PRIORITY
  1240.  
  1241. LHS_SYNTAX
  1242.   DECLARING_RULE_PROPERTIES
  1243.     ASSIGNING_RULE_PRIORITY
  1244.  
  1245. 3.8.1 Assigning Rule Priority
  1246. A salience statement allows the user to assign a priority to a rule. When
  1247. multiple rules are in the agenda, the rule with the highest priority will
  1248. fire first.
  1249.  
  1250. Syntax:
  1251.  
  1252.    (declare (salience <num>))
  1253.  
  1254. where <num> must be an integer. If not specified, the salience value for a
  1255. rule defaults to zero. Salience values may be either positive or negative.
  1256. The largest allowed value is 10000. The smallest allowed value is -10000.
  1257.  
  1258. Example:
  1259.  
  1260.    (defrule test
  1261.       (declare (salience 99))    ; salience declaration
  1262.       (initial-fact)   ; matches the initial fact
  1263.       =>
  1264.       (printout "I Have a salience value of 99." crlf))
  1265.  
  1266. END-ENTRY
  1267.  
  1268. 1MBEGIN-ENTRY-RHS_SYNTAX
  1269.  
  1270. RHS_SYNTAX
  1271.  
  1272. 4.0 RHS Syntax - Actions
  1273. This section describes the various actions available on the RHS of rules. 
  1274.  
  1275. Subtopics :
  1276.  
  1277.   BASIC_ACTIONS          MATH_FUNCTIONS
  1278.   MULTI-FIELD_FUNCTIONS  ADDITIONAL_FUNCTIONS
  1279.   CLIPS_I/O_SYSTEM
  1280.  
  1281. END-ENTRY
  1282.  
  1283. 2MBEGIN-ENTRY-BASIC_ACTIONS
  1284.  
  1285. RHS_SYNTAX
  1286.   BASIC_ACTIONS
  1287.  
  1288. 4.1 Basic Actions
  1289. The following actions are the most commonly used RHS actions. They deal with
  1290. basic functions like asserting and retracting facts.
  1291.  
  1292. Subtopics :
  1293.  
  1294.     CREATING_NEW_FACTS                 BINDING_VARIABLES
  1295.     REMOVING_FACTS_FROM_THE_FACT-LIST  STOPPING_CLIPS
  1296.     ASSERTING_A_STRING
  1297.  
  1298. END-ENTRY
  1299.  
  1300. 3MBEGIN-ENTRY-CREATING_NEW_FACTS
  1301.  
  1302. RHS_SYNTAX
  1303.   BASIC_FACTS
  1304.     CREATING_NEW_FACTS
  1305.  
  1306. 4.1.1 Creating New Facts
  1307. The assert action allows you to add a fact to the fact-list. Only one fact
  1308. may be asserted in each assert statement. However, multiple asserts may be
  1309. placed on the RHS of a rule.
  1310.  
  1311. Syntax:
  1312.  
  1313.    (assert (<<pattern>>))
  1314.  
  1315. The fact asserted may contain bound variables, function calls, and literal
  1316. values. If an identical copy of the fact already exists in the fact-list, the
  1317. fact will not be added.
  1318.  
  1319. Examples:
  1320.  
  1321.    (assert (data red))   ; assert a simple fact
  1322.  
  1323.    (defrule close-valve
  1324.       (temp ?sensor high)
  1325.       (valve ?v open)
  1326.       (not (error-status confirmed))
  1327.       =>
  1328.       (assert  (Set ?v close))   ;assert a fact with variables
  1329.       (printout "Close valve due to high temp" crlf))
  1330.  
  1331. Subtopics :
  1332.  
  1333.       CALLING_EXTERNAL_FUNCTIONS
  1334.  
  1335. END-ENTRY
  1336.  
  1337. 4IBEGIN-ENTRY-CALLING_EXTERNAL_FUNCTIONS
  1338.  
  1339. RHS_SYNTAX
  1340.   BASIC_ACTIONS
  1341.     CREATING_NEW_FACTS
  1342.       CALLING_EXTERNAL_FUNCTIONS
  1343.  
  1344. 4.1.1.1 Calling External Functions
  1345. Sometimes it is preferable to call an external function from inside an
  1346. assert. The return value from the function is incorporated directly into the
  1347. pattern at the position the function was called. As with pattern expansion
  1348. on the LHS side of a rule, the equal operator (=) is used.
  1349.  
  1350. Syntax:
  1351.  
  1352.    (assert ([<<fields>>] =(<function> <<args...>>) [<<fields>>])
  1353.  
  1354. This is exactly the same as binding a variable to the return from a function
  1355. using the bind function and then placing the variable inside the assert.
  1356.  
  1357. Examples:
  1358.  
  1359.    (assert (data red =(+ ?x ?y)))
  1360.  
  1361.    (defrule user-close-valve
  1362.       (goal close valve)
  1363.       (input-from user)
  1364.       =>
  1365.       (printout "Which valve should be closed? ")
  1366.       (assert (close-valve =(read))))
  1367.  
  1368. END-ENTRY
  1369.  
  1370. 3IBEGIN-ENTRY-REMOVING_FACTS_FROM_THE_FACT-LIST
  1371.  
  1372. RHS_SYNTAX
  1373.   BASIC_ACTIONS
  1374.     REMOVING_FACTS_FROM_THE_FACT-LIST
  1375.  
  1376. 4.1.2 Removing Facts from the Fact-list
  1377. The retract action allows you to remove facts from the fact-list. Multiple
  1378. facts may be retracted with a single retract statement. The retraction of a
  1379. fact also removes all rules from the agenda that depended upon that fact for
  1380. activation.
  1381.  
  1382. Syntax:
  1383.  
  1384.    (retract ?<fact-var> [?<<fact-vars>>] | <fact-num> [<<fact-nums>>])
  1385.  
  1386. Facts may be identified either as fact variables (?<fact-var>) bound on the
  1387. LHS as described in LHS_SYNTAX PATTERN_BINDINGS, or by number (<fact-num>). 
  1388. Note that the number is generally not known during the execution of a program,
  1389. so facts are usually retracted by binding them on the LHS of a rule. External 
  1390. functions may not be called from retract.
  1391.  
  1392. Example:
  1393.  
  1394.    (defrule change-valve-status
  1395.       ?f1<-(valve ?v open)
  1396.       ?f2<-(Set ?v close)
  1397.       =>
  1398.       (retract ?f1 ?f2)
  1399.       (assert  (valve ?v close)))
  1400.  
  1401. END-ENTRY
  1402.  
  1403. 3IBEGIN-ENTRY-ASSERTING_A_STRING
  1404.  
  1405. RHS_SYNTAX
  1406.   BASIC_ACTIONS
  1407.     ASSERTING_A_STRING
  1408.  
  1409. 4.1.3 Asserting a String
  1410. The string_assert function is similar to assert in that it will add a fact to
  1411. the fact-list. However, string_assert takes a single string and breaks it
  1412. into separate fields prior to asserting the fact. Spaces, newlines, carriage
  1413. returns, or tabs within the string will be used as the delimiter between
  1414. fields. Like assert, only one fact may be asserted with each string_assert
  1415. statement.
  1416.  
  1417. Syntax:
  1418.  
  1419.    (string_assert <quoted-string>)
  1420.  
  1421. If an identical copy of the fact already exists in the fact-list, the fact
  1422. will not be added. Fields may contain a quoted string by escaping the quote
  1423. with a backslash. This functions is particularly effective when used with the
  1424. readline function (see RHS_SYNTAX CLIPS_I/O_SYSTEM COMMON_I/O_FUNCTIONS
  1425. READLINE). 
  1426.  
  1427. Examples:
  1428.  
  1429.    statement:                               asserted fact:
  1430.    (string_assert "status valve open")      (status valve open)
  1431.    (string_assert "light \"red\"")          (light "red")
  1432.  
  1433. END-ENTRY
  1434.  
  1435. 3IBEGIN-ENTRY-BINDING_VARIABLES
  1436.  
  1437. RHS_SYNTAX
  1438.   BASIC_ACTIONS
  1439.     BINDING_VARIABLES
  1440.  
  1441. 4.1.4 Binding Variables
  1442. Occasionally it is important to create new variables or modify the value of
  1443. previously bound variables on the RHS of a rule. The bind function provides
  1444. this capability.
  1445.  
  1446. Syntax:
  1447.  
  1448.    (bind ?<var-name>  <value> or <variable> or (<defined-function>))
  1449.  
  1450. Where <var-name> must be a variable name (it may have been previously bound).
  1451. <var-name> can be bound to literal values, other bound variables, or the
  1452. return from a function call.
  1453.  
  1454. Examples:
  1455.  
  1456.    (bind ?input (read))
  1457.    (bind ?value (+ ?x ?y))
  1458.    (bind ?value (+ (* ?y ?z) (* ?x ?z)))
  1459.    (bind ?new ?old)
  1460.    (bind ?number 14)
  1461.  
  1462. END-ENTRY
  1463.  
  1464. 3IBEGIN-ENTRY-STOPPING_CLIPS
  1465.  
  1466. RHS_SYNTAX
  1467.   BASIC_ACTIONS
  1468.     STOPPING_CLIPS
  1469.  
  1470. 4.1.5 Stopping CLIPS
  1471. The halt function may be used on the RHS of a rule to prevent further rule
  1472. firing. It is called without arguments. After halt is called, control is
  1473. returned to the top level program. The agenda is left intact, and execution
  1474. may be continued with a run command.
  1475.  
  1476. Syntax:
  1477.  
  1478.    (halt)
  1479.  
  1480. Example:
  1481.  
  1482.    (defrule halt-if-error
  1483.       (data ?x)
  1484.       =>
  1485.       (if (< (abs ?x) 0.00001)
  1486.       then
  1487.          (printout "Error, number to small" crlf)
  1488.          (halt)
  1489.       else
  1490.          (assert (new_data =(/ 15 ?x)))
  1491.  
  1492. END-ENTRY
  1493.  
  1494. 2MBEGIN-ENTRY-MULTI-FIELD_FUNCTIONS
  1495.  
  1496. RHS_SYNTAX
  1497.   MULTI-FIELD_FUNCTIONS
  1498.  
  1499. 4.2 Multi-field Functions
  1500. The following functions operate on multi-field variables.
  1501.  
  1502. Subtopics :
  1503.  
  1504.     NUMBER_OF_ELEMENTS     FINDING_AN_ELEMENT
  1505.     SPECIFYING_AN_ELEMENT
  1506.  
  1507. END-ENTRY
  1508.  
  1509. 3IBEGIN-ENTRY-NUMBER_OF_ELEMENTS
  1510.  
  1511. RHS_SYNTAX
  1512.   MULTI-FIELD_FUNCTIONS
  1513.     NUMBER_OF_ELEMENTS
  1514.  
  1515. 4.2.1 Number of Elements
  1516. The length function returns the number of elements bound to a multi-field
  1517. variable.
  1518.  
  1519. Syntax:
  1520.  
  1521.    (length <variable>)
  1522.  
  1523. where <variable> must be a multi-field variable ($?). If the variable is not
  1524. a multi-field variable, length returns a negative one (-1).
  1525.  
  1526. Example:
  1527.  
  1528. Given this fact in the database:   (data a b c d e f g)
  1529.  
  1530.    (defrule test-length
  1531.       (data $?a)
  1532.       =>
  1533.       (bind ?num (length $?a))
  1534.       (printout crlf "Length of data is " ?num))
  1535.  
  1536. The above rule prints:    Length of data is 7
  1537.  
  1538. END-ENTRY
  1539.  
  1540. 3IBEGIN-ENTRY-SPECIFYING_AN_ELEMENT
  1541.  
  1542. RHS_SYNTAX
  1543.   MULTI-FIELD_FUNCTIONS
  1544.     SPECIFYING_AN_ELEMENT
  1545.  
  1546. 4.2.2 Specifying an Element
  1547. The nth function will return a specified element from a multi-field variable.
  1548. It is similar in use to the LISP nth function.
  1549.  
  1550. Syntax:
  1551.  
  1552.    (nth <number> <variable>)
  1553.  
  1554. where <number> is an integer from 1 to the number of elements bound to the
  1555. variable. <variable> must be a multi-field variable ($?). The symbol nil will
  1556. be returned if <number> is greater than number of elements in the variable.
  1557.  
  1558.  
  1559. Example:
  1560.  
  1561. Given the following fact in the fact-list:  (data a b c d e f g)
  1562.  
  1563.    (defrule test-length
  1564.       (data $?a)
  1565.       =>
  1566.       (bind ?c (nth 3 $?a))
  1567.       (printout crlf "Third element in data is " ?c))
  1568.  
  1569. The above rule prints:   Third element in data is c
  1570.  
  1571. END-ENTRY
  1572.  
  1573. 3IBEGIN-ENTRY-FINDING_AN_ELEMENT
  1574.  
  1575. RHS_SYNTAX
  1576.   MULTI-FIELD_FUNCTIONS
  1577.     FINDING_AN_ELEMENT
  1578.  
  1579. 4.2.3 Finding an element
  1580. The memberfunction will tell if an atom is in a multi-value variable.
  1581.  
  1582. Syntax:
  1583.  
  1584.    (member <atom> $?<var>)
  1585.  
  1586. where <atom> can be either a literal value or a variable. <var> must be bound
  1587. to a multi-field variable. If <atom> is one of the values bound to <var>,
  1588. member will return the number of the element. otherwise it will return 0.
  1589.  
  1590. Examples:
  1591.  
  1592. Given the following fact in the fact-list: 
  1593.             (data red "green" blue brown)
  1594.  
  1595.    (defrule test-member
  1596.       (data $?a)
  1597.       =>
  1598.       (bind ?val (member blue $?a))
  1599.       (fprintout t "Blue is item " ?a " in the list" crlf))
  1600.  
  1601. The above rule prints: Blue is item 3 in the list
  1602.  
  1603. END-ENTRY
  1604.  
  1605. 2MBEGIN-ENTRY-CLIPS_I/O_SYSTEM
  1606.  
  1607. RHS_SYNTAX
  1608.   CLIPS_I/O_SYSTEM
  1609.  
  1610. 4.3 The CLIPS I/O System
  1611. CLIPS uses a system called I/O routing to provide very flexible I/O while
  1612. remaining portable. A more complete discussion of I/O routing is covered in
  1613. the Advanced Programming Guide.
  1614.  
  1615. Subtopics :
  1616.  
  1617.     LOGICAL_NAMES   COMMON_I/O_FUNCTIONS
  1618.  
  1619. END-ENTRY
  1620.  
  1621. 3IBEGIN-ENTRY-LOGICAL_NAMES
  1622.  
  1623. RHS_SYNTAX
  1624.   CLIPS_I/O_SYSTEM
  1625.     LOGICAL_NAMES
  1626.  
  1627. 4.3.1 Logical Names
  1628. One of the key concepts of I/O routing is the use of logical names. Logical
  1629. names allow reference to an I/O device without having to understand the
  1630. details of the implementation of the reference. Many functions in CLIPS make
  1631. use of logical names. A logical name can be either a word, a number, or a
  1632. string. Several logical names are predefined by CLIPS and used extensively
  1633. throughout the CLIPS code. These are:
  1634.  
  1635. Name        Description
  1636.  
  1637. wclips      The CLIPS prompt is sent to this logical name.
  1638. wdialog     All informational messages are sent to this logical name.
  1639. wdisplay    Requests to display CLIPS information, such as facts or rules are
  1640.             sent to this logical name.
  1641. werror      All error messages are sent to this logical name.
  1642. wtrace      All tracing (watch) information is sent to this logical name.
  1643. wagenda     When the agenda is displayed, it is sent to this logical name.
  1644. stdin       The default for all user inputs is this logical name.
  1645. stdout      All output from the printout function is sent to this logical name.
  1646.  
  1647. The format and fprintout functions send output to stdout if t is 
  1648. specified as the logical name.
  1649.  
  1650. Any of these logical names may be used anywhere a logical name is expected.
  1651.  
  1652. END-ENTRY
  1653.  
  1654. 3MBEGIN-ENTRY-COMMON_I/O_FUNCTIONS
  1655.  
  1656. RHS_SYNTAX
  1657.   CLIPS_I/O_SYSTEM
  1658.     COMMON_I/O_FUNCTIONS
  1659.  
  1660. 4.3.2 Common I/O Functions
  1661. CLIPS provides some of the most commonly needed I/O capabilities through
  1662. several pre-defined functions.
  1663.  
  1664. Subtopics :
  1665.  
  1666.       OPEN       PRINTOUT
  1667.       CLOSE      FPRINTOUT
  1668.       READ       FORMAT
  1669.       READLINE
  1670.  
  1671. END-ENTRY
  1672.  
  1673. 4IBEGIN-ENTRY-OPEN
  1674.  
  1675. RHS_SYNTAX
  1676.   CLIPS_I/O_SYSTEM
  1677.     COMMON_I/O_FUNCTIONS
  1678.       OPEN
  1679.  
  1680. 4.3.2.1 Open
  1681. The open function allows a user to open a file from the RHS of a rule and
  1682. attaches a logical name to it. This function takes three arguments: 1) the
  1683. name of the file to be opened, 2) the logical name which will be used by
  1684. other CLIPS I/O  functions to access the file, and 3) an optional mode
  1685. specifier. The mode specifier must be one of the following:
  1686.  
  1687.    Mode              Means
  1688.      r               read access only
  1689.      w               write access only
  1690.      r+              read and write access
  1691.      a               append access only
  1692.                                              
  1693. If the mode is not specified, a default of read access only is assumed. The
  1694. access mode may not be meaningful in some operating systems. 
  1695.  
  1696. Syntax:
  1697.  
  1698.    (open "<file-name>" <logical-name> ["<mode>"])
  1699.  
  1700. The <file-name> must be enclosed in double quotes and may include directory
  1701. specifiers. The backslash (\) and any other special characters that are part
  1702. of <file-name> must be escaped with a backslash. The logical name should not
  1703. have been previously used.
  1704.  
  1705. Examples:
  1706.  
  1707.    (defrule fileopen-test
  1708.       (initial-fact)
  1709.       =>
  1710.       (open "myfile.clp" myfiletag "r+"))
  1711.       (open "MS-DOS\\directory\\file.clp" file)
  1712.  
  1713. END-ENTRY
  1714.  
  1715. 4IBEGIN-ENTRY-CLOSE
  1716.  
  1717. RHS_SYNTAX
  1718.   CLIPS_I/O_SYSTEM
  1719.     COMMON_I/O_FUNCTIONS
  1720.       CLOSE
  1721.  
  1722. 4.3.2.2 Close
  1723. The close function closes a file stream previously opened with the open 
  1724. command. The file is specified by a logical name previously attached to the
  1725. desired stream.
  1726.  
  1727. Syntax:
  1728.  
  1729.    (close [<logical-name>])
  1730.  
  1731. If close is called without arguments, all open files will be closed.
  1732.  
  1733. Example:
  1734.  
  1735.    (defrule file-open
  1736.       (initial-fact)
  1737.       =>
  1738.       (open "test.clp" data-file))
  1739.       
  1740.                ; Other rules which use the file
  1741.       
  1742.    (defrule file-close
  1743.       (close-file data-file)
  1744.       =>
  1745.       (close data-file))
  1746.  
  1747. The user is responsible for closing all files opened during execution. If
  1748. files are not closed, the contents are not guaranteed to be correct.
  1749.  
  1750. END-ENTRY
  1751.  
  1752. 4IBEGIN-ENTRY-READ
  1753.  
  1754. RHS_SYNTAX
  1755.   CLIPS_I/O_SYSTEM
  1756.     COMMON_I/O_FUNCTIONS
  1757.       READ
  1758.  
  1759. 4.3.2.3 Read
  1760. The read function allows a user to input information for a single field.  All
  1761. the standard field rules (e.g. multiple words must be embedded within quotes)
  1762. apply. 
  1763.  
  1764. Syntax:
  1765.  
  1766.    (read [<logical-name>])
  1767.  
  1768. where <logical-name> is an optional parameter. If it is specified, read tries
  1769. to read from whatever is attached to the logical file name. If <logical-name>
  1770. is t or is not specified, the function will read from stdin.  If an end of
  1771. file is encountered while reading, read will return the word EOF. If errors
  1772. are encountered while reading, the string "*** READ ERROR ***" will be
  1773. returned.
  1774.  
  1775. Example:
  1776.  
  1777.    (defrule fileread
  1778.       (initial-fact)
  1779.       =>
  1780.       (open "data.clp" mydata)
  1781.       (bind ?input (read mydata))
  1782.       (assert (data ?input)))
  1783.  
  1784. END-ENTRY
  1785.  
  1786. 4IBEGIN-ENTRY-READLINE
  1787.  
  1788. RHS_SYNTAX
  1789.   CLIPS_I/O_SYSTEM
  1790.     COMMON_I/O_FUNCTIONS
  1791.       READLINE
  1792.  
  1793. 4.3.2.4 Readline
  1794. The readline function is similar to the read function, but it allows a whole
  1795. string to be input instead of a single field. Normally, read will stop when
  1796. it encounters a space, tab, carriage return or end of file. readline only
  1797. stops when it encounters a carriage return or end of file. Any tabs or spaces
  1798. in the input are returned by readline as a part of the string. readline
  1799. returns a quoted string.
  1800.  
  1801. Syntax:
  1802.  
  1803.    (readline [<logical-name>])
  1804.  
  1805. where <logical-name> is an optional parameter. If it is specified, readline
  1806. tries to read from whatever is attached to the logical file name. If
  1807. <logical-name> is t or is not specified, the function will read from stdin. 
  1808. As with read, if end of file is encountered, readline will return the word
  1809. EOF. If an error is encountered during input, readline  returns the quoted
  1810. string "*** READ ERROR ***".
  1811.  
  1812. Example:
  1813.  
  1814.    (defrule file-read-line
  1815.       (initial-fact)
  1816.       =>
  1817.       (open "data.txt" mydata)
  1818.       (bind ?input-string (readline mydata))
  1819.       (assert (data ?input-string)))
  1820.  
  1821. If the file "data.txt" had a first line as follows:
  1822.  
  1823.    the pretty red dog
  1824.  
  1825. the following fact will be asserted:
  1826.  
  1827.    (data "the pretty red dog")
  1828.  
  1829. END-ENTRY
  1830.  
  1831. 4IBEGIN-ENTRY-PRINTOUT
  1832.  
  1833. RHS_SYNTAX
  1834.   CLIPS_I/O_SYSTEM
  1835.     COMMON_I/O_FUNCTIONS
  1836.       PRINTOUT
  1837.  
  1838. 4.3.2.5 Printout
  1839. The printout function allows simple output to the standard output device 
  1840. (whatever is attached to stdout, usually the screen). It will evaluate
  1841. variable bindings and print the value of a variable in the output string. Any
  1842. number of items may be placed in a printout.
  1843.  
  1844. Syntax:
  1845.  
  1846.    (printout <item> ... <item> [crlf])
  1847.  
  1848. Where <item> is a bound variable, string, number, word, or function call. The
  1849. word crlf will force a carriage return/line feed and may be placed anywhere
  1850. in the list of items.
  1851.  
  1852. Example:
  1853.  
  1854.    (defrule change-valve-status
  1855.       ?f1<-(valve ?v open)
  1856.       ?f2<-(Set ?v close)
  1857.       =>
  1858.       (retract ?f1 ?f2)
  1859.       (assert  (valve ?v close))
  1860.       (printout "The valve " ?v " has been closed" crlf))
  1861.  
  1862. Note that the printout function is completely replaced by fprintout and
  1863. format. This function is still provided for compatibility with code written
  1864. in earlier releases of CLIPS.
  1865.  
  1866. END-ENTRY
  1867.  
  1868. 4IBEGIN-ENTRY-FPRINTOUT
  1869.  
  1870. RHS_SYNTAX
  1871.   CLIPS_I/O_SYSTEM
  1872.     COMMON_I/O_FUNCTIONS
  1873.       FPRINTOUT
  1874.  
  1875. 4.3.2.6 Fprintout
  1876. The fprintout function allows output to a device attached to a logical name.
  1877. The logical name MUST be specified and the device must have been previously
  1878. prepared for output (e.g. a file must be opened first). To send output to
  1879. stdout, use a t for the logical name. fprintout will evaluate variable
  1880. bindings and print the value of a variable in the output string. Any number
  1881. of items may be placed in an fprintout.
  1882.  
  1883. Syntax:
  1884.  
  1885.    (fprintout <logical-name> <item> ... <item> [crlf])
  1886.  
  1887. where <item> is a literal value, a bound variable, or a function call. As
  1888. with printout, the word crlf will force a carriage return/newline and may be
  1889. placed anywhere in the item list.
  1890.  
  1891. Example:
  1892.  
  1893.    (defrule change-valve-status
  1894.       ?f1<-(valve ?v open)
  1895.       ?f2<-(Set ?v close)
  1896.       =>      
  1897.       (open "out.clp" data "w")
  1898.       (retract ?f1 ?f2)
  1899.       (assert  (valve ?v close))
  1900.       ;; The next line sends output to the file
  1901.       (fprintout data "The valve " ?v " has been closed" crlf)
  1902.       (fprintout data "Example with \"quoted\" information" crlf)
  1903.       ;; The next line sends output to standard out
  1904.       (fprintout t "Data written." crlf))
  1905.  
  1906. END-ENTRY
  1907.  
  1908. 4IBEGIN-ENTRY-FORMAT
  1909.  
  1910. RHS_SYNTAX
  1911.   CLIPS_I/O_SYSTEM
  1912.     COMMON_I/O_FUNCTIONS
  1913.       FORMAT
  1914.  
  1915. 4.3.2.7 Format
  1916. The format function allows a user to send formatted output to a device
  1917. attached to a logical name. It can be used in place of fprintout, when
  1918. special formatting of output information is desired. The format commands are
  1919. similar to the printf statement in C.
  1920.  
  1921. Syntax:
  1922.  
  1923.    (format <logical-name> "<control-string>" <<parameter-list>>)
  1924.  
  1925. where <logical-name> is any logical name. If it is t, then output is sent to
  1926. stdout. The <control-string> is a quoted string which specifies how the
  1927. output should be formatted. The <<parameter-list>> are the bound variables or
  1928. literal values which are to be output.  Function calls may also be embedded
  1929. in the <<parameter-list>> and the return from the function will be output.
  1930. Format currently does not support multi-field variables in the
  1931. <<parameter-list>>.
  1932.  
  1933. The control string consists of text and format flags. The text is output
  1934. exactly as specified and the format flags describe how each parameter in the
  1935. <<parameter-list>> is to be formatted. The first format flag corresponds to
  1936. the first value in the parameter list, the second flag corresponds to the
  1937. second value, and so on. The format flags must be preceded by a percent sign
  1938. (%) and are of the general format:
  1939.  
  1940.    %-M.Nx
  1941.  
  1942. where x is one of the flags listed below, the minus sign is an optional
  1943. justification flag, and M and N are optional parameters which specify the
  1944. field width and number of digits following the decimal place. If M is used,
  1945. at least M characters will be output. If more than M characters are required
  1946. to display the value, then format expands the field as needed. If M starts
  1947. with a 0 (e.g. %07d) then a zero is used as the pad character, otherwise
  1948. spaces are used. If N is not specified, it defaults to six digits for
  1949. floating point numbers. If a  minus sign is included before the M, the value
  1950. will be left justified, otherwise the value is right justified. 
  1951.  
  1952. Format Flags:
  1953.    d   :   Display parameter as an integer.
  1954.           (The N specifier has no meaning)
  1955.  
  1956.    f   :   Display parameter as a floating-point number.
  1957.  
  1958.    e   :   Display parameter as a floating-point using power of ten          
  1959.            notation. 
  1960.    g   :   Display parameter in the most general format, whatever is         
  1961.            shorter. 
  1962.  
  1963.    o   :   Display parameter as an unsigned octal number.
  1964.            (The N specifier has no meaning)
  1965.  
  1966.    x   :   Display parameter as an unsigned hexidecimal number.
  1967.           (The N specifier has no meaning)
  1968.  
  1969.    s   :   Display parameter as a string. Quoted strings will have the       
  1970.            leading and trailing quotes stripped.
  1971.           (The N specifier has no meaning. Also, zero can not be used       
  1972.                 for the pad character)
  1973.  
  1974.    n   :   Put a carriage return/line feed in the output
  1975.  
  1976.    %   :   Put the percent character into the output
  1977.  
  1978. Examples:
  1979.  
  1980. Given the following variable bindings:
  1981.  
  1982.    ?num   = 12
  1983.    ?float   = 12.01
  1984.    ?str1   = valve-A1
  1985.    ?str2   = "capacity"
  1986.  
  1987.       format statement            Gives
  1988.  
  1989.    (format t "Test:%d" ?num)      Test:12
  1990.    (format t "Test:%4d" ?num)     Test:  12
  1991.    (format t "Test:%04d" ?num)    Test:0012
  1992.    (format t "Test:%-04d" ?num)   Test:1200
  1993.    (format t "Test:%d" ?float)    Test:12
  1994.  
  1995.    (format t "Test:%f" ?num)      Test:12.000000
  1996.    (format t "Test:%f" ?float)    Test:12.010000
  1997.    (format t "Test:%7f" ?num)     Test:12.000000
  1998.    (format t "Test:%7.2f" ?num)   Test:  12.00
  1999.     (format t "Test:%07.2f" ?num) Test:0012.00
  2000.  
  2001.    (format t "Test:%e" ?num)      Test:1.200000e+01
  2002.    (format t "Test:%7e" ?num)     Test:1.200000e+01
  2003.    (format t "Test:%7.2e" ?num)   Test:1.20e+01
  2004.    (format t "Test:%07.2e" ?num)  Test:1.20e+01
  2005.    (format t "Test:%011.2e" ?num) Test:0001.20e+01
  2006.  
  2007.    (format t "Test:%g" ?num)      Test:12
  2008.    (format t "Test:%g" ?float)    Test:12.01
  2009.    (format t "Test:%g" 1234567890)Test:1.234568e+09
  2010.  
  2011.    (format t "Test:%o" ?num)      Test:14
  2012.    (format t "Test:%x" ?num)      Test:c
  2013.  
  2014.    (format t "Test:%s" ?str1)     Test:valve-A1
  2015.    (format t "Test:%s" ?str2)     Test:capacity
  2016.  
  2017.    (format t "The %s is at %d%% of its \"%s\"" ?str1 ?num ?str2)
  2018.  
  2019. gives
  2020.  
  2021.    The valve-A1 is at 12% of its "capacity"
  2022.  
  2023. Portability Note
  2024.  
  2025. The format function uses the C function sprintf as a base. Some systems may
  2026. not support sprintf or may not support all these features, which may affect
  2027. how format works.
  2028.  
  2029. END-ENTRY
  2030.  
  2031. 2MBEGIN-ENTRY-MATH_FUNCTIONS
  2032.  
  2033. RHS_SYNTAX
  2034.   MATH_FUNCTIONS
  2035.  
  2036. 4.4 Math Functions
  2037. CLIPS provides several functions for mathematical computations. They are
  2038. split into two packages, a set of standard math functions and a set of
  2039. extended math functions.
  2040.  
  2041. Subtopics :
  2042.  
  2043.     STANDARD_MATH_FUNCTIONS   EXTENDED_MATH_FUNCTIONS
  2044.  
  2045. END-ENTRY
  2046.  
  2047. 3IBEGIN-ENTRY-STANDARD_MATH_FUNCTIONS
  2048.  
  2049. RHS_SYNTAX
  2050.   MATH_FUNCTIONS
  2051.     STANDARD_MATH_FUNCTIONS
  2052.  
  2053. 4.4.1 Standard Math Functions
  2054. The standard math functions include add, subtract, multiply, and divide.
  2055. These functions should only be used on numeric arguments. An error message
  2056. will be printed during execution if a string argument is passed to a math
  2057. function.
  2058.  
  2059. Examples:
  2060.  
  2061.    divide     (bind ?var (/ ?x ?y))   ; means ?var = ?x / ?y
  2062.    multiply   (bind ?var (* ?x ?y))   ; means ?var = ?x * ?y
  2063.    add        (bind ?var (+ ?x ?y))   ; means ?var = ?x + ?y
  2064.    subtract   (bind ?var (- ?x ?y))   ; means ?var = ?x - ?y
  2065.  
  2066. Arithmetic function calls can be used anywhere an external function is valid.
  2067.  
  2068. END-ENTRY
  2069.  
  2070. 3IBEGIN-ENTRY-EXTENDED_MATH_FUNCTIONS
  2071.  
  2072. RHS_SYNTAX
  2073.   MATH_FUNCTIONS
  2074.     EXTENDED_MATH_FUNCTIONS
  2075.  
  2076. 4.4.2 Extended Math Functions
  2077. In addition to the standard math functions, CLIPS also provided a large number
  2078. of scientific and trigonometric math functions for more extensive computations.
  2079. Although included in the generic version of CLIPS, if an expert system does not
  2080. need these capabilities, these functions may be excluded from the executable
  2081. element of CLIPS to provide more memory (see the Advanced Programming Guide).
  2082. The following functions all take one argument:
  2083.  
  2084. General Syntax:
  2085.  
  2086.    (<fun> <arg>)
  2087.  
  2088. Example:
  2089.  
  2090.    (defrule trigtest
  2091.       (number ?x)
  2092.       =>
  2093.       (bind ?y (cos ?x))
  2094.  
  2095. Function   Returns:
  2096.  
  2097. cos        cosine
  2098. sin        sine
  2099. tan        tangent
  2100. sec        secant
  2101. csc        cosecant
  2102. cot        cotangent
  2103. acos       arccosine
  2104. asin       arcsine
  2105. atan       arctangent
  2106. asec       arcsecant
  2107. acsc       arccosecant
  2108. acot       arccotangent
  2109. cosh       hyperbolic cosine
  2110. sinh       hyperbolic sine
  2111. tanh       hyperbolic tangent
  2112. sech       hyperbolic secant
  2113. csch       hyperbolic cosecant
  2114. coth       hyperbolic tangent
  2115. acosh      hyperbolic arccosine
  2116. asinh      hyperbolic arcsine
  2117. atanh      hyperbolic arctangent
  2118. asech      hyperbolic arcsecant
  2119. acsch      hyperbolic arccosecant
  2120. acoth      hyperbolic arccotangent
  2121.  
  2122.    (NOTE: All the trigonometric functions expect RADIAN arguments)
  2123.  
  2124. log        log base e
  2125. log10      log base 10
  2126. exp        e**<arg>
  2127. sqrt       square root
  2128. trunc      truncates argument to integer
  2129. deg-rad    convert from degrees to radians
  2130. rad-deg    convert from radians to degrees
  2131. abs        absolute value
  2132.  
  2133. The following functions take multiple arguments:
  2134.  
  2135. Function   # of arguments   Returns:
  2136.  
  2137. min        1 or more        min value of all args
  2138. max        1 or more        max value of all args
  2139. pi         none             the value of pi
  2140. mod        2                modulus of arg1 by arg2
  2141. **         2                arg1 raised to the arg2 power
  2142.  
  2143.  
  2144. Portability Note
  2145.  
  2146. These mathematical functions use the C library math.h. If your system does
  2147. not support this library, you need to make some adjustments to math.c. The
  2148. system dependent math functions are called from clcos,  clsin, and so on.
  2149. You must change each of these to call the appropriate functions from your
  2150. system. Make sure that the functions clcos, clsin, etc. always return
  2151. FLOATING point numbers. To link these functions, most compilers provide a
  2152. separate math library which must be included during linking.
  2153.  
  2154. END-ENTRY
  2155.  
  2156. 2MBEGIN-ENTRY-ADDITIONAL_FUNCTIONS
  2157.  
  2158. RHS_SYNTAX
  2159.   ADDITIONAL_FUNCTIONS
  2160.  
  2161. 4.5 Additional Functions
  2162. The following are additional functions for use on the RHS of CLIPS rules.
  2163.  
  2164. Subtopics :
  2165.  
  2166.     SYSTEM   IF...THEN...ELSE
  2167.     GENSYM   WHILE
  2168.     SETGEN   STRING_CONCATENATION
  2169.     CALL     USING_CLIPS_INTERFACE_COMMANDS
  2170.  
  2171. END-ENTRY
  2172.  
  2173. 3IBEGIN-ENTRY-SYSTEM
  2174.  
  2175. RHS_SYNTAX
  2176.   ADDITIONAL_FUNCTIONS
  2177.     SYSTEM
  2178.  
  2179. 4.5.1 System
  2180. The system function allows a call to the operating system. It is patterned
  2181. after the system function provided to C on most UNIX systems. 
  2182.  
  2183. Syntax:
  2184.  
  2185.    (system <<args>>)
  2186.  
  2187. Example:
  2188.  
  2189.    (defrule print-directory
  2190.       (print-directory  ?directory)
  2191.       =>
  2192.       (system "dir " ?directory))   ; Note space => "dir<space>"
  2193.  
  2194. Note that any spaces needed for proper parsing of the system command must be 
  2195. added by the user in the call to system.
  2196.  
  2197. Portability Note
  2198.  
  2199. Not all operating systems/compilers provide this function. The code is stored
  2200. in the sysdep.c file and the default coding for generic CLIPS is a
  2201. non-functional stub which will compile on any machine.
  2202.  
  2203. END-ENTRY
  2204.  
  2205. 3IBEGIN-ENTRY-GENSYM
  2206.  
  2207. RHS_SYNTAX
  2208.   ADDITIONAL_FUNCTIONS
  2209.     GENSYM
  2210.  
  2211. 4.5.2 Gensym
  2212. The gensym function returns a special, sequenced word, which can be stored as
  2213. a single field. This is primarily for tagging patterns which need a unique
  2214. identifier but the user doesn't care what the identifier is. Multiple calls
  2215. to gensym are guaranteed to return different identifiers of the form:
  2216.  
  2217.             genX
  2218.  
  2219. where X is a positive integer. The first call to gensym returns gen1, all
  2220. subsequent calls increment the number. If users plan to use the gensym
  2221. feature, they should avoid creating facts which include a user defined field
  2222. of this form.
  2223.  
  2224. Example:
  2225.  
  2226.    (assert (new-id  =(gensym) flag1 7))
  2227.  
  2228. which, on the first call, generates a fact of the form:
  2229.  
  2230.    (new-id gen1 flag1 7)
  2231.  
  2232. END-ENTRY
  2233.  
  2234. 3IBEGIN-ENTRY-SETGEN
  2235.  
  2236. RHS_SYNTAX
  2237.   ADDITIONAL_FUNCTIONS
  2238.     SETGEN
  2239.  
  2240. 4.5.3 Setgen
  2241. The setgen function allows the user to set the starting number used by  
  2242. gensym (see RHS_SYNTAX ADDITIONAL_FUNCTIONS GENSYM).
  2243.  
  2244. Syntax:
  2245.  
  2246.    (setgen <num>)
  2247.  
  2248. where <num> must be a positive integer value. All subsequent calls to gensym
  2249. will return a sequenced word with the numeric portion of the word starting at
  2250. <num>.
  2251.  
  2252. Example:
  2253.  
  2254.    (setgen 32)
  2255.  
  2256. After this, calls to gensym will return  gen32, gen33, etc.
  2257.  
  2258. END-ENTRY
  2259.  
  2260. 3IBEGIN-ENTRY-CALL
  2261.  
  2262. RHS_SYNTAX
  2263.   ADDITIONAL_FUNCTIONS
  2264.     CALL
  2265.  
  2266. 4.5.4 Call
  2267. Previous versions of CLIPS provided access to external functions through the
  2268. call syntax. Version 4 of CLIPS allows external functions to be called
  2269. directly from the RHS. To provide compatibility with code written for earlier
  2270. versions, call is still available. Arguments may be passed to the external
  2271. function as described in the Advanced Programming Guide.
  2272.  
  2273. Syntax:
  2274.  
  2275.    (call (<function-name> [<<args...>>]))
  2276.  
  2277. Functions called in this manner must be called for effect only. The return
  2278. value will not be captured.
  2279.  
  2280. Example:
  2281.  
  2282.     (defrule display-valve-system
  2283.       (valve ?v1 open)
  2284.       (valve ?v2&~v1 closed)
  2285.       =>
  2286.       (call (display-valves ?v1 ?v2)))
  2287.  
  2288. END-ENTRY
  2289.  
  2290. 3IBEGIN-ENTRY-IF...THEN...ELSE
  2291.  
  2292. RHS_SYNTAX
  2293.   ADDITIONAL_FUNCTIONS
  2294.     IF...THEN...ELSE
  2295.  
  2296. 4.5.5 If...then...else
  2297. Under certain circumstances, it is preferable to take actions based on
  2298. parameter testing on the RHS of a rule instead of writing two or more rules.
  2299. CLIPS provides an if...then...else structure to allow this kind of operation.
  2300.  
  2301. Syntax:
  2302.  
  2303.    (if (<predicate-function> [<<args...>>])
  2304.     then
  2305.       (<<action 1>>)
  2306.          
  2307.       (<<action n>>)
  2308.    [else
  2309.       (<<action 1>>)
  2310.          
  2311.       (<<action n>>)])
  2312.  
  2313. Any number of allowable RHS actions may be used inside the then or else
  2314. section, including another if...then...else structure. The else portion is
  2315. optional. All predicate functions are available for use in this structure and
  2316. are used as they are in test. Variables used in the comparison must have been
  2317. previously bound.
  2318. Example:
  2319.    (defrule closed-valves
  2320.       (temp high)
  2321.       (valve ?v closed)
  2322.       =>
  2323.       (if (= ?v 6)
  2324.        then
  2325.          (printout "The special valve " ?v " is closed!" crlf)
  2326.          (assert (perform special operation))
  2327.        else
  2328.          (printout "Valve " ?v " is normally closed" crlf)))
  2329.  
  2330. Note that this rule could just as easily have been accomplished with two
  2331. rules, and it is usually better to do so.
  2332.  
  2333.    (defrule closed-valves-number-6
  2334.       (temp high)
  2335.       (valve 6 closed)
  2336.       =>
  2337.       (printout "The special valve 6 is closed!" crlf)
  2338.       (assert (perform special operation)))
  2339.  
  2340.    (defrule closed-valves-other-than-6
  2341.       (temp high)
  2342.       (valve ?v&~6 closed)
  2343.       =>
  2344.       (printout "Valve " ?v " is normally closed" crlf)))
  2345.  
  2346. END-ENTRY
  2347.  
  2348. 3IBEGIN-ENTRY-WHILE
  2349.  
  2350. RHS_SYNTAX
  2351.   ADDITIONAL_FUNCTIONS
  2352.     WHILE
  2353.  
  2354. 4.5.6 While
  2355. The while structure is provided to allow simple looping on the RHS of a rule.
  2356. Its use is similar to that of if...then...else:
  2357.  
  2358. Syntax:
  2359.  
  2360.    (while (<predicate-function> [<<args...>>])
  2361.       (<<action 1>>)
  2362.          
  2363.       (<<action n>>))
  2364.  
  2365. Again, all predicate functions are available for use in while. Any number of
  2366. allowable RHS actions may be placed inside the while block, including
  2367. if...then...else or additional while structures. The test is performed prior
  2368. to the first execution of the loop.
  2369.  
  2370. Example:
  2371.  
  2372.    (defrule open-valves
  2373.       (valves-open-through ?v)
  2374.       =>
  2375.       (while (> ?v 0)
  2376.          (printout "Valve " ?v " is open" crlf)
  2377.          (bind ?v (- ?v 1))))
  2378.  
  2379. END-ENTRY
  2380.  
  2381. 3IBEGIN-ENTRY-STRING_CONCATENATION
  2382.  
  2383. RHS_SYNTAX
  2384.   ADDITIONAL_FUNCTIONS
  2385.     STRING_CONCATENATION
  2386.  
  2387. 4.5.7 String Concatenation
  2388. The str_cat function will concatenate words or quoted strings and returns a
  2389. single quoted string.
  2390.  
  2391. Syntax:
  2392.  
  2393.    (str_cat <item1> <<items>>)
  2394.  
  2395. Each item must be a word, a string, a variable bound to either a word or a
  2396. string, or a function which returns a word or a string. Numbers are not
  2397. allowed.
  2398.  
  2399. Example:
  2400.  
  2401.    (bind ?new (str_cat "foo" bar))
  2402.  
  2403. gives
  2404.  
  2405.      ?new = "foobar"
  2406.  
  2407. END-ENTRY
  2408.  
  2409. 3IBEGIN-ENTRY-USING_CLIPS_INTERFACE_COMMANDS
  2410.  
  2411. RHS_SYNTAX
  2412.   ADDITIONAL_FUNCTIONS
  2413.     USING_CLIPS_INTERFACE_COMMANDS
  2414.  
  2415. 4.5.8 Using CLIPS Interface commands
  2416. Most of the commands documented in USING_CLIPS ENVIRONMENT_COMMANDS as part of
  2417. the CLIPS interactive interface are available on the RHS of a rule. They may be
  2418. called just like any other action. The exceptions are the run, reset, clear and
  2419. excise commands. These should not be called from the RHS of a rule. The
  2420. consequences are unpredictable. See ENVIRONMENT_COMMANDS for descriptions of the
  2421. available commands.
  2422.  
  2423. END-ENTRY
  2424.  
  2425. 1MBEGIN-ENTRY-USING_CLIPS
  2426.  
  2427. USING_CLIPS
  2428.  
  2429. 5.0 Using CLIPS
  2430. CLIPS expert systems may be executed in two ways; interactively using a
  2431. simple, line type interface, or as embedded expert systems in which the user
  2432. provides a main program and controls execution of the expert system. Embedded
  2433. applications are discussed in the Advanced programming Guide. 
  2434.  
  2435. CLIPS provides a simple, interactive, line type interface for high
  2436. portability. The standard usage is: Create or edit rules using any standard
  2437. text editor and save the file(s) as a text file. Exit the editor and execute
  2438. CLIPS. Load rule file(s) into CLIPS. The interface provides commands for
  2439. viewing the current state of the system, tracing execution, adding or
  2440. removing information, or clearing CLIPS.
  2441.  
  2442. Subtopics :
  2443.  
  2444.   ENVIRONMENT_COMMANDS     MEMORY_MANAGEMENT_COMMANDS
  2445.   SYSTEM_STATUS_COMMANDS   ADDITIONAL_COMMANDS
  2446.   DEBUGGING_COMMANDS
  2447.  
  2448. END-ENTRY
  2449.  
  2450. 2IBEGIN-ENTRY-ENVIRONMENT_COMMANDS
  2451.  
  2452. USING_CLIPS
  2453.   ENVIRONMENT_COMMANDS
  2454.  
  2455. 5.1 Environment Commands
  2456. The following commands control the CLIPS environment:
  2457.  
  2458. (reset)   Resets CLIPS. Removes all activations from the agenda 
  2459. and all facts from the fact-list, then asserts all facts listed in 
  2460. deffacts statements into the fact-list.
  2461.  
  2462. (clear)   Removes all rules and deffacts from the environment.  
  2463. Removes all activations from the agenda and all facts from 
  2464. the fact-list.
  2465.  
  2466. (run [<limit>])   Starts execution of the rules. If <limit> is positive,
  2467. execution will cease after <limit> rule firings or when the agenda 
  2468. contains no rule activations. If <limit> is not specified, or is 
  2469. a negative integer, execution will cease when the agenda 
  2470. contains no rule activations.
  2471.  
  2472.    Example:   (run 3)
  2473.  
  2474. (load <file-name>)   Loads the rules stored in the file specified by 
  2475. <file-name> into the environment.
  2476.  
  2477.    Example:    (load "rules.txt")
  2478.  
  2479. (save <file-name>)   Saves all of the rules in the current environment into 
  2480. the file specified by <file-name>.
  2481.  
  2482.    Example:    (save "rules.txt")
  2483.  
  2484. END-ENTRY
  2485.  
  2486. 2IBEGIN-ENTRY-SYSTEM_STATUS_COMMANDS
  2487.  
  2488. USING_CLIPS
  2489.   SYSTEM_STATUS_COMMANDS
  2490.  
  2491. 5.2 System Status Commands
  2492. The following commands display the current CLIPS status:
  2493.  
  2494. (facts)           Displays all facts stored in the fact-list.
  2495.  
  2496. (rules)           Displays the names of all rules stored in the database.
  2497.  
  2498. (agenda)          Displays all activations on the agenda.
  2499.  
  2500. (pprule <rule>)   Displays the text of the rule named <rule>.
  2501.    Example:  (pprule bogus-name)
  2502.  
  2503. (list-deffacts)   Displays the names of all deffact blocks currently loaded 
  2504.                   in CLIPS.
  2505.  
  2506. (ppdeffact <ID>)  Displays the text of a the deffacts block named <ID>.
  2507.  
  2508. END-ENTRY
  2509.  
  2510. 2IBEGIN-ENTRY-DEBUGGING_COMMANDS
  2511.  
  2512. USING_CLIPS
  2513.   DEBUGGING_COMMANDS
  2514.  
  2515. 5.3 Debugging Commands
  2516. The following commands control the CLIPS debugging aids:
  2517.  
  2518. (watch <item>)   If <item> is facts, all fact assertions and retractions will
  2519.                  be displayed.  If <item> is rules, all rule firings will be 
  2520.                  displayed.  If <item> is activations, all rule activations and 
  2521.                  deactivations will be displayed. If <item> is all, then 
  2522.                  facts, rules and activations will all be displayed.
  2523.  
  2524.                  Example:  (watch rules)
  2525.  
  2526. (unwatch <item>)   Deactivates the watch command for <item>. 
  2527.  
  2528.                    Example:  (unwatch rules)
  2529.  
  2530. (matches <rule>)   Displays a list of the facts which match each pattern on
  2531.                    the LHS of the rule, and the combinations, if any.
  2532.  
  2533. (dribble-on <file>)   Sends all watch information to <file>.
  2534.  
  2535. (dribble-off)   Stop sending watch information to a file.
  2536.  
  2537. END-ENTRY
  2538.  
  2539. 2IBEGIN-ENTRY-MEMORY_MANAGEMENT_COMMANDS
  2540.  
  2541. USING_CLIPS
  2542.   MEMORY_MANAGEMENT_COMMANDS
  2543.  
  2544. 5.4 Memory Management Commands
  2545. The following commands display CLIPS memory status information. 
  2546.  
  2547. (mem-used)   Display the number of bytes CLIPS has used since CLIPS 
  2548.              was started.
  2549.  
  2550. (release-mem)   Releases all free memory CLIPS is holding internally back 
  2551.                 to the operating system.
  2552.  
  2553. (conserve-mem)   Turns off storage of pretty print information. This can save
  2554.                  considerable memory in a large system. It should be called
  2555.                  prior to loading any rules.
  2556.  
  2557. These functions generally should not be called unless you know exactly what
  2558. you are doing. CLIPS memory management is more fully described in the
  2559. Advanced Programmers Guide.
  2560.  
  2561. END-ENTRY
  2562.  
  2563. 2IBEGIN-ENTRY-ADDITIONAL_COMMANDS
  2564.  
  2565. USING_CLIPS
  2566.   ADDITIONAL_COMMANDS
  2567.  
  2568. 5.5 Additional Commands
  2569. The following commands are also available:
  2570.  
  2571. (assert <fact>)   Asserts <fact> into the database.
  2572.  
  2573.                   Example:  (assert (this is a fact))
  2574.  
  2575. (retract <<fact#>>)   Retracts the fact(s) with number(s) <<fact#>> from the 
  2576.                       database.   
  2577.  
  2578.                       Example:    (retract 4)  or  (retract 3 24 7)
  2579.  
  2580. (excise <rule>)   Remove the rule named <rule> from the system.
  2581.  
  2582. (undeffacts <name>)   Reverse the effect of a deffacts statement. All facts
  2583.                       listed in the deffacts construct named <name> will no 
  2584.                       longer be put into the initial fact-list after a reset.
  2585.  
  2586. (batch <file>)   Allows "batch" processing of CLIPS interactive commands. 
  2587.                  Processes all commands stored in <file> as though they had 
  2588.                  been entered at the top level. All interface commands can be
  2589.                  used in a batch file, including rule definitions and responses
  2590.                  to read or readline calls. Full error checking will not be 
  2591.                  done on rules defined in this manner (load is better for 
  2592.                  adding rules to the system).
  2593.  
  2594.                  Example:   
  2595.  
  2596.                  (batch "rules.bat") 
  2597.                     where "rules.bat" contains a number of load commands which
  2598.                  will cause all rules to be loaded.
  2599.  
  2600. (<name> [<<args>>])   Any function, user defined or CLIPS defined, may be 
  2601.                       called directly from the top level.
  2602.  
  2603.                       Example:   (system "dir")
  2604.  
  2605. (defrule <<rule>>)   Define a new rule, as described in CLIPS_OVERVIEW
  2606.                      DEFINING_CONSTRUCTS DEFINING_RULES.
  2607.  
  2608. (deffacts <<facts>>)   Define a new deffacts block, as described in 
  2609.                        DEFINING_INITIAL_FACTS.
  2610.  
  2611. As mentioned in USING_CLIPS_INTERFACE_COMMANDS, all of these commands can also
  2612. be called from the RHS of a rule, except the run, reset, excise, or clear
  2613. commands.
  2614.  
  2615. END-ENTRY
  2616.  
  2617. 1MBEGIN-ENTRY-APPENDICES
  2618.  
  2619. APPENDICES
  2620.  
  2621.   DEFINED_FUNCTIONS      GLOSSARY
  2622.   VERSION_DIFFERENCES    ERROR_MESSAGES
  2623.  
  2624. END-ENTRY
  2625.  
  2626. 2IBEGIN-ENTRY-DEFINED_FUNCTIONS
  2627.  
  2628. APPENDICES
  2629.   DEFINED_FUNCTIONS
  2630.  
  2631. The following table lists all the defined functions provided by CLIPS along
  2632. with examples of their use.
  2633.  
  2634.  Symbol     Function                Use                 Means
  2635.                         Logical
  2636.  
  2637.    !        not (inverse)           logical                -
  2638.    &&       and                     logical                -
  2639.    ||       or                      logical                -
  2640.  
  2641.                        Comparison
  2642.  
  2643.    =        equal (numeric)         (test (= ?x ?y))    ?x = ?y
  2644.    eq       equal (any)             (test (eq ?x ?y))   ?x eq ?y
  2645.    !=       not equal (numeric)     (test (!= ?x ?y))   ?x  ?y
  2646.    neq      not equal (any)         (test (neq ?x ?y))  ?x neq ?y
  2647.    >=       greater than or equal   (test (>= ?x ?y))   ?x >= ?y
  2648.    >        greater than            (test (> ?x ?y))    ?x > ?y
  2649.    <=       less than or equal      (test (<= ?x ?y))   ?x <= ?y
  2650.    <        less than               (test (< ?x ?y))    ?x < ?y
  2651.  
  2652.                        Arithmetic
  2653.  
  2654.    /        division                (test (/ ?x ?y))    ?x / ?y
  2655.    *        multiplication          (test (* ?x ?y))    ?x * ?y
  2656.    +        addition                (test (+ ?x ?y))    ?x + ?y
  2657.    -        subtraction             (test (- ?x ?y))    ?x - ?y
  2658.  
  2659.                        Predicate
  2660.  
  2661.    Function          Use                      Means
  2662.  
  2663.    (numberp <arg>)   (foo ?x&:(numberp ?x))   Is the value a number?
  2664.    (stringp <arg>)   (foo ?x&:(stringp ?x))   Is the value a string?
  2665.    (wordp <arg>)     (foo ?x&:(wordp ?x))     Is the value a word?
  2666.    (evenp <arg>)     (foo ?x&:(evenp ?x))     Is the value an even number?
  2667.    (oddp <arg>)      (foo ?x&:(oddp ?x))      Is the value an odd number?
  2668.  
  2669. = and !=  are for comparisons between numbers
  2670. eq and neq are for any kind of comparisons
  2671.  
  2672. END-ENTRY
  2673.  
  2674. 2IBEGIN-ENTRY-VERSION_DIFFERENCES
  2675.  
  2676. APPENDICES
  2677.   VERSION_DIFFERENCES
  2678.  
  2679. Version 4.0
  2680. There have been many changes to CLIPS between the initial release, version
  2681. 3.0, and this release, version 4.0. The primary differences are: 
  2682.  
  2683.    Improved performance - Almost all applications will see some performance 
  2684. improvement using version 4.0 of CLIPS. Some applications  will run up to
  2685. 100% faster.
  2686.  
  2687.    Addition of numerous new functions - This version of CLIPS includes 
  2688. numerous new functions that allow file I/O, access to the underlying operating
  2689. system (on some machines), and makes the extended math package a standard
  2690. feature.
  2691.    Easier integration of custom I/O - The I/O router system makes integration
  2692. of specialized interfaces considerably easier.
  2693.  
  2694.    Easier installation - The CLIPS source code has considerably "cleaned up" 
  2695. and is better documented internally. Compiler directives allows better use of
  2696. machine dependent features. Some features can be selected or left out by
  2697. setting compiler flags.
  2698.  
  2699. None of these changes will affect code written under earlier releases. Great
  2700. care has been taken to insure that CLIPS is upwardly compatible. 
  2701.  
  2702. Minor Changes
  2703.  
  2704. Two functions from version 3.0 are no longer needed: printout, and call. The
  2705. printout function has been replaced by fprintout and format, which are
  2706. compatible with the I/O router system. The call function is no longer needed,
  2707. since user functions can be called directly from the top level or from the
  2708. RHS of a rule. Both these functions are still available to allow
  2709. compatibility with existing CLIPS code. To insure future compatibility and
  2710. efficient performance, old code should be changed to the new syntax.
  2711.  
  2712. The exponentiation function, **, has been moved from the standard math
  2713. package to the extended math package.
  2714.  
  2715. The predicate function stringp works slightly differently. Previously it
  2716. returned true if the argument was either a word or a string. Now it returns
  2717. false if the argument is a word. The wordp function has been added to allow
  2718. checking for variable of type word.
  2719.  
  2720. The function define_function which is used to add user defined functions to
  2721. CLIPS (see the Advanced Programming Guide) now takes four arguments instead
  2722. of three. The fourth argument is a string variable containing the name of the
  2723. external function. Code that calls define_function with only three arguments
  2724. should still work, but ought to be changed for compatibility of future
  2725. versions of CLIPS.
  2726.  
  2727. END-ENTRY
  2728.  
  2729. 2IBEGIN-ENTRY-GLOSSARY
  2730.  
  2731. APPENDICES
  2732.   GLOSSARY
  2733.  
  2734. This section defines some of the terminology used throughout this manual. 
  2735.  
  2736. action   Any of a number of functions which can occur on the RHS of 
  2737.          a rule (see RHS_SYNTAX).
  2738.  
  2739. activation   A rule is activated if all it's conditions are satisfied and it
  2740.              is ready to fire. An activated rule is placed on the agenda.
  2741.  
  2742. agenda   The agenda is a list of all the rules that are presently ready to 
  2743.          fire. It is sorted by salience values. When a rule is activated, 
  2744.          it is placed in front of all the rules that have salience values 
  2745.          less than or equal to its own. The rule at the front of the 
  2746.          agenda is the next rule that will fire.
  2747.  
  2748. conditions   A set of patterns on the LHS of a rule which must all be 
  2749.              satisfied before a rule can fire.
  2750.  
  2751. external function   A function defined by the user or provided by CLIPS and 
  2752.                     called from within CLIPS rules.
  2753.  
  2754. fact   A set of words, strings or numbers separated by spaces. 
  2755.        Facts can have any number of fields and can be in any 
  2756.        order. Facts are the data which the expert system reasons 
  2757.        about. They represent the current state of the world.
  2758.  
  2759. field   A single word, string or number in a pattern or fact.
  2760.  
  2761. fire   A rule is said to have fired if all it's conditions are satisfied 
  2762.        and the actions are then executed.
  2763.  
  2764. instantiated   The pattern or variable has matched successfully against a 
  2765.                fact or field in the current fact-list.
  2766.  
  2767. LHS   Left Hand Side: The logical pattern structure that must be 
  2768.       satisfied in order for the RHS's actions to be performed. 
  2769.  
  2770. number   Any field which consists only of numbers (0-9), a decimal 
  2771.          point (.), a sign (+ or -), and/or an (e) for exponential notation
  2772.    
  2773. pattern   A conditional element on the LHS of a rule which is intended 
  2774.           to match elements in the fact-list.
  2775.  
  2776. RHS   Right Hand Side: The actions to be performed when a rule's 
  2777.       LHS is satisfied.  
  2778.  
  2779. rule   A collection of conditions and actions. When all patterns are 
  2780.        satisfied, the actions will be taken. Rules are the basic unit of 
  2781.        knowledge in CLIPS.
  2782.  
  2783. salience   A priority number given to a rule.  When multiple rules are 
  2784.            ready for firing, they are fired in order of priority. The default 
  2785.            salience is zero (0).  Rules with the same salience are fired 
  2786.            in arbitrary order.
  2787.  
  2788. special character   Any printable character (ASCII codes 32 through 127).
  2789.  
  2790. string   A set of characters that starts with a double quotes (") and is 
  2791.          followed by one or more letters (A-z), numbers (0-9), underscores(_),
  2792.          dashes (-), spaces, or special characters. A string 
  2793.          also ends with double quotes.
  2794.  
  2795. word   Any set of characters that starts with an alphabetic character 
  2796.        and is followed by zero or more letters (A-z), numbers (0-9), 
  2797.        underscores(_), or dashes (-).
  2798.  
  2799. END-ENTRY
  2800.  
  2801. 2MBEGIN-ENTRY-ERROR_MESSAGES
  2802.  
  2803. APPENDICES
  2804.   ERROR_MESSAGES
  2805.  
  2806. CLIPS typically will display two kinds of error messages those associated
  2807. with function execution during run-time, and those associated with parsing
  2808. while loading rules. This appendix describes some of the more common error
  2809. messages and what they mean.
  2810.  
  2811. Subtopics :
  2812.  
  2813.     RUN-TIME_ERRORS    RULE_PARSING_ERRORS
  2814.  
  2815. END-ENTRY
  2816.  
  2817. 3IBEGIN-ENTRY-RUN-TIME_ERRORS
  2818.  
  2819. APPENDICES
  2820.   ERROR_MESSAGES
  2821.     RUN-TIME_ERRORS
  2822.  
  2823. F.1 Run-time Error Message
  2824.  
  2825. --Function <name> expected <number> arguments
  2826.  
  2827. This error occurs when a function is not passed exactly  the number of
  2828. arguments it expects. The function is <name> and the number of arguments it
  2829. expected is <number>.
  2830.  
  2831.  
  2832. --Function <name> expected at least <number> arguments
  2833.  
  2834. This error occurs when a function is passed fewer arguments than it expected.
  2835. The function is <name> and the number of arguments it expected is <number>.
  2836.  
  2837.  
  2838. --Function <name> expected no more than <number> arguments
  2839.  
  2840. This error occurs when a function is passed more arguments than it needs. The
  2841. function is <name> and the number of arguments it expected is <number>.
  2842.  
  2843.  
  2844. --Function <name> expected argument #<number> to be of type <type>
  2845.  
  2846. rfloat received a request from function <name> for argument #<number> which
  2847. is not a number
  2848.  
  2849. rstring received a request from function <name> for argument #<number> which
  2850. is not a string
  2851.  
  2852. These errors occur when a function is passed the wrong type of argument,
  2853. typically a string or word when expecting a number, or vice versa.
  2854.  
  2855.  
  2856. rfloat received a request from function <name> for argument #<number> which
  2857. is non-existent
  2858.  
  2859. rstring received a request from function <name> for argument #<number> which
  2860. is non-existent
  2861.  
  2862. runkown received a request from function <name> for argument #<number> which
  2863. is non-existent
  2864.  
  2865. These errors occur when a function is passed fewer arguments than it
  2866. expected.
  2867.  
  2868. END-ENTRY
  2869.  
  2870. 3IBEGIN-ENTRY-RULE_PARSING_ERRORS
  2871.  
  2872. APPENDICES
  2873.   ERROR_MESSAGES
  2874.     RULE_PARSING_ERRORS
  2875.  
  2876. F.2 Rule Parsing Error Message
  2877. Most parsing errors occur when loading the rules from a file or typing them
  2878. in from the top level interface. If loading them into the CLIPS interactive
  2879. interface, CLIPS will attempt to display the error message along with the
  2880. rule to demonstrate where the error occurred.  Although the error messages
  2881. attempt to provide meaningful information, it may be more useful to look at
  2882. the point at which parsing of the rule stopped.
  2883.  
  2884. --Missing a rule name!
  2885.  
  2886. This error occurs when a rule construct does not have a name.
  2887.  
  2888.  
  2889. --A pattern begins with '(' or ?<var>
  2890.  
  2891. This error occurs when a pattern construct on the LHS of a rule does not have
  2892. an opening parenthesis or variable.
  2893.  
  2894.  
  2895. --LHS of rule <name> contains no patterns only
  2896.  
  2897. This error occurs when a rule has no conditions
  2898.  
  2899.  
  2900. --Only a single pattern may appear after a not
  2901.  
  2902. This error occurs when multiple patterns are placed inside a not construct.
  2903.  
  2904.  
  2905. --Found <token> when expecting => in <rule>
  2906.  
  2907. This error occurs when a RHS action such as bind or fprintout is found before
  2908. the =>.
  2909.  
  2910.  
  2911. --Expected ')' to finish a rule
  2912.  
  2913. This error occurs when the final closing parenthesis is left off a rule.
  2914.  
  2915.  
  2916. --Missing <- after ?<var> in the LHS of <rule>
  2917.  
  2918. This error occurs when attempting to bind a pattern to a variable, but the
  2919. left arrow is forgotten.
  2920.  
  2921.  
  2922. --Missing '(' after ?<var> in the LHS of <rule>
  2923.  
  2924. This error occurs when attempting to bind a pattern to a variable, but the
  2925. opening parenthesis is forgotten.
  2926.  
  2927.  
  2928. --Missing closing ')' for test construct in <rule>
  2929.  
  2930. This error occurs when a closing parenthesis is left out of a test block.
  2931.  
  2932.  
  2933. --Missing '(' after logical pattern operator in <rule>
  2934.  
  2935. This error occurs when an opening parenthesis is left out of an and or or
  2936. construct.
  2937.  
  2938.  
  2939. --Unexpected token <token> found in the LHS of <rule>
  2940.  
  2941. This error occurs when a RHS action such as bind or fprintout are found on
  2942. the LHS of a rule.
  2943.  
  2944.  
  2945. --Expected a pattern element such as a variable, word, or number in the pattern
  2946. of <rule>
  2947.  
  2948. This occurs when a token such as => or <- is found within a pattern.
  2949.  
  2950.  
  2951. --Declaration is illegal at this point in <rule>.
  2952.  
  2953. This error occurs when a declaration is made after a pattern has been found
  2954. or if a declaration is made within a logical pattern operator such as and,
  2955. or, not.
  2956.  
  2957.  
  2958. --Missing a '(' after declare in <rule>
  2959.  
  2960. This error occurs when something other than an opening parenthesis follows a
  2961. declare token.
  2962.  
  2963.  
  2964. --Missing function declaration for function <function> in <rule>
  2965.  
  2966. This error occurs when the function called from either the LHS or RHS of a
  2967. rule is undefined, either because of a typo or because the user forgot to
  2968. define it in usrfuncs.
  2969.  
  2970.  
  2971. --Unable to find variable <name> on RHS of <rule>
  2972.  
  2973. This error occurs when a variable is reference on the RHS of a rule and is
  2974. neither bound on the LHS of the rule or in a bind statement preceding the
  2975. action in which the variable is mentioned.
  2976.  
  2977.  
  2978. --Unable to find variable <name> on LHS of <rule>
  2979.  
  2980. This error occurs when an unbound variable is referred to on the LHS of a
  2981. rule.  This can only occur within a test expression.
  2982.  
  2983.  
  2984. --Unable to find binder <name> on the RHS of rule
  2985.  
  2986. This error occurs when a retract statement references a fact binder that was
  2987. not de-fined within the LHS of the rule.
  2988.  
  2989. Example:
  2990.  
  2991.    (defrule foo ""
  2992.       ?f <- (a)
  2993.       =>
  2994.       (retract ?g))
  2995.  
  2996.  
  2997.  
  2998. --Missing deffacts name
  2999.  
  3000. This error occurs when the name is left off a deffacts block.
  3001.  
  3002.  
  3003. --Variable <name> is unbound in rule <rule>
  3004.  
  3005. This error occurs when a variable is referenced during the execution of a
  3006. rule, but has not yet been bound.  This can only happen to variables that are
  3007. defined in a bind statement. 
  3008.  
  3009. Example:
  3010.  
  3011.    (defrule foo ""
  3012.       (fact ?x)
  3013.            =>
  3014.        (if (> ?x 3) then (bind ?y 4))
  3015.            (assert (new-fact ?y)))
  3016.  
  3017. END-ENTRY
  3018.  
  3019. 1MBEGIN-ENTRY-TEXT_PROCESSING
  3020.  
  3021. TEXT_PROCESSING
  3022.  
  3023. T.0 Text Processing
  3024. CLIPS provides a set of functions to build and access a hierarchical lookup
  3025. system for multiple external files.
  3026.  
  3027. Subtopics :
  3028.  
  3029.   ENTRY_FILE_FORMAT  PRINT-REGION
  3030.   FETCH              TOSS
  3031.  
  3032. END-ENTRY
  3033.  
  3034. 2IBEGIN-ENTRY-ENTRY_FILE_FORMAT
  3035.  
  3036. TEXT_PROCESSING
  3037.   ENTRY_FILE_FORMAT
  3038.  
  3039. T.1 Entry File Format
  3040. Each file that is to be loaded into the internal lookup table must be described
  3041. in a particular way.  Each topic entry in each file must be in the format given
  3042. below : 
  3043.  
  3044. Format:
  3045.  
  3046. $$    <level-num> <entry-type> BEGIN-ENTRY- <topic-name>
  3047.           .                            
  3048.           .
  3049.       Topic information in form to be displayed when referenced.
  3050.           .
  3051.           .
  3052. $$    END-ENTRY
  3053.  
  3054. The delimeter strings must be the only things on their lines. Imbedded
  3055. white-space between the fields of the delimeters is allowed.
  3056.  
  3057. <level-num> is the level of the hierarchical tree to which the entry belongs.
  3058. The lower the number the closer to the root level the topic is, i.e., the
  3059. lowest level number indicates the root level.  Subtopics are indicated by
  3060. making the level number of the current topic larger than the previous entry
  3061. (which is to be the parent).  Thus, the tree must be entered in the file
  3062. sequentially, i.e., a topic with all its subtopics must be described before
  3063. going on to a topic at the same level. Entering a number less than the previous 
  3064. topic's will cause the tree to be searched upwards until a level number is
  3065. found which is less than the current one.  The current topic will then be
  3066. attached as a subtopic at that level. Thus, in this manner, multiple root trees
  3067. may be created. Level number and order of entry in a file can indicate the order
  3068. of precedence in which a list of subtopics which are all children of the same
  3069. topic will be searched.  Topics with the same level number will be searched in
  3070. the order that they appear in the file.  Topics with lower level numbers will be
  3071. searched first.
  3072.  
  3073. Example :
  3074.  
  3075. $$ 0MBEGIN-ENTRY-ROOT
  3076. $$ END-ENTRY
  3077. $$ 2IBEGIN-ENTRY-SUBTOPIC1
  3078. $$ END-ENTRY
  3079. $$ 1IBEGIN-ENTRY-SUBTOPIC2
  3080. $$ END-ENTRY
  3081.  
  3082. In the above example, SUBTOPIC1 and SUBTOPIC2 are both children of ROOT.
  3083. However, in searching the children of ROOT, SUBTOPIC2 would be found first.
  3084.                                                                               
  3085. <entry-type> must be a single CAPITAL letter code : M (for MENU) or I (for 
  3086. INFORMATION).  Only MENU entries may have subtopics.
  3087.  
  3088. <topic-name> can be any alphanumeric string of less than 80 characters. There
  3089. cannot be any white-space imbedded in the name.
  3090.  
  3091. Beginning a line with the delimeter `$$' forces the loader to treat the line
  3092. as pure text, even if one of the key delimeters is in it.  When the line is
  3093. printed, the dollar-signs are treated as blanks.
  3094.  
  3095. Example :
  3096.  
  3097. $$ 0MBEGIN-ENTRY-ROOT1
  3098. $$ END-ENTRY
  3099. $$ 1MBEGIN-ENTRY-1SUBTOPIC1
  3100. $$ END-ENTRY
  3101. $$ 2IBEGIN-ENTRY-11SUBTOPIC1
  3102. $$ END-ENTRY
  3103. $$ 1IBEGIN-ENTRY-1SUBTOPIC2
  3104. $$ END-ENTRY
  3105. $$ 0IBEGIN-ENTRY-ROOT2
  3106. $$ END-ENTRY
  3107. $$ -1MBEGIN-ENTRY-ROOT3
  3108. $$ END-ENTRY
  3109. $$ 0IBEGIN-ENTRY-3SUBTOPIC1
  3110. $$ END-ENTRY
  3111.  
  3112. Tree Diagram of Above Example :
  3113.  
  3114.    --> ROOT1 --> ROOT2 --> ROOT3
  3115.        /   \                 |
  3116.       /     \                |
  3117.      V       V               V
  3118. SUBTOPIC1 1SUBTOPIC2     3SUBTOPIC1
  3119.      |
  3120.      |
  3121.      V
  3122. 11SUBTOPIC1
  3123.  
  3124. END-ENTRY
  3125.  
  3126. 2IBEGIN-ENTRY-FETCH
  3127.  
  3128. TEXT_PROCESSING
  3129.   FETCH
  3130.  
  3131. T.2 fetch
  3132. fetch loads the named file (which must be in the appropriate format) into the
  3133. internal lookup table.
  3134.  
  3135. Syntax :
  3136.  
  3137.   (fetch <file-name>)
  3138.  
  3139. The function returns a non-zero integer if the fetch was successful.  If the 
  3140. file could not be loaded or already was loaded, the function returns zero.
  3141.  
  3142. END-ENTRY
  3143.  
  3144. 2IBEGIN-ENTRY-PRINT-REGION
  3145.  
  3146. TEXT_PROCESSING
  3147.   PRINT-REGION
  3148.  
  3149. T.3 print-region
  3150. print-region looks up a specified entry in a particular file which has been
  3151. previously loaded into the lookup table and prints the contents of that entry
  3152. to the specified output.
  3153.  
  3154. Syntax :
  3155.  
  3156.   (print-region <logical-name> <lookup-file> [<topic-field(s)>])
  3157.  
  3158. <logical-name> is a name previously attached to an output device.  To send
  3159. the output to stdout, specify t for the logical name.
  3160.  
  3161. <lookup-file> is the name of the previously loaded file in which the entry
  3162. is to be found.
  3163.  
  3164. [<topic-fields(s)>] is the full path of the topic entry to be found. For 
  3165. example, to display on the screen the entry for ROOT SUBTOPIC from the file
  3166. foo.lis, you would type : (print-region t "foo.lis" ROOT SUBTOPIC).  Only
  3167. one entry can be accessed per print-region call.
  3168.  
  3169. Each element or field in the path is delimited by white-space, and the
  3170. function is not case sensitive.  In addition, the entire name of a field need
  3171. not be specified. Only enough characters to distinguish the field from other
  3172. choices at the same level of the tree are necessary (if there is a conflict, 
  3173. the function will pick the first one in the list).  For instance, 
  3174. (print-region t "foo.lis" roo sub) would be sufficient for the above example.
  3175.  
  3176. There are a few special fields that can be specified :
  3177.   ^    -  Branch up one level.
  3178. <nil>  -  Giving no topic field will branch up one level.
  3179.  
  3180. The level of the tree for a file remains constant between calls to print-region.
  3181. Thus, in order to access an entry at the root level after branching down
  3182. several levels in a previous call requires an equal amount of branch-ups.
  3183.  
  3184. END-ENTRY
  3185.  
  3186. 2IBEGIN-ENTRY-TOSS
  3187.  
  3188. TEXT_PROCESSING
  3189.   TOSS
  3190.  
  3191. T.4 toss
  3192. toss unloads the named file from the internal lookup table and releases the
  3193. memory back to the system.  
  3194.  
  3195. Syntax :
  3196.  
  3197.   (toss <file-name>)
  3198.  
  3199. The function returns a non-zero integer if the toss was successful.  If the
  3200. file was not on the lookup table, it returns zero.
  3201.  
  3202. END-ENTRY
  3203. 
  3204.