home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 8 Other / 08-Other.zip / PMCLIPS.ZIP / PMCLIPS.HLP (.txt) < prev    next >
OS/2 Help File  |  1990-07-12  |  66KB  |  2,514 lines

  1.  
  2. ΓòÉΓòÉΓòÉ 1. Help for Help ΓòÉΓòÉΓòÉ
  3.  
  4. Select Help for help on the Help pull-down for information on how to use the 
  5. OS/2 System Editor help facility. 
  6.  
  7.  
  8. ΓòÉΓòÉΓòÉ 2. Extended Help for CLIPS ΓòÉΓòÉΓòÉ
  9.  
  10. Use this choice to obtain general information on the application you are using. 
  11.  
  12.  
  13. ΓòÉΓòÉΓòÉ 3. Keys Help for CLIPS ΓòÉΓòÉΓòÉ
  14.  
  15. This is the Keys Help Panel, NOT COMPLETE YET 
  16.  
  17.  
  18. ΓòÉΓòÉΓòÉ 4. Clips Manual Contents Page ΓòÉΓòÉΓòÉ
  19.  
  20. PMClips consists of two separate programs, the CLIPS inference system from NASA 
  21. and PMCLIPS; a Presentation Manager Front End.  PMClips basically forks CLIPS 
  22. as a background process and manages all of the I/O through named pipes 
  23. (re-directed stdin and stdout).  In this BETA release, The following are not 
  24. completely implemented: 
  25.  
  26.     -- Edit and Delete features of
  27.        the BROWSER.
  28.     -- Embeded EMACS Editor (This
  29.        will be provided as a forked
  30.        process)
  31.     -- Some minor problems with Color
  32.        options
  33.     -- Formating of many of the HELP
  34.        screens is not yet complete.
  35. See appendix "E" for support and licensing information. 
  36.  
  37. CLIPS Online Manual Chapters: 
  38.  
  39. 1) CLIPS Overview 
  40. 2) Rule Lefthand Side Syntax 
  41. 3) Rule Righthand Side Syntax 
  42. 4) Using CLIPS 
  43. 5) Appendices 
  44.  
  45.  
  46. ΓòÉΓòÉΓòÉ 5. CLIPS Overview ΓòÉΓòÉΓòÉ
  47.  
  48. Section 1 - CLIPS Overview 
  49.  
  50. This section gives a general overview of CLIPS and the basic concepts  used 
  51. throughout this manual. 
  52.  
  53. Subtopics: 
  54. CLIPS Rules 
  55. CLIPS Facts 
  56. CLIPS Basic Cycle of Execution 
  57. CLIPS Reference Manual Syntax 
  58. Defining Constructs 
  59. Commenting Rules 
  60. Integration with other Languages 
  61.  
  62.  
  63. ΓòÉΓòÉΓòÉ 5.1. Rules ΓòÉΓòÉΓòÉ
  64.  
  65. 1.1 Rules 
  66.  
  67. The primary method of representing knowledge in CLIPS is a rule.  A rule is a 
  68. collection of conditions and the actions to be taken if the conditions are met. 
  69. The developer of an expert system defines the rules which describe how to solve 
  70. a problem.  The entire set of rules in an expert system is called a knowledge 
  71. base.  CLIPS provides the mechanism (the inference engine) which attempts to 
  72. match the rules to the current state of the system and applies the actions. 
  73. The current state is represented by a list of facts. 
  74.  
  75.  
  76. ΓòÉΓòÉΓòÉ 5.2. Facts ΓòÉΓòÉΓòÉ
  77.  
  78. 1.2 Facts 
  79.  
  80. Facts are the basic form of data in a CLIPS system.  Each fact represents a 
  81. piece of information which has been placed in the current list of facts, called 
  82. the fact-list.  Rules execute (or fire) based on the existence or non-existence 
  83. of facts.  A fact is constructed of several positional fields separated by 
  84. spaces or, a word followed by slots separated by parentheses.  Any number of 
  85. fields may be stored in a fact, and the number of facts in the fact-list is 
  86. limited only by the amount of memory in the computer.  Facts may be asserted 
  87. into the fact-list prior to starting execution and may be added (asserted) or 
  88. removed (retracted) as the action of a rule firing.  If a fact is asserted into 
  89. the fact-list that exactly matches an already existing fact, the new assertion 
  90. will be ignored. 
  91.  
  92. Each field within a fact can be one of three things: a number, a word, or a 
  93. string.  A number is any field which consists only of numbers (0-9), a decimal 
  94. point (.), a sign (+ or -), and, optionally, an (e) for exponential notation 
  95. with its corresponding sign.  Some examples are 
  96.  
  97.     237        15.09
  98.     +12.9     -32.3e-7
  99.  
  100. All numbers are stored as single-precision floating-point values, regardless of 
  101. whether a decimal point was included or not.  The number of significant digits 
  102. will depend on the machine implementation.  Roundoff errors also may occur, 
  103. again depending on the machine implementation.  As with any computer language, 
  104. care should be taken when comparing floating-point values. 
  105.  
  106. A word in CLIPS is any sequence of characters that starts with any printable 
  107. ASCII character and is followed by zero or more characters (there are 
  108. exceptions to this rule).  When a delimiter is found, the word is ended.  The 
  109. following characters act as delimiters, a space, a tab, a carriage return, a 
  110. line feed, a double quote, a opening and closing parentheses "(" and ")", an 
  111. ampersand "&", a bar "|", a less than "<", and a tilde "~".  A semicolon ";" 
  112. starts a CLIPS comment (see sec.  2.6) and also acts as a delimiter.  Some 
  113. simple examples are 
  114.  
  115.   foo         Hello
  116.   B76-HI      bad_value
  117.  
  118. CLIPS is case sensitive; i.e., uppercase letters only will match uppercase 
  119. letters.  Some printable ASCII characters may or may not be used as the first 
  120. character in a word, depending on the character that follows it. 
  121.  
  122. A string is a set of characters that starts with a double quote (") and is 
  123. followed by one or more characters (any printable character).  A string ends 
  124. with double quotes.  Double quotes may be embedded within a string by placing a 
  125. backslash (\) in front of the character.  A backslash may be embedded by 
  126. placing two consecutive backslash characters in the string.  Some examples are 
  127.  
  128.   "foo"       "a and b"
  129.   "1 number"  "a\"quote"
  130.  
  131. Note that a string surrounded by double quotes will only match another string. 
  132. A string will not match a word or vice versa.  Strings are sometimes referred 
  133. to as quoted strings. 
  134.  
  135. A slot consists of an opening parenthesis  ("("), a slot name, one or more slot 
  136. values of type number, word, or string, and a closing parenthesis (")").  Slots 
  137. may only be used when the first field of the fact is a word and that word was 
  138. previously declared as a template (See deftemplate below).  Slots may not be 
  139. mixed with the usual, or positional, fields.  Also, slots are required when the 
  140. value of the first field was declared to be a template. 
  141.  
  142. All fields may be of any allowed type, and no restriction is placed on the 
  143. ordering of fields, except as follows.  CLIPS facts are free form, which means 
  144. that there are very few reserved words.  The following words are reserved and 
  145. should not be used as the first field in a fact: test, and, or, not, declare. 
  146. These words are reserved only when used in the first position; they may be used 
  147. in any other field position. 
  148.  
  149. The first fact in the fact-list is asserted automatically by the system during 
  150. a reset.  This fact (initial-fact) can be treated like any other fact and may 
  151. be matched or retracted. 
  152.  
  153.  
  154. ΓòÉΓòÉΓòÉ 5.3. Basic Cycle Of Execution ΓòÉΓòÉΓòÉ
  155.  
  156. 1.3 Basic Cycle of Execution 
  157.  
  158. Once a knowledge base (in the form of rules) is built and the fact-list is 
  159. prepared, CLIPS is ready to execute rules.  In a conventional language, the 
  160. starting point, the stopping point, and the sequence of operations are defined 
  161. explicitly by the programmer.  With CLIPS, the program flow does not need to be 
  162. defined quite so explicitly.  The knowledge (rules) and the data (facts) are 
  163. separated, and the inference engine provided by CLIPS is used to apply the 
  164. knowledge to the data.  The basic execution cycle is as follows: 
  165.  
  166.      a) The knowledge base is examined to see if any rule's conditions have 
  167.     been   met. 
  168.  
  169.      b) All rules whose conditions currently are met are activated and placed 
  170.     on   the agenda.  The agenda is essentially a stack.  Rules are pushed onto 
  171.     the stack when they are activated.  If the priority of the new rule is 
  172.     less than the rule currently on top of the stack, the new rule is pushed 
  173.     down the stack until all rules of higher priority are above it.  Rules of 
  174.     equal or lower priority will remain below the new rule. 
  175.  
  176.      c) The top rule on the agenda is selected and its right-hand side (RHS) 
  177.     actions are executed. 
  178.  
  179.  As a result of RHS actions, new rules can be activated or deactivated.  This 
  180.  cycle is repeated until all rules that can fire have done so or until the rule 
  181.  limit is reached.  The number of rule firings allowed in a cycle may be set by 
  182.  the programmer and rule priorities can be assigned (see salience, sec. 2.8.1). 
  183.  
  184.  
  185. ΓòÉΓòÉΓòÉ 5.4. CLIPS Refference Manual Syntax ΓòÉΓòÉΓòÉ
  186.  
  187. 1.4 Reference Manual Syntax 
  188.  
  189. The terminology used throughout this manual to describe the CLIPS syntax is 
  190. fairly common to computer reference manuals.  Plain words or symbols, 
  191. particularly parentheses, are to be typed exactly as they appear.  Symbols 
  192. enclosed in single-angle brackets, such as <name>, represent a single field to 
  193. be defined by the user.  Symbols enclosed in double-angle brackets, such as 
  194. <<pattern>>, represent one or more fields which must be defined by the user. 
  195. Symbols enclosed within square brackets, such as [<<comment>>], are optional 
  196. parameters.  Vertical bars indicate a choice between multiple parameters. 
  197. White spaces (tabs, spaces, carriage returns) are used by CLIPS only as 
  198. delimiters between fields and are ignored otherwise (unless inside double 
  199. quotes).  Examples in this manual show recommended indentation style. 
  200.  
  201. Small pieces of C code also are used in this manual.  The syntax used for C 
  202. code is slightly different and is more in keeping with the convention used in 
  203. standard C manuals. 
  204.  
  205.  
  206. ΓòÉΓòÉΓòÉ 5.5. Defining Constructs ΓòÉΓòÉΓòÉ
  207.  
  208. 1.5 Defining Constructs 
  209.  
  210. Three defining constructs appear in CLIPS: defrule, deffacts, and deftemplate. 
  211. All constructs in CLIPS are surrounded by parentheses.  The construct opens 
  212. with a left parenthesis and closes with a right parenthesis.  Each pattern or 
  213. block within a construct also opens and closes with parentheses. 
  214.  
  215. Subtopics : 
  216. Defining Rules 
  217. Defining Initial Facts 
  218. Defining a Fact Template 
  219.  
  220.  
  221. ΓòÉΓòÉΓòÉ 5.5.1. Defining Rules ΓòÉΓòÉΓòÉ
  222.  
  223. 1.5.1 Defining Rules 
  224.  
  225. Rules are defined using the defrule construct. 
  226.  
  227. Syntax 
  228.  
  229.   (defrule <name> ["<comment>"]
  230.       [(<<first pattern>>)
  231.          .
  232.          .       ; Left-Hand Side
  233.          .
  234.       (<<nth pattern>>)]
  235.       =>
  236.       [(<<first action>>)
  237.          .
  238.          .       ; Right-Hand Side
  239.          .
  240.       (<<mth action>>)])
  241.  
  242. where <name> is similar to a word, except that it must start with an alphabetic 
  243. character.  The comment is optional and can be any string enclosed within 
  244. double quotes.  The left-hand side (LHS) is made up of a series of patterns 
  245. which represent the condition elements for the rule.  An implicit and always 
  246. surrounds all of the patterns on the LHS.  On the right-hand side (RHS), we 
  247. have a list of actions to be performed when the LHS of the rule is satisfied. 
  248. The arrow (=>) separates the LHS from the RHS.  There is no limit to the number 
  249. of conditions or actions a rule may have (other than the limitation placed by 
  250. actual available memory).  Actions are performed sequentially if, and only if, 
  251. all condition elements on the LHS are satisfied. 
  252.  
  253. If no patterns are on the LHS, the pattern (initial-fact) is automatically 
  254. used.  If no actions are on the RHS, the rule can be activated and fired, but 
  255. nothing will happen. 
  256.  
  257.  
  258. ΓòÉΓòÉΓòÉ 5.5.2. Defining Initial Facts ΓòÉΓòÉΓòÉ
  259.  
  260. 1.5.2 Defining Initial Facts 
  261.  
  262. With the deffacts construct, facts can be added to the initial fact-list. 
  263. Facts asserted through deffacts may be retracted or pattern matched like any 
  264. other fact.  The initial fact-list, including any defined deffacts, is always 
  265. reconstructed after a reset.  All facts added via a deffacts may also be 
  266. retracted by using undeffacts to remove the fact-list (See Section 5.5). 
  267.  
  268. Syntax 
  269.  
  270.   (deffacts <name> ["<comment>"]
  271.       [(<<fact 1>>)
  272.          .
  273.          .
  274.          .
  275.       (<<fact n>>)])
  276.  
  277. where <name> is similar to a word, except that it must start with an alphabetic 
  278. character.  <name> is used to identify the set of facts.  An optional comment 
  279. also may be included.  There may be multiple deffacts constructs.  Any number 
  280. of facts may be asserted into the initial fact-list in each deffacts statement. 
  281.  
  282. Dynamic expressions may be included in a fact by using the pattern expansion 
  283. (=) operator (See Section 2.4.3).  All such expressions are evaluated when 
  284. CLIPS is reset. 
  285.  
  286.  
  287. ΓòÉΓòÉΓòÉ 5.5.3. Defining a Fact Template ΓòÉΓòÉΓòÉ
  288.  
  289. 1.5.3 Defining a Fact Template 
  290.  
  291. Facts, while free form, encode information positionally.  To access that 
  292. information a user must know, not only what data is stored in a fact, but which 
  293. field contains the data.  Templates provide the user with the ability to 
  294. abstract a fact's structure by assigning names to each field found within the 
  295. fact. 
  296.  
  297. Templates are created by using the deftemplate construct. 
  298.  
  299. Syntax 
  300.  
  301. (deftemplate <name> ["<comment>"]
  302.     (field <name>
  303.        (default ?NONE | <<One token of type word, string, or number>>) |
  304.        (type <<One or more of NUMBER, WORD, STRING>> | ?VARIABLE) |
  305.        (allowed-words <<list of allowed WORDS>>) |
  306.        (allowed-strings <<list of allowed strings>>) |
  307.        (allowed-numbers <<list of allowed numbers>>) |
  308.        (range <number> | ?VARIABLE <number> | ?VARIABLE)
  309.     ) |
  310.     (multi-field <name>
  311.        (default ?NONE | <<One or more tokens of type of word, string,
  312.         number>>) |
  313.        (min-number-of-elements <number> | ?VARIABLE) |
  314.        (max-number-of-elements <number> | ?VARIABLE) |
  315.        (type <<One or more of NUMBER, WORD, STRING>> | ?VARIABLE) |
  316.        (allowed-words <<list of allowed WORDS>>) |
  317.        (allowed-strings <<list of allowed strings>>) |
  318.        (allowed-numbers <<list of allowed numbers>>) |
  319.        (range <number> | ?VARIABLE <number> | ?VARIABLE)
  320.     )
  321. )
  322.  
  323. where <name> is similar to a word, except that it must start with an alphabetic 
  324. character.  <name> is used to identify the template.  The value of ?VARIABLE 
  325. must be taken in context.  For example, (range ?VARIABLE ?VARIABLE) is 
  326. equivalent to (range -.  +.).  The attributes labeled "<ignored-..." are not 
  327. processed by CLIPS, hence the name.  They are provided for the CLIPS Cross 
  328. Reference, Style, and Verification (CRSV) utility. 
  329.  
  330. See the Monkees and Bananas Sample Problem for the complete example. 
  331.  
  332. A template may have, at most, one multi-field-slot. 
  333.  
  334. CLIPS inforces the definition of the template on all instances.  For example, 
  335. it is an error to store (or match) multiple values in a single value field. 
  336.  
  337. Fields which are not specified in a pattern are defaulted according to the 
  338. following rules: 
  339.  
  340.     If the pattern is in the LHS, unspecified slots are equivalent to 
  341.     wildcarded (?) fields.  Unspecified multi-value slots are equivalent to 
  342.     multi-value wildcards ($?). 
  343.  
  344.     If the pattern is in an assert, unspecified slots are equivalent to 
  345.     fields specifying the default value(s) for that field.  The word nil is 
  346.     used as the value of a single value slot that has no user-defined 
  347.     default.  The default for a multi-value slot is nothing (i.e. a 
  348.     multifield value of length 0). 
  349.  
  350.  Redefining a deftemplate will result in the previous definition being 
  351.  discarded; adverse effects on facts and rules loaded with the old definition 
  352.  should be expected.  The reason for this is that the template acts as a 
  353.  translator during fact and rule I/O; internally, facts and rules always use 
  354.  positional fields.  Defining a new template may result in a different mapping 
  355.  of name to position which then results in misinterpretation of previously 
  356.  defined facts and rules. 
  357.  
  358.  
  359. ΓòÉΓòÉΓòÉ 5.6. Commenting Clips Rules ΓòÉΓòÉΓòÉ
  360.  
  361. 1.6 Commenting CLIPS Rules 
  362.  
  363. As with any programming language, it is highly beneficial to comment the code. 
  364. The def...  forms defrule, deffacts, and deftemplate allow a comment directly 
  365. following the construct name.  Comments also can be placed within CLIPS code by 
  366. using a semicolon (;).  Everything from the semicolon until the next return 
  367. character will be ignored by the CLIPS reader.  If the semicolon is the first 
  368. character in the line, the entire line will be treated as a comment.  Examples 
  369. of commented code will be provided throughout the reference manual.  Comment 
  370. text is not saved by CLIPS when loading rules. 
  371.  
  372.  
  373. ΓòÉΓòÉΓòÉ 5.7. Integeration with Other Languages ΓòÉΓòÉΓòÉ
  374.  
  375. 1.7 Integration with Other Languages 
  376.  
  377. When using an expert system, two kinds of integration are important: embedding 
  378. CLIPS in other systems, and calling external functions from the RHS or LHS of a 
  379. CLIPS rule.  CLIPS was designed to allow both kinds of integration. 
  380.  
  381. Using CLIPS as an embedded application allows the easy integration of CLIPS 
  382. with existing systems.  This is useful in cases where the expert system is a 
  383. small part of a larger task or needs to share data with other functions.  In 
  384. these situations, CLIPS can be called as a subroutine and information may be 
  385. passed both to and from CLIPS.  Embedded applications are discussed in the 
  386. Advanced Programming Guide. 
  387.  
  388. It also may be useful to call external functions while executing a CLIPS rule. 
  389. CLIPS allows external function calls on both the LHS and RHS of a rule.  On the 
  390. LHS, they can be called as predicate functions to allow specialized testing of 
  391. a rule's conditions.  On the RHS of a rule, they can be called for a number of 
  392. reasons, such as a function to alert the user when an error condition is 
  393. detected.  User-defined external functions also may be called from the top 
  394. level of the interactive interface.  CLIPS variables or literal values may be 
  395. passed to an external function, and functions may return values to CLIPS.  The 
  396. easy addition of external functions allows CLIPS to be extended or customized 
  397. in almost any way.  The Advanced Programming Guide describes how to integrate 
  398. CLIPS with functions or systems written in C as well as in other languages. 
  399.  
  400.  
  401. ΓòÉΓòÉΓòÉ 6. LHS_SYNTAX ΓòÉΓòÉΓòÉ
  402.  
  403. Section 2 - LHS Syntax - Conditions 
  404.  
  405. This section describes the syntax of patterns on the LHS of a rule.  These 
  406. patterns represent the conditions that must be satisfied before a rule can 
  407. fire. 
  408.  
  409. The template fact 'set' is used throughout this section.  The template 
  410. definition to define 'set' is as follows: 
  411.  
  412. (deftemplate set "A structure describing a set of numbers"
  413.     (field size
  414.        (type NUMBER)
  415.        (default 0))
  416.     (field avg
  417.        (type NUMBER)
  418.        (default 0.0))
  419.     (multi-field list
  420.        (type NUMBER)))
  421.  
  422. Subtopics : 
  423. Literal Patterns 
  424. WildCards 
  425. Variables 
  426. Constraining Fields 
  427. Using Test to Constrain Variables 
  428. Constraining Patterns 
  429. Pattern Bindings 
  430. Declaring Rule Properties 
  431.  
  432.  
  433. ΓòÉΓòÉΓòÉ 6.1. LITERAL_PATTERNS ΓòÉΓòÉΓòÉ
  434.  
  435. 2.1 Literal Patterns 
  436.  
  437. The most basic pattern is one which precisely defines the exact fact that will 
  438. match.  This is called a literal pattern.  It does not contain any variables or 
  439. wildcard fields.  All fields in a literal pattern must be matched by all fields 
  440. in a pattern in the fact-list. 
  441.  
  442. Note that space or control characters inside double quotes (i.e., in a string) 
  443. could cause problems.  Roundoff errors also could make it difficult to match 
  444. numerical values to more than three or four decimal places.  Also, field 
  445. ordering does not affect matching when using a template (See previous 
  446. examples). 
  447.  
  448.  
  449. ΓòÉΓòÉΓòÉ 6.2. WILDCARDS ΓòÉΓòÉΓòÉ
  450.  
  451. 2.2 Wildcards Single- and Multifield 
  452.  
  453. CLIPS has two wildcard symbols that may be used to represent fields in a 
  454. pattern.  These are the question (?) and dollar-question ($?) wildcards.  CLIPS 
  455. interprets these wildcard symbols as standing in place of some part of a fact. 
  456. The question wildcard matches any value (number, word, or string) stored in 
  457. exactly one field in the fact.  It is a single-field wildcard symbol.  The 
  458. dollar-question wildcard matches any value in zero or more fields in a fact. 
  459. It is a multifield wildcard symbol standing in the place of multiple fields. 
  460. Single- and multifield wildcards may be combined in a single pattern in any 
  461. combination. 
  462.  
  463. Multifield wildcard and literal fields can be combined to provide very powerful 
  464. constructs.  A pattern to match all of the facts that have the word YELLOW in 
  465. any field (other than the first) could be written as 
  466.  
  467.   (data $? YELLOW $?) 
  468.  
  469. Some examples of what this pattern would match are 
  470.  
  471.     (data YELLOW blue red green)
  472.     (data YELLOW red)
  473.     (data red YELLOW)
  474.     (data YELLOW)
  475.     (data YELLOW data YELLOW)
  476.  
  477. The last fact will match twice, since YELLOW appears twice in the fact.  The 
  478. use of multifield wildcards should be confined to cases of patterns in which 
  479. the single-field wildcard cannot create a pattern that satisfies the match 
  480. required, since the multifield wildcard produces every possible match 
  481. combination that can be derived from a fact.  This derivation of matches 
  482. requires a significant amount of time to perform compared to the time needed to 
  483. perform a single-field match. 
  484.  
  485.  
  486. ΓòÉΓòÉΓòÉ 6.3. VARIABLES ΓòÉΓòÉΓòÉ
  487.  
  488. 2.3 Variables Single- and Multifield 
  489.  
  490. Wildcard symbols replace portions of a fact pattern and accept any value. The 
  491. value of the field being replaced may be captured in a variable for comparison, 
  492. display, or other manipulations.  This is done by directly following the 
  493. wildcard symbol with a variable name. 
  494.  
  495. Syntax 
  496.  
  497.     ?<name> ; a single-field variable
  498.     $?<name>; a multifield variable
  499.  
  500. where <name> is similar to a word, except that it must start with an alphabetic 
  501. character.  Double quotes are not allowed as part of a variable name; i.e.  a 
  502. string cannot be used for a variable name.  The rules for pattern matching are 
  503. similar to those for wildcard symbols.  On its first appearance, a variable 
  504. acts just like a wildcard in that it will bind to any value in the field(s). 
  505. However, later appearances of the variable require the field(s) to match the 
  506. variable's binding.  The binding will only be true within the scope of the rule 
  507. in which it occurs.  Each rule has a private list of variable names with their 
  508. associated values; thus, variables are local to a rule.  Bound variables can be 
  509. passed to external functions. 
  510.  
  511. Once the initial binding of a variable occurs, all references to that same 
  512. variable have to match the same value that the first binding matched.  This 
  513. applies to both single- and multifield variables.  It also applies across 
  514. patterns. 
  515.  
  516.  
  517. ΓòÉΓòÉΓòÉ 6.4. CONSTRAINING_FIELDS ΓòÉΓòÉΓòÉ
  518.  
  519. 2.4 Constraining Fields 
  520.  
  521. Field constraints are functions that constrain the range of values which a 
  522. particular field within a pattern may have.  There are two types of field 
  523. constraints: logical operators and predicate functions. 
  524.  
  525. Subtopics : 
  526. Logical Operators 
  527. Predicate Functions 
  528. Constraining Fields Through Pattern Expansion 
  529.  
  530.  
  531. ΓòÉΓòÉΓòÉ 6.4.1. LOGICAL_OPERATORS ΓòÉΓòÉΓòÉ
  532.  
  533. 2.4.1 Logical Operators 
  534.  
  535. Three logical operators are available for constraining values inside of a 
  536. pattern.  These are the & (AND), | (OR), and ~ (NOT) operators.  The logical 
  537. operators can be combined in almost any manner or number to constrain the value 
  538. of specific fields while pattern matching.  Evaluation of multiple constraints 
  539. can be considered to occur from left to right. 
  540.  
  541. Syntax 
  542.  
  543.     <value1>&<value2>       ; the AND operator
  544.     <value1>|<value2> ; the OR operator
  545.     ~<value>                    ; the NOT operator
  546.  
  547. AND operator typically is used only in conjunction with the other logical 
  548. operators or variable bindings.  Logical operators may be used together with 
  549. variable bindings. 
  550.  
  551. More Syntax 
  552.  
  553.     ?x&<value1>|<value2> ; the OR operator with variable
  554.     ?x&~<value>           ; the NOT operator with variable
  555.  
  556. If this is the first occurrence of the variable name, the field will be 
  557. constrained according to the logical operators only.  The resulting value will 
  558. be stored in the variable.  If the variable has been bound previously, it is 
  559. considered an additional constraint along with the logical operators; i.e., the 
  560. field must have the same value already bound to the variable and it 
  561. additionally must match the constraints defined by the logical operators. 
  562.  
  563.  
  564. ΓòÉΓòÉΓòÉ 6.4.2. PREDICATE_FUNCTIONS ΓòÉΓòÉΓòÉ
  565.  
  566. 2.4.2 Predicate Functions 
  567.  
  568. Sometimes it becomes necessary to constrain a field to more complex values than 
  569. can be defined by logic operators.  CLIPS allows the use of predicate functions 
  570. to accomplish this.  Predicate functions check to see if the value of the field 
  571. meets the constraints defined in the function.  If it does, the function 
  572. returns TRUE and pattern matching continues.  Otherwise, it returns FALSE and 
  573. the pattern fails to match.  Predicate functions are called by combining a 
  574. logical operator with a colon (&:, |: or ~:).  The value of the field must be 
  575. bound to a variable and passed to the function. 
  576.  
  577. Syntax 
  578.  
  579.     ?x&:(<function> <<arguments>>)
  580.     ?x| :(<function> <<arguments>>)
  581.     ?x&~:(<function> <<arguments>>)
  582.  
  583. Multiple predicate functions may be used to constrain a single field.  They are 
  584. evaluated from left to right and are each separated by a logical 
  585. operator/colon.  Several predicate functions are provided by CLIPS; users also 
  586. may develop their own predicate functions.  Predicate functions operate on the 
  587. arguments passed to them.  The predicate functions provided by CLIPS are 
  588.  
  589.       Function              Purpose
  590.  
  591.     (numberp <arg>)   Is the value a number?
  592.     (stringp <arg>)   Is the value a string?
  593.     (wordp <arg>)     Is the value a word?
  594.  
  595. In addition to these functions, the following functions are included in the 
  596. CLIPS extended math package.  integerp does not imply a CLIPS integer data 
  597. type. 
  598.  
  599.     (evenp<arg>)      Is the value an even number?
  600.     (oddp <arg>)      Is the value an odd number?
  601.     (integerp <arg>)  Is the value a whole number?
  602.  
  603.  
  604. ΓòÉΓòÉΓòÉ 6.4.3. CONSTRAINING_FIELDS_THROUGH_PATTERN_EXPANSION ΓòÉΓòÉΓòÉ
  605.  
  606. 2.4.3 Constraining Fields through Pattern Expansion 
  607.  
  608. It is possible to use the return value of an external function to constrain the 
  609. value of a field.  The pattern expansion (=) operator allows the user to call 
  610. external functions from inside of a pattern.  (The pattern expansion operator 
  611. (=) is different from the comparison function which uses the same symbol (=). 
  612. The difference can be determined from context.) The return value must be either 
  613. a string, a word, or a number.  This value is incorporated directly into the 
  614. pattern at the position at which the function was called, and any matching 
  615. patterns must match this value as though the rule were typed with that value. 
  616.  
  617. Syntax 
  618.  
  619.     =(<function> <<args...>>)
  620.  
  621. Note that the return from a pattern expansion may be negated. 
  622.  
  623. Pattern expansion also can be used within variable bindings and combined with 
  624. other logical operators. 
  625.  
  626.  
  627. ΓòÉΓòÉΓòÉ 6.5. USING_TEST_TO_CONSTRAIN_VARIABLES ΓòÉΓòÉΓòÉ
  628.  
  629. 2.5 Using Test to Constrain Variables 
  630.  
  631. The field constraint functions allow very descriptive constraints to be applied 
  632. to pattern matching.  An additional constraint capability is provided with the 
  633. test function.  As with predicate functions, the user can compare the variable 
  634. bindings that already have occurred in any manner.  Mathematical comparisons on 
  635. variables (e.g., is the difference between ?x and ?y greater than some value?) 
  636. and complex logical or equality comparisons can be done.  External functions 
  637. also can be called which compare variables in any way that the user desires. 
  638.  
  639. Any kind of external function may be embedded within a test operation (or 
  640. within field constraints).  User-defined predicate functions must take 
  641. arguments as defined in the Advanced Programming Guide and should return FALSE 
  642. for false and TRUE for true.  (The symbols, TRUE and FALSE, are defined in the 
  643. clips.h file which always should be included in files with user-defined 
  644. functions.) All defined functions use the prefix notation, so the operands to a 
  645. function always appear after the function name.  Several logical, comparison, 
  646. and arithmetic functions are provided by CLIPS.  A complete list of 
  647. CLIPS-defined functions can be found in appendix A. 
  648.  
  649. Syntax 
  650.  
  651.     (test (<defined-function> [<<arguments>>]))
  652.  
  653. Since test is a special type of function call, patterns may not use the word 
  654. test as the first field in a pattern.  A test operation also may not be the 
  655. first pattern on the LHS of a rule.  Functions within a test can be nested and 
  656. are evaluated from the inside out.  The functions inherit their syntax and 
  657. terminology from both LISP and C. 
  658.  
  659. The comparison functions (=, !=, >=, etc.) are valid only for comparing numeric 
  660. fields.  When checking the equality of strings, the eq and neq comparison 
  661. functions should be used.  eq and neq can compare strings or numbers and will 
  662. not produce an error when comparing a string to a number.  All the comparison 
  663. functions also will compare more than two values; e.g., if eq is given a list 
  664. of values, it will only return true if all the values are equal to the first 
  665. value, if >= is given a value, it will return true only if each value is 
  666. greater than the preceding value. 
  667.  
  668. The logical functions and and or provide short-circuited logical operations. 
  669. For those not familiar with short-circuited logic, the functions perform as 
  670. follows.  The and (or) function evaluates its arguments from left-to-right and 
  671. returns false (true) immediately after evaluating an argument whose value was 
  672. false (true).  If all arguments evaluate to true (false) then the function 
  673. returns true (false).  The advantages of short-circuited forms are two-fold. 
  674. First, they are faster since not all of their arguments need be evaluated. 
  675. Secondly, a programmer can use the short-circuited behavior to implement 
  676. optionally executed software. 
  677.  
  678. All defined functions may be used as predicates, although usually it is 
  679. meaningful only for the comparison functions. 
  680.  
  681.  
  682. ΓòÉΓòÉΓòÉ 6.6. PATTERN_MATCHING_WITH_TEMPLATE_FACTS ΓòÉΓòÉΓòÉ
  683.  
  684. 2.6 Pattern Matching with Template Facts 
  685.  
  686. Template facts provide users with the ability to abstract fact structure. 
  687. Templates are a derivative of the relation form of fact.  In this form the 
  688. first field of a fact specifies a "relation" that applied to the remaining 
  689. fields in the fact.  For example, (father-of jack bill) states that bill is the 
  690. father of jack.  Templates differ from relations by using slots for the fields 
  691. following the template name.  The template name (i.e.  relation) is required 
  692. since CLIPS uses it to determine the set of valid slot names. 
  693.  
  694. The example relation, father-of, may be abstracted by choosing names for the 
  695. two variable fields.  For this example, the slot names parent and child are 
  696. chosen.  The resulting template may be declared with the deftemplate form: 
  697.  
  698. (deftemplate father-of
  699.     (field parent
  700.         (default ?NONE))
  701.     (field child
  702.         (default ?NONE)))
  703.  
  704. Now that father-of is a template, the fact that bill is jack's father may be
  705. expressed as either (father-of (parent bill) (child jack)) or (father-of
  706. (child jack) (parent bill)).  The immediate advantages of clarity and slot
  707. order independence should be readily apparent.  There is an additional, less
  708. obvious advantage associated with using templates.
  709.  
  710. That advantage is that a template pattern need not contain all of the slots
  711. defined for that template.  When the pattern is on the LHS of a rule, the
  712. missing slots are equivalent to specifying the slot with a wildcard.  For
  713. example, the pattern (father-of (parent ?father)) is equivalent to (father-of
  714. (parent ?father) (child ?)).  Missing slots in a template being asserted are
  715. assigned their default value, if any, nil if it is a single value slot, or
  716. nothing (i.e.  a multifield value of length 0) if it is a multivalue slot.
  717.  
  718. Template patterns may be used wherever patterns are permitted.  Provided, of
  719. course, that the deftemplate defining a template is parsed prior to all
  720. instances of that template.
  721.  
  722. Template fields are declared at definition time (See deftemplate) to contain
  723. either single or multiple values.  Patterns which do not conform to the
  724. template definition will be flagged as errors.
  725.  
  726. A single value slot used in the LHS may only contain constraints intended to
  727. match a single value, $? and $?<var> may not be used.
  728.  
  729. A multi-value slot has not limitations on the number of values.
  730.  
  731.  
  732.  
  733. ΓòÉΓòÉΓòÉ 6.7. CONSTRAINING_PATTERNS ΓòÉΓòÉΓòÉ
  734.  
  735. 2 . 6  Constraining  Patterns 
  736.  
  737. The  LHS  of  a  CLIPS  rule  is  made  up  of  a  series  of  relation  or 
  738. template  patterns  which  represent  the  conditions  that  must  be 
  739. satisfied  for  the  rule  to  be  placed  on  the  agenda .   CLIPS  assumes 
  740. that  all  rules  have  an  implicit  and  surrounding  the  patterns  on  the 
  741. LHS .   This  means  that  all  conditions  on  the  LHS  must  be  met  before 
  742. the  rule  can  be  activated .   There  is  no  need  to  explicitly  define 
  743. an  implicit  and  condition .   However ,  it  is  possible  to  override 
  744. this  default  and  define  other  logical  combinations  of  conditions  which 
  745. would  cause  a  rule  to  fire . 
  746.  
  747. Logical  pattern  blocks  allow  patterns  to  be  combined  using  inclusive 
  748. or  and  explicit  and  logic .   The  entire  block  is  treated  as  a 
  749. single  condition  on  the  LHS  and  must  be  satisfied  together  with  all 
  750. other  conditions  before  the  rule  can  fire .   Logical  blocks  may  be 
  751. mixed  with  other  logical  blocks  in  any  order ,  and  patterns  within 
  752. the  logical  block  may  use  field  constraints .   As  with  all  CLIPS 
  753. features ,  the  blocks  are  marked  by  opening  and  closing  parentheses . 
  754.  
  755. Subtopics  : 
  756. Inclusive  OR 
  757. Explicit  AND 
  758. Pattern  Negation 
  759.  
  760.  
  761. ΓòÉΓòÉΓòÉ 6.7.1. INCLUSIVE_OR ΓòÉΓòÉΓòÉ
  762.  
  763. 2 . 6 . 1  Inclusive  Or 
  764.  
  765. The  or  logical  block  allows  any  one  of  several  patterns  to  trigger 
  766. a  rule  firing .   If  any  of  the  patterns  inside  of  the  or  block 
  767. exist ,  the  constraint  is  satisfied .   If  all  other  LHS  conditions 
  768. are  true ,  the  rule  will  be  activated .   Any  number  of  patterns  may 
  769. be  within  an  or  block .   The  identical  effect  could  be  accomplished 
  770. by  writing  multiple  rules  with  similar  left -  and  right - hand  sides . 
  771.  
  772. Syntax 
  773.  
  774.     (defrule <name>
  775.         [(<<additional patterns>>)]
  776.         (or (<<pattern 1>>)
  777.                   .
  778.                   .
  779.             (<<pattern n>>))
  780.         [(<<additional patterns>>)]
  781.         =>
  782.         [(<<actions>>)])
  783.  
  784. If more than one of the patterns in the or block can be met, the rule will fire 
  785. multiple times, once for each satisfied combination of conditions. 
  786.  
  787.  
  788. ΓòÉΓòÉΓòÉ 6.7.2. EXPLICIT_AND ΓòÉΓòÉΓòÉ
  789.  
  790. 2.6.2 Explicit And 
  791.  
  792. An explicit and is provided to allow the mixing of and and or conditions. This 
  793. allows logical combinations of patterns within an or block.  The constraint 
  794. will be satisfied when all of the patterns inside of the explicit and block are 
  795. satisfied.  If all other LHS conditions are true, the rule will be activated. 
  796. Any number of patterns may be placed in an and block.  Any number of and's may 
  797. be within an or block. 
  798.  
  799. Syntax 
  800.  
  801.     (defrule <name>
  802.         [(<<additional patterns>>)]
  803.         (or     (and(<<pattern 1>>)
  804.                 .
  805.                 .
  806.                 (<<pattern n>>))
  807.             (<<other patterns>>))
  808.         [(<<additional patterns>>)]
  809.         =>
  810.         [(<<actions>>)])
  811.  
  812.  
  813. ΓòÉΓòÉΓòÉ 6.7.3. PATTERN_NEGATION ΓòÉΓòÉΓòÉ
  814.  
  815. 2.6.3 Pattern Negation 
  816.  
  817. Sometimes the lack of information is meaningful; i.e., one wishes to fire a 
  818. rule if a fact does not exist in the fact-list.  The not function provides this 
  819. capability.  As with logic blocks, any number of additional patterns may be on 
  820. the LHS of the rule and field constraints may be used within the negated 
  821. pattern. 
  822.  
  823. Syntax 
  824.  
  825.     (defrule <name>
  826.         [(<<preceding patterns>>)]
  827.         (not (<<pattern 2>>))
  828.         [(<<additional patterns>>)]
  829.         =>
  830.         [(<<actions>>)])
  831.  
  832. Only one pattern may be negated at a time.  Multiple patterns may be negated by 
  833. using multiple not statements.  And and or logic blocks may not be placed 
  834. inside of a not pattern, although a not may be placed inside of an and or or. 
  835. Care must be taken when combining not with or and and blocks; the results are 
  836. not always obvious! The same holds true for variable bindings within a negated 
  837. pattern.  Variables that are previously bound may be used freely inside of a 
  838. negated pattern.  However, variables bound for the first time within a negated 
  839. pattern can be used only in that pattern.  Since negated patterns are treated 
  840. differently by CLIPS, users always should perform a reset after creating or 
  841. loading rules that include negated patterns. 
  842.  
  843. Negating a not is illegal; i.e., a (not (not (<<pattern>>))) is not allowed. 
  844.  
  845.  
  846. ΓòÉΓòÉΓòÉ 6.8. PATTERN_BINDINGS ΓòÉΓòÉΓòÉ
  847.  
  848. 2.7 Pattern Bindings 
  849.  
  850. Certain RHS actions, such as retract, operate on an entire fact.  To signify 
  851. which fact they are to act upon, a variable can be bound to an entire fact. 
  852.  
  853. Syntax 
  854.  
  855.     ?<var-name><-(<<fields>>)
  856.  
  857. The left arrow, "<-", is a required part of the syntax.  A variable bound to a 
  858. fact can be compared to other fact variables or passed to external functions. 
  859. A fact variable is not 'defined' until the entire pattern has been parsed (see 
  860. examples below). 
  861.  
  862.  
  863. ΓòÉΓòÉΓòÉ 6.9. DECLARING_RULE_PROPERTIES ΓòÉΓòÉΓòÉ
  864.  
  865. 2.8 Declaring Rule Properties 
  866.  
  867. This feature allows the properties or characteristics of a rule to be defined. 
  868. The characteristics are declared on the LHS of a rule using the declare 
  869. construct.  A rule may have multiple declare constructs, but all declare 
  870. statements must appear before the first pattern on the LHS.  The general syntax 
  871. is 
  872.  
  873. Syntax 
  874.  
  875.     (declare (<something> [<<args>>]))
  876.  
  877. Currently, only one declarative feature, salience, is allowed.  Future CLIPS 
  878. versions may provide other declarative capabilities as well as functions to 
  879. allow users to define their own declarative properties. 
  880.  
  881. Subtopics : 
  882. Assigning Rule Priority 
  883.  
  884.  
  885. ΓòÉΓòÉΓòÉ 6.9.1. ASSIGNING_RULE_PRIORITY ΓòÉΓòÉΓòÉ
  886.  
  887. 2.8.1 Assigning Rule Priority 
  888.  
  889. A salience statement allows the user to assign a priority to a rule.  When 
  890. multiple rules are in the agenda, the rule with the highest priority will fire 
  891. first. 
  892.  
  893. Syntax 
  894.  
  895.     (declare (salience <num>))
  896.  
  897. where <num> must be an integer.  If not specified, the salience value for a 
  898. rule defaults to zero.  Salience values may be either positive or negative. 
  899. The largest allowed value is 10000.  The smallest allowed value is -10000. 
  900.  
  901.  
  902. ΓòÉΓòÉΓòÉ 7. RHS_SYNTAX ΓòÉΓòÉΓòÉ
  903.  
  904. Section 3 - RHS Syntax - Actions 
  905.  
  906. This section describes the various actions available on the RHS of  rules. 
  907.  
  908. Subtopics : 
  909. Basic Actions 
  910. Multifield Functions 
  911. String Functions 
  912. CLIPS I/O System 
  913. Math Functions 
  914. Additional FUnctions 
  915.  
  916.  
  917. ΓòÉΓòÉΓòÉ 7.1. BASIC_ACTIONS ΓòÉΓòÉΓòÉ
  918.  
  919. 3.1 Basic Actions 
  920.  
  921. The following actions are the most commonly used RHS actions.  They deal with 
  922. basic functions like asserting and retracting facts. 
  923.  
  924. Subtopics : 
  925. Creating New Facts 
  926. Removing Facts from the Fact List 
  927. Modifying Template Facts 
  928. Asserting a String 
  929. Binding Variables 
  930. Stopping CLIPS 
  931.  
  932.  
  933. ΓòÉΓòÉΓòÉ 7.1.1. CREATING_NEW_FACTS ΓòÉΓòÉΓòÉ
  934.  
  935. 3.1.1 Creating New Facts 
  936.  
  937. The assert action allows the user to add a fact to the fact-list.  Multiple 
  938. facts may be asserted with each call and multiple asserts may be placed on the 
  939. RHS of a rule. 
  940.  
  941. Syntax 
  942.  
  943.     (assert  (<<pattern>>)
  944.             [(<<additional patterns>>)])
  945.  
  946. The fact asserted may contain bound variables, function calls, and literal
  947. values.  If an identical copy of the fact already exists in the fact-list,
  948. the fact will not be added.
  949.  
  950. Subtopics :
  951.  
  952. Calling External Functions
  953.  
  954.  
  955.  
  956.  
  957. ΓòÉΓòÉΓòÉ 7.1.2. CALLING_EXTERNAL_FUNCTIONS ΓòÉΓòÉΓòÉ
  958.  
  959.       CALLING _ EXTERNAL _ FUNCTIONS 
  960.  
  961. 3 . 1 . 1 . 1  Calling  External  Functions 
  962.  
  963. Sometimes  it  is  preferable  to  call  an  external  function  from  inside 
  964. an  assert .   The  return  value  from  the  function  is  incorporated 
  965. directly  into  the  pattern  at  the  position  at  which  the  function  was 
  966. called .   As  with  pattern  expansion  on  the  LHS  of  a  rule ,  the 
  967. pattern  expansion  operator  ( = )  is  used . 
  968.  
  969. Syntax 
  970.  
  971.     (assert ([<<fields>>] =(<function> <<args...>>) [<<fields>>]))
  972.  
  973. This is the same as binding a variable to the return from a function using
  974. the bind function, then placing the variable inside the assert.
  975.  
  976.  
  977.  
  978. ΓòÉΓòÉΓòÉ 7.1.3. REMOVING_FACTS_FROM_THE_FACT-LIST ΓòÉΓòÉΓòÉ
  979.  
  980. 3 . 1 . 2  Removing  Facts  from  the  Fact - list 
  981.  
  982. The  retract  action  allows  the  user  to  remove  facts  from  the  fact - 
  983. list .  Multiple  facts  may  be  retracted  with  a  single  retract 
  984. statement .   The  retraction  of  a  fact  also  removes  all  rules  that 
  985. depended  upon  that  fact  for  activation  from  the  agenda . 
  986.  
  987. Syntax 
  988.  
  989.     (retract ?<fact-var> [?<<fact-vars>>] | <fact-num> [<<fact-nums>>])
  990.  
  991. Facts may be identified either as fact variables (?<fact-var>) bound on the
  992. LHS as described in section 3.7 or by number (<fact-num>).  Note that the
  993. number generally is not known during the execution of a program, so facts
  994. usually are retracted by binding them on the LHS of a rule.  Only fact
  995. variables or fact numbers may be used in a retract.  External functions may
  996. not be called.
  997.  
  998.  
  999.  
  1000. ΓòÉΓòÉΓòÉ 7.1.4. MODIFYING_TEMPLATE_FACTS ΓòÉΓòÉΓòÉ
  1001.  
  1002. 3 . 1 . 3  Modifying  Template  Facts 
  1003.  
  1004. The  modify  action  allows  the  user  to  modify  template  facts  on  the 
  1005. fact - list .  Only  one  fact  may  be  modified  with  a  single  modify 
  1006. statement .   The  modification  of  a  fact  is  equivalent  to  retracting 
  1007. the  present  fact  and  asserting  the  modified  fact . 
  1008.  
  1009. Syntax 
  1010.  
  1011.       (modify ?<fact-var> <<(<field-name> <<field-value>>)>>)
  1012.  
  1013. Facts may be identified either as fact variables (?<fact-var>) bound on the
  1014. LHS as described in section 3.7 or by number (<fact-num>).  Note that the
  1015. number generally is not known during the execution of a program, so facts
  1016. usually are modified by binding them on the LHS of a rule.  Only fact
  1017. variables or fact numbers may be used in a modify.  External functions may
  1018. not be called.
  1019.  
  1020.  
  1021.  
  1022. ΓòÉΓòÉΓòÉ 7.1.5. ASSERTING_A_STRING ΓòÉΓòÉΓòÉ
  1023.  
  1024. 3 . 1 . 4  Asserting  a  String 
  1025.  
  1026. The  str - assert  function  is  similar  to  assert  in  that  it  will  add 
  1027. a  fact  to  the  fact - list .   However ,  str - assert  takes  a  single 
  1028. string  and  breaks  it  into  separate  fields  prior  to  asserting  the 
  1029. fact .   The  standard  delimiters  defined  in  section  2 . 2  will  be  used 
  1030. between  fields .   Only  one  fact  may  be  asserted  with  each  str - 
  1031. assert  statement . 
  1032.  
  1033. Syntax 
  1034.  
  1035.     (str-assert <quoted-string>)
  1036.  
  1037. If an identical copy of the fact already exists in the fact-list, the fact will 
  1038. not be added.  Fields may contain a quoted string by escaping the quote with a 
  1039. backslash.  This function is particularly effective when used with the readline 
  1040. function (see sec.  3.3.2.4).  Note that this function takes a string and turns 
  1041. it into fields.  If the fields within that string are going to contain special 
  1042. characters, they need to be escaped twice. 
  1043.  
  1044. In previous versions of CLIPS, this capability was provided by the 
  1045. string_assert and str_assert functions.  The name was changed for reasons of 
  1046. consistency.  Rules that use either string_assert or str_assert will be 
  1047. accepted by CLIPS for compatibility, but they should be changed to ensure 
  1048. compatibility with future versions of CLIPS. 
  1049.  
  1050.  
  1051. ΓòÉΓòÉΓòÉ 7.1.6. BINDING_VARIABLES ΓòÉΓòÉΓòÉ
  1052.  
  1053. 3.1.5 Binding Variables 
  1054.  
  1055. Occasionally it is important to create new variables or modify the value of 
  1056. previously bound variables on the RHS of a rule.  The bind function provides 
  1057. this capability. 
  1058.  
  1059. Syntax 
  1060.  
  1061.     (bind ?<var-name>  <value> or <variable> or (<defined-function>))
  1062.  
  1063. where <var-name> must be a variable name (it may have been bound previously). 
  1064. <var-name> can be bound to literal values, to other bound variables, or to the 
  1065. return from a function call. 
  1066.  
  1067.  
  1068. ΓòÉΓòÉΓòÉ 7.1.7. STOPPING_CLIPS ΓòÉΓòÉΓòÉ
  1069.  
  1070. 3.1.6 Stopping CLIPS 
  1071.  
  1072. The halt function may be used on the RHS of a rule to prevent further rule 
  1073. firing.  It is called without arguments.  After halt is called, control is 
  1074. returned to the top-level program.  The agenda is left intact, and execution 
  1075. may be continued with a run command. 
  1076.  
  1077. Syntax 
  1078.  
  1079.     (halt)
  1080.  
  1081.  
  1082. ΓòÉΓòÉΓòÉ 7.2. MULTIFIELD_FUNCTIONS ΓòÉΓòÉΓòÉ
  1083.  
  1084. 3.2 Multifield Functions 
  1085.  
  1086. The following functions operate on multifield variables. 
  1087.  
  1088. Subtopics : 
  1089. Number of Elements 
  1090. Specifying and Element 
  1091. Finding an Element 
  1092. Comparing Multifield Variables 
  1093.  
  1094.  
  1095. ΓòÉΓòÉΓòÉ 7.2.1. NUMBER_OF_ELEMENTS ΓòÉΓòÉΓòÉ
  1096.  
  1097. 3.2.1 Number of Elements 
  1098.  
  1099. The length function returns the number of elements bound to a multifield 
  1100. variable. 
  1101.  
  1102. Syntax 
  1103.  
  1104.     (length <variable>)
  1105.  
  1106. where <variable> must be a multifield variable ($?).  If the variable is not a 
  1107. multifield variable, length returns a negative one (-1). 
  1108.  
  1109.  
  1110. ΓòÉΓòÉΓòÉ 7.3. SPECIFYING_AN_ELEMENT ΓòÉΓòÉΓòÉ
  1111.  
  1112. 3.2.2 Specifying an Element 
  1113.  
  1114. The nth function will return a specified element from a multifield variable. It 
  1115. is similar in use to the LISP nth function. 
  1116.  
  1117. Syntax 
  1118.  
  1119.     (nth <constant-or-variable> <mvariable>)
  1120.  
  1121. where <constant-or-variable> is an integer from 1 to the number of elements 
  1122. bound to the <mvariable>.  <mvariable> must be a multifield variable ($?).  The 
  1123. symbol nil will be returned if <constant-or-variable> is greater than the 
  1124. number of elements in the variable. 
  1125.  
  1126.  
  1127. ΓòÉΓòÉΓòÉ 7.3.1. FINDING_AN_ELEMENT ΓòÉΓòÉΓòÉ
  1128.  
  1129. 3.2.3 Finding an Element 
  1130.  
  1131. The member function will tell if an atom is in a multifield variable. 
  1132.  
  1133. Syntax 
  1134.  
  1135.     (member <atom> $?<var>)
  1136.  
  1137. where <atom> can be either a literal value or a variable.  <var> must be bound 
  1138. to a multifield variable.  If <atom> is one of the values bound to <var>, 
  1139. member will return the number of the element.  Otherwise it will return 0. 
  1140.  
  1141.  
  1142. ΓòÉΓòÉΓòÉ 7.3.2. COMPARING_MULTIFIELD_VARIABLES ΓòÉΓòÉΓòÉ
  1143.  
  1144. 3.2.4 Comparing Multifield Variables 
  1145.  
  1146. This function checks if one multifield variable is a subset of another; i.e., 
  1147. if all the elements in the first set are also in the second set. 
  1148.  
  1149. Syntax 
  1150.  
  1151.     (subset $?<list1> $?<list2>)
  1152.  
  1153. Both variables must have been bound previously.  If <list1> is a subset of 
  1154. <list2>, the function returns TRUE; otherwise it returns FALSE.  The order of 
  1155. the list is not considered.  If $?<list1> is bound to an empty set, subset 
  1156. always returns TRUE. 
  1157.  
  1158.  
  1159. ΓòÉΓòÉΓòÉ 7.4. DELETION_OF_FIELDS_IN_MULTIFIELD_VALUES ΓòÉΓòÉΓòÉ
  1160.  
  1161. 3.2.5 Deletion of Fields in Multifield Values 
  1162.  
  1163. This function deletes an indexed field from a multifield value. 
  1164.  
  1165. Syntax 
  1166.  
  1167.     (mv-delete <field-index> <list>)
  1168.  
  1169. where <field-index> may be any CLIPS number and <list> may be any multifield 
  1170. value.  The modified multifield value is returned which is the same as 
  1171. <list>with the field specified by <field-index> removed. 
  1172.  
  1173.  
  1174. ΓòÉΓòÉΓòÉ 7.4.1. APPENDING_MULTIFIELD_VALUES ΓòÉΓòÉΓòÉ
  1175.  
  1176. 3.2.6 Appending Multifield Values 
  1177.  
  1178. This function appends any number of values to create a multifield value. 
  1179.  
  1180. Syntax 
  1181.  
  1182.     (mv-append [<Item 1> <Item 2> <Item 3> ..... <Item n>])
  1183.  
  1184. where <Item i> may be any CLIPS value.  A multifield value is returned as the
  1185. result.  If any <item> is not multifield then it is assumed to be a
  1186. multifield value of length 1.  If mv-append is called with no arguments, it
  1187. returns an empty multifield variable (which is meaningful!).  If it is called
  1188. with one argument, it turns that value into a multifield variable.
  1189.  
  1190.  
  1191.  
  1192. ΓòÉΓòÉΓòÉ 7.4.2. CREATING_MULTIFIELD_VALUES_FROM_STRINGS ΓòÉΓòÉΓòÉ
  1193.  
  1194. 3 . 2 . 7  Creating  Multifield  Values  from  Strings . 
  1195.  
  1196. This  function  constructs  a  multifield  value  from  a  string  by  using 
  1197. each  field  in  a  string  as  a  field  in  a  new  multifield  value . 
  1198.  
  1199. Syntax 
  1200.  
  1201.     (str-explode <string>)
  1202.  
  1203. A new multifield value is created in which each delimited field in order in 
  1204. string is taken to be a field in the new multifield value which is returned. 
  1205.  
  1206.  
  1207. ΓòÉΓòÉΓòÉ 7.4.3. CREATING_STRINGS_FROM_MULTIFIELD_VALUES ΓòÉΓòÉΓòÉ
  1208.  
  1209. 3.2.8 Creating Strings from Multifield Values 
  1210.  
  1211. This function creates a single string from a multifield value. 
  1212.  
  1213. Syntax 
  1214.  
  1215.     (str-implode <list>)
  1216.  
  1217. Each field in list in order is concatenated into a string value with a single 
  1218. blank separating fields.  The new string is returned. 
  1219.  
  1220.  
  1221. ΓòÉΓòÉΓòÉ 7.4.4. EXTRACTING_A_SUBSEQUENCE_FROM_A_MULTIFIELD_VALUE ΓòÉΓòÉΓòÉ
  1222.  
  1223. 3.2.9 Extracting a Sub-sequence from a Multifield Value 
  1224.  
  1225. This function extracts a specified range from a multifield value and returns a 
  1226. new multifield value containing just the sub-sequence. 
  1227.  
  1228. Syntax 
  1229.  
  1230.     (mv-subseq <start-index> <end-index> <list>)
  1231.  
  1232. where <start-index> and <end-index> are integers specifying the starting and 
  1233. ending points of the desired sub-sequence in <list>. 
  1234.  
  1235.  
  1236. ΓòÉΓòÉΓòÉ 7.5. STRING_FUNCTIONS ΓòÉΓòÉΓòÉ
  1237.  
  1238. 3.3 String Functions 
  1239.  
  1240. The following functions perform operations that are related to strings. 
  1241. String Concatenation 
  1242. Taking a String Apart 
  1243. Searching a String 
  1244. Converting a String to Lowercase 
  1245. Converting a String to Uppercase 
  1246. Compareng two Strings 
  1247. Evaluating a String 
  1248.  
  1249.  
  1250. ΓòÉΓòÉΓòÉ 7.5.1. STRING_CONCATENATION ΓòÉΓòÉΓòÉ
  1251.  
  1252. 3.3.1 String Concatenation 
  1253.  
  1254. The str-cat function will concatenate words, numbers, or quoted strings and 
  1255. return a single quoted string. 
  1256.  
  1257. Syntax 
  1258.  
  1259.     (str-cat <item1> <<items>>)
  1260.  
  1261. Each item can be any one of: a word, number, string, bound variable, or 
  1262. function. 
  1263.  
  1264. In previous versions of CLIPS, this capability was provided by the str_cat 
  1265. function.  The name was changed for reasons of consistency.  Rules that use 
  1266. str_cat will be accepted by CLIPS for compatibility, but they should be changed 
  1267. to ensure compatibility with future versions of CLIPS. 
  1268.  
  1269.  
  1270. ΓòÉΓòÉΓòÉ 7.5.2. TAKING_A_STRING_APART ΓòÉΓòÉΓòÉ
  1271.  
  1272. 3.3.2 Taking a String Apart 
  1273.  
  1274. The sub-string function will retrieve a portion of a string from another 
  1275. string. 
  1276.  
  1277. Syntax 
  1278.  
  1279.     (sub-string <starting-position> <ending-position> <string>)
  1280.  
  1281. where <starting-position>, counting from one, must be a number marking the 
  1282. beginning position in <string> to get the sub-string, <ending-position> must be 
  1283. a number marking the ending position in <string>, and <string> may be any valid 
  1284. CLIPS string.  If <starting-position> is greater than or equal to 
  1285. <ending-position>, a null string is returned. 
  1286.  
  1287.  
  1288. ΓòÉΓòÉΓòÉ 7.5.3. SEARCHING_A_STRING ΓòÉΓòÉΓòÉ
  1289.  
  1290. 3.3.3 Searching a String 
  1291.  
  1292. The str-index function will retrieve the position of a string inside another 
  1293. string. 
  1294.  
  1295. Syntax 
  1296.  
  1297.     (str-index  <string-to-find> <string-to-search>)
  1298.  
  1299. where <string-to-search> is searched for the first occurrence of 
  1300. <string-to-find>.  Returns the starting position, counting from one, of 
  1301. <string-to-find> in <string-to-search> or returns 0 if not found. 
  1302.  
  1303.  
  1304. ΓòÉΓòÉΓòÉ 7.5.4. EVALUATING_A_STRING ΓòÉΓòÉΓòÉ
  1305.  
  1306. 3.3.4 Evaluating a String 
  1307.  
  1308. The eval function evaluates the string as though it were entered at the 
  1309. command prompt. 
  1310.  
  1311. Syntax 
  1312.  
  1313.     (eval  <string-or-word>)
  1314.  
  1315. where <string-or-word> the command to be executed.  Note: eval does not permit 
  1316. the use of variables nor will it evaluate any of the construct definition forms 
  1317. (i.e.  defrule, deffacts, deftemplate). 
  1318.  
  1319. The eval function is not available for run-time modules. 
  1320.  
  1321.  
  1322. ΓòÉΓòÉΓòÉ 7.5.5. CONVERTING_A_STRING_TO_UPPERCASE ΓòÉΓòÉΓòÉ
  1323.  
  1324. 3.3.5 Converting a String to Uppercase 
  1325.  
  1326. The upcase function will return a string or word with uppercase alphabetic 
  1327. characters. 
  1328.  
  1329. Syntax 
  1330.  
  1331.     (upcase  <string-or-word>)
  1332.  
  1333. where <string-or-word> is the string to be converted. 
  1334.  
  1335.  
  1336. ΓòÉΓòÉΓòÉ 7.5.6. CONVERTING_A_STRING_TO_LOWERCASE ΓòÉΓòÉΓòÉ
  1337.  
  1338. 3.3.6 Converting a String to Lowercase 
  1339.  
  1340. The lowcase function will return a string or word with lowercase alphabetic 
  1341. characters. 
  1342.  
  1343. Syntax 
  1344.  
  1345.     (lowcase  <string-or-word>)
  1346.  
  1347. where <string-or-word> is the string to be converted. 
  1348.  
  1349.  
  1350. ΓòÉΓòÉΓòÉ 7.5.7. COMPARING_TWO_STRINGS ΓòÉΓòÉΓòÉ
  1351.  
  1352. 3.3.7 Comparing Two Strings 
  1353.  
  1354. The str-compare function will compare two strings to determine their logical 
  1355. relationship (i.e.  equal, less than, greater than).  The comparison is 
  1356. performed character-by-character until the strings are exhausted (implying 
  1357. equal strings) or unequal characters are found.  The positions of the unequal 
  1358. characters within the ASCII character set are used to determine the logical 
  1359. relationship of unequal strings. 
  1360.  
  1361. Syntax 
  1362.  
  1363.     (str-compare  <string-or-word1> <string-or-word2>)
  1364.  
  1365. returns 0 if the strings are equal, < 0 if string-or-word1 < string-or-word2, 
  1366. and > 0 if string-or-word1 > string-or-word2. 
  1367.  
  1368.  
  1369. ΓòÉΓòÉΓòÉ 7.6. CLIPS_I/O_SYSTEM ΓòÉΓòÉΓòÉ
  1370.  
  1371. 3.4 The CLIPS I/O System 
  1372.  
  1373. CLIPS uses a system called input/output (I/O) routing to provide very flexible 
  1374. I/O while remaining portable.  A more complete discussion of I/O routing is 
  1375. covered in the Advanced Programming Guide. 
  1376.  
  1377. Subtopics : 
  1378. Logical Names 
  1379. Common I/O Functions 
  1380.  
  1381.  
  1382. ΓòÉΓòÉΓòÉ 7.6.1. LOGICAL_NAMES ΓòÉΓòÉΓòÉ
  1383.  
  1384. 3.4.1 Logical Names 
  1385.  
  1386. One of the key concepts of I/O routing is the use of logical names.  Logical 
  1387. names allow reference to an I/O device without having to understand the details 
  1388. of the implementation of the reference.  Many functions in CLIPS make use of 
  1389. logical names.  A logical name can be either a word, a number, or a string. 
  1390. Several logical names are predefined by CLIPS and used extensively throughout 
  1391. the CLIPS code. 
  1392.  
  1393.  
  1394. ΓòÉΓòÉΓòÉ 7.6.2. COMMON_I/O_FUNCTIONS ΓòÉΓòÉΓòÉ
  1395.  
  1396. 3.4.2 Common I/O Functions 
  1397.  
  1398. CLIPS provides some of the most commonly needed I/O capabilities through 
  1399. several predefined functions. 
  1400.  
  1401. Subtopics : 
  1402. Open 
  1403. Close 
  1404. Read 
  1405. ReadLine 
  1406. Fprintout and Printout 
  1407. Format 
  1408.  
  1409.  
  1410. ΓòÉΓòÉΓòÉ 7.6.2.1. OPEN ΓòÉΓòÉΓòÉ
  1411.  
  1412. 3.4.2.1 Open 
  1413.  
  1414. The open function allows a user to open a file from the RHS of a rule and 
  1415. attaches a logical name to it.  This function takes three arguments: (1) the 
  1416. name of the file to be opened; (2) the logical name which will be used by other 
  1417. CLIPS I/O functions to access the file; and (3) an optional mode specifier. 
  1418. The mode specifier must be one of the following: 
  1419.  
  1420.   Mode      Means
  1421.      r         read access only
  1422.      w         write access only
  1423.      r+        read and write access
  1424.      a         append access only
  1425.  
  1426. If the mode is not specified, a default of read access only is assumed.  The 
  1427. access mode may not be meaningful in some operating systems. 
  1428.  
  1429. Syntax   (open "<file-name>" <logical-name> ["<mode>"]) 
  1430.  
  1431. The <file-name> must be enclosed in double quotes and may include directory 
  1432. specifiers.  The backslash (\) and any other special characters that are part 
  1433. of <file-name> must be escaped with a backslash.  The logical name should not 
  1434. have been used previously. 
  1435.  
  1436.  
  1437. ΓòÉΓòÉΓòÉ 7.6.2.2. CLOSE ΓòÉΓòÉΓòÉ
  1438.  
  1439. 3.4.2.2 Close 
  1440.  
  1441. The close function closes a file stream previously opened with the open 
  1442. command.  The file is specified by a logical name previously attached to the 
  1443. desired stream. 
  1444.  
  1445. Syntax 
  1446.  
  1447.     (close [<logical-name>])
  1448.  
  1449. If close is called without arguments, all open files will be closed. 
  1450.  
  1451. The user is responsible for closing all files opened during execution.  If 
  1452. files are not closed, the contents are not guaranteed to be correct. 
  1453.  
  1454.  
  1455. ΓòÉΓòÉΓòÉ 7.6.2.3. READ ΓòÉΓòÉΓòÉ
  1456.  
  1457. 3.4.2.3 Read 
  1458.  
  1459. The read function allows a user to input information for a single field.  All 
  1460. of the standard field rules (e.g., multiple words must be embedded within 
  1461. quotes) apply. 
  1462.  
  1463. Syntax 
  1464.  
  1465.     (read [<logical-name>])
  1466.  
  1467. where <logical-name> is an optional parameter.  If specified, read tries to 
  1468. read from whatever is attached to the logical file name.  If <logical-name> is 
  1469. t or is not specified, the function will read from stdin.  All the delimiters 
  1470. defined in section 2.2 can be used as delimiters.  If an end of file (EOF) is 
  1471. encountered while reading, read will return the word EOF.  If errors are 
  1472. encountered while reading, the string "*** READ ERROR ***" will be returned. 
  1473.  
  1474.  
  1475. ΓòÉΓòÉΓòÉ 7.6.2.4. READLINE ΓòÉΓòÉΓòÉ
  1476.  
  1477. 3.4.2.4 Readline 
  1478.  
  1479. The readline function is similar to the read function, but it allows a whole 
  1480. string to be input instead of a single field.  Normally, read will stop when it 
  1481. encounters a delimiter.  readline only stops when it encounters a carriage 
  1482. return, a semicolon or an end of file.  Any tabs or spaces in the input are 
  1483. returned by readline as a part of the string.  readline returns a quoted 
  1484. string. 
  1485.  
  1486. Syntax 
  1487.  
  1488.     (readline [<logical-name>])
  1489.  
  1490. where <logical-name> is an optional parameter.  If specified, readline tries to 
  1491. read from whatever is attached to the logical file name.  If <logical-name> is 
  1492. t or is not specified, the function will read from stdin.  As with read, if an 
  1493. end of file is encountered, readline will return the word EOF.  If an error is 
  1494. encountered during input, readline returns the quoted string "*** READ ERROR 
  1495. ***". 
  1496.  
  1497.  
  1498. ΓòÉΓòÉΓòÉ 7.6.2.5. FPRINTOUT_AND_PRINTOUT ΓòÉΓòÉΓòÉ
  1499.  
  1500. 3.4.2.5 Fprintout and Printout 
  1501.  
  1502. These functions, fprintout and printout, allow output to a device attached to a 
  1503. logical name.  The logical name must be specified and the device must have been 
  1504. prepared previously for output (e.g., a file must be opened first).  To send 
  1505. output to stdout, use a t for the logical name.  The function will evaluate 
  1506. variable bindings and print the value of a variable in the output string.  Any 
  1507. number of items may be placed in an fprintout or a printout. 
  1508.  
  1509. Syntax 
  1510.  
  1511.     (fprintout <logical-name> <item> ... <item> [crlf])
  1512.     (printout <logical-name> <item> ... <item> [crlf])
  1513.  
  1514. where <item> is a literal value, a bound variable, or a function call.  The 
  1515. word crlf will force a carriage return/newline and may be placed anywhere in 
  1516. the item list. 
  1517.  
  1518. Note that the printout function has been modified from releases previous to 
  1519. version 4.2 of CLIPS and uses the same syntax as fprintout.  This function is 
  1520. still provided for compatibility with code written in earlier releases of 
  1521. CLIPS, but t will have to be supplied as the logical name to the printout 
  1522. function call. 
  1523.  
  1524.  
  1525. ΓòÉΓòÉΓòÉ 7.6.2.6. FORMAT ΓòÉΓòÉΓòÉ
  1526.  
  1527. 3.4.2.6 Format 
  1528.  
  1529. The format function allows a user to send formatted output to a device attached 
  1530. to a logical name.  It can be used in place of printout when special formatting 
  1531. of output information is desired.  Although a slightly more complicated 
  1532. function, format provides much better control over how the output is formatted. 
  1533. The format commands are similar to the printf statement in C.  The format 
  1534. function always returns a string containing the formatted output.  A logical 
  1535. name of nil may be used when the formatted return string is desired without 
  1536. writing to a device. 
  1537.  
  1538. Syntax   (format <logical-name> "<control-string>" <<parameter-list>>) 
  1539.  
  1540. where <logical-name> is any logical name.  If t is given, output is sent to 
  1541. stdout.  The <control-string> is a quoted string which specifies how the output 
  1542. should be formatted.  The <<parameter-list>> is the bound variables or literal 
  1543. values which are to be output.  Function calls also may be embedded in the 
  1544. <<parameter-list>> and the return from the function will be output.  Format 
  1545. currently does not support multifield variables in the <<parameter-list>>. 
  1546.  
  1547. The control string consists of text and format flags.  Text is output exactly 
  1548. as specified, and format flags describe how each parameter in the 
  1549. <<parameter-list>> is to be formatted.  The first format flag corresponds to 
  1550. the first value in the parameter list, the second flag corresponds to the 
  1551. second value, and so on.  The format flags must be preceded by a percent sign 
  1552. (%) and are of the general format    %-M.Nx 
  1553.  
  1554. where x is one of the flags listed below, the minus sign is an optional 
  1555. justification flag, and M and N are optional parameters which specify the field 
  1556. width and number of digits following the decimal place.  If M is used, at least 
  1557. M characters will be output.  If more than M characters are required to display 
  1558. the value, format expands the field as needed.  If M starts with a 0 (e.g., 
  1559. %07d), a zero is used as the pad character; otherwise spaces are used.  If N is 
  1560. not specified, it defaults to six digits for floating-point numbers.  If a 
  1561. minus sign is included before the M, the value will be left justified; 
  1562. otherwise the value is right justified. 
  1563.  
  1564. Format Flags
  1565.  d Display parameter as an integer.
  1566.    (The N specifier has no meaning.)
  1567.  
  1568.  f Display parameter as a floating-point
  1569.    number.
  1570.  
  1571.  e Display parameter as a floating-point
  1572.    using power of 10 notation.
  1573.  
  1574.  g Display parameter in the most general
  1575.    format, whichever is shorter.
  1576.  
  1577.  o Display parameter as an unsigned octal
  1578.    number.  (The N specifier has no
  1579.    meaning.)
  1580.  
  1581.  x Display parameter as an unsigned
  1582.    hexadecimal number.  (The N specifier
  1583.    has no meaning.)
  1584.  
  1585.  s Display parameter as a string.  Quoted
  1586.    strings will have the leading and
  1587.    trailing quotes stripped.  (The N
  1588.    specifier has no meaning.  Zero also
  1589.    cannot be used for the pad character.)
  1590.  
  1591.  n Put a carriage return/line feed in the
  1592.    output.
  1593.  
  1594.  % Put the percent character into the
  1595.    output.
  1596. Portability Note 
  1597.  
  1598. The format function uses the C function sprintf as a base. Some systems may not 
  1599. support sprintf or may not support all of these features, which may affect how 
  1600. format works. 
  1601.  
  1602.  
  1603. ΓòÉΓòÉΓòÉ 7.7. MATH_FUNCTIONS ΓòÉΓòÉΓòÉ
  1604.  
  1605. 3.5 Math Functions 
  1606.  
  1607. CLIPS provides several functions for mathematical computations.  They are split 
  1608. into two packages:  a set of standard math functions and a set of  extended 
  1609. math functions. 
  1610.  
  1611. Subtopics : 
  1612. Standard Math Functions 
  1613. Extended Math Functions 
  1614.  
  1615.  
  1616. ΓòÉΓòÉΓòÉ 7.7.1. STANDARD_MATH_FUNCTIONS ΓòÉΓòÉΓòÉ
  1617.  
  1618.  3.5.1 Standard Math Functions  The standard math functions include add, 
  1619. subtract, multiply, and divide.  These functions should be used only on numeric 
  1620. arguments.  An error message will be printed if a string argument is passed to 
  1621. a math function.  Arithmetic function calls can be used anywhere that an 
  1622. external function is valid. 
  1623.  
  1624.  
  1625. ΓòÉΓòÉΓòÉ 7.7.2. EXTENDED_MATH_FUNCTIONS ΓòÉΓòÉΓòÉ
  1626.  
  1627. 3.5.2 Extended Math Functions 
  1628.  
  1629. In addition to the standard math functions, CLIPS also provides a large number 
  1630. of scientific and trigonometric math functions for more extensive computations. 
  1631. Although included in the generic version of CLIPS, if an expert system does not 
  1632. need these capabilities, these functions may be excluded from the executable 
  1633. element of CLIPS to provide more memory (see the Advanced Programming Guide). 
  1634.  
  1635. The following functions all take one argument: eneral Syntax 
  1636.  
  1637. (<fun> <arg>)
  1638.  
  1639. Function                 Returns
  1640.   acos     arccosine
  1641.   acosh    hyperbolic arccosine
  1642.   acot     arccotangent
  1643.   acoth    hyperbolic arccotangent
  1644.   acsc     arccosecant
  1645.   acsch    hyperbolic arccosecant
  1646.   asec     arcsecant
  1647.   asech    hyperbolic arcsecant
  1648.   asin     arcsine
  1649.   asinh    hyperbolic arcsine
  1650.   atan     arctangent
  1651.   atanh    hyperbolic arctangent
  1652.   cos      cosine
  1653.   cosh     hyperbolic cosine
  1654.   cot      cotangent
  1655.   coth     hyperbolic tangent
  1656.   csc      cosecant
  1657.   csch     hyperbolic cosecant
  1658.   sec      secant
  1659.   sech     hyperbolic secant
  1660.   sin      sine
  1661.   sinh     hyperbolic sine
  1662.   tan      tangent
  1663.   tanh     hyperbolic tangent
  1664.  
  1665. NOTE:  All trigonometric functions
  1666.        expect RADIAN arguments.
  1667.  
  1668.   abs      absolute value
  1669.   deg-grad convert from degrees to gradiant
  1670.   deg-rad  convert from degrees to radians
  1671.   exp      e**<arg>
  1672.   grad-deg convert from gradiant to degrees
  1673.   log      log base e
  1674.   log10    log base 10
  1675.   rad-deg  convert from radians to degrees
  1676.   sqrt     square root
  1677.   trunc    truncates argument to integer
  1678.  
  1679. The following functions take multiple arguments:
  1680.  
  1681.        # OF ARGS RETURNS
  1682.   **   2         arg1 raised to the arg2 power
  1683.   max  1 or more max value of all args
  1684.   min  1 or more min value of all args
  1685.   mod  2         modulus of arg1 by arg2
  1686.   pi   none      the value of pi
  1687.  
  1688. Portability Note 
  1689.  
  1690. These mathematical functions use the C library math.h.  If the user's system 
  1691. does not support this library, the user needs to make some adjustments to 
  1692. math.c.  The system-dependent math functions are called from clcos, clsin, and 
  1693. so on.  The user must change each of these to call the appropriate functions 
  1694. from his system.  The user also must make sure that the functions clcos, clsin, 
  1695. etc., always return FLOATING point numbers.  To link these functions, most 
  1696. compilers provide a separate math library that must be included during linking. 
  1697.  
  1698.  
  1699. ΓòÉΓòÉΓòÉ 7.8. ADDITIONAL_FUNCTIONS ΓòÉΓòÉΓòÉ
  1700.  
  1701. 3.6 Additional Functions 
  1702.  
  1703. The following are additional functions for use on the RHS of CLIPS rules. 
  1704.  
  1705. Subtopics : 
  1706. System 
  1707. Gensym 
  1708. SetGen 
  1709. Call 
  1710. If Then Else 
  1711. While 
  1712. Using CLIPS Interface Commands 
  1713.  
  1714.  
  1715. ΓòÉΓòÉΓòÉ 7.8.1. SYSTEM ΓòÉΓòÉΓòÉ
  1716.  
  1717. 3.6.1 System 
  1718.  
  1719. The system function allows a call to the operating system.  It is patterned 
  1720. after the system function provided to C on most UNIX systems. 
  1721.  
  1722. Syntax 
  1723.  
  1724.     (system <<args>>)
  1725.  
  1726. Note that any spaces needed for proper parsing of the system command must be 
  1727. added by the user in the call to system. 
  1728.  
  1729. Portability Note 
  1730.  
  1731. Not all operating systems/compilers provide this function.  The code is stored 
  1732. in the sysdep.c file, and the default coding for generic CLIPS is a 
  1733. nonfunctional stub that will compile on any machine. 
  1734.  
  1735.  
  1736. ΓòÉΓòÉΓòÉ 7.8.2. GENSYM ΓòÉΓòÉΓòÉ
  1737.  
  1738. 3.6.2 Gensym 
  1739.  
  1740. The gensym function returns a special, sequenced word that can be stored as a 
  1741. single field.  This is primarily for tagging patterns that need a unique 
  1742. identifier, but the user does not care what the identifier is.  Multiple calls 
  1743. to gensym are guaranteed to return different identifiers of the form 
  1744.  
  1745.         genX 
  1746.  
  1747. where X is a positive integer.  The first call to gensym returns gen1; all 
  1748. subsequent calls increment the number.  Note that gensym is not reset after a 
  1749. call to clear.  If users plan to use the gensym feature, they should avoid 
  1750. creating facts which include a user-defined field of this form. 
  1751.  
  1752.  
  1753. ΓòÉΓòÉΓòÉ 7.8.3. SETGEN ΓòÉΓòÉΓòÉ
  1754.  
  1755. 3.6.3 Setgen 
  1756.  
  1757. The setgen function allows the user to set the starting number used by gensym 
  1758. (see sec.  3.5.2). 
  1759.  
  1760. Syntax 
  1761.  
  1762.     (setgen <num>)
  1763.  
  1764. where <num> must be a positive integer value.  All subsequent calls to gensym 
  1765. will return a sequenced word with the numeric portion of the word starting at 
  1766. <num>. 
  1767.  
  1768. After this, calls to gensym will return gen32, gen33, etc. 
  1769.  
  1770.  
  1771. ΓòÉΓòÉΓòÉ 7.8.4. CALL ΓòÉΓòÉΓòÉ
  1772.  
  1773. 3.6.4 Call 
  1774.  
  1775. Previous versions of CLIPS provide access to external functions through the 
  1776. call syntax.  CLIPS now allows external functions to be called directly from 
  1777. the RHS.  To provide compatibility with code written for earlier versions, call 
  1778. is still available.  Arguments may be passed to the external function as 
  1779. described in the Advanced Programming Guide. 
  1780.  
  1781. Syntax 
  1782.  
  1783.     (call (<function-name> [<<args...>>]))
  1784.  
  1785. Functions called in this manner must be called for effect only.  The return 
  1786. value will not be captured. 
  1787.  
  1788.  
  1789. ΓòÉΓòÉΓòÉ 7.8.5. IF THEN ELSE ΓòÉΓòÉΓòÉ
  1790.  
  1791. 3.6.5 If...then...else 
  1792.  
  1793. Under certain circumstances, it is preferable to take actions based on 
  1794. parameter testing on the RHS of a rule instead of writing two or more rules. 
  1795. CLIPS provides an if...then...else structure to allow for this kind of 
  1796. operation. 
  1797.  
  1798. Syntax 
  1799.  
  1800.     (if (<predicate-function> [<<args...>>])
  1801.     then
  1802.         [(<<action 1>>)
  1803.             .
  1804.         (<<action n>>)]
  1805.     [else
  1806.         (<<action 1>>)
  1807.             .
  1808.         (<<action n>>)])
  1809.  
  1810. Any number of allowable RHS actions may be used inside of the then or else 
  1811. section, including another if...then...else structure.  The else portion is 
  1812. optional.  All predicate functions are available for use in this structure and 
  1813. are used as proscribed in test.  Variables used in the comparison must have 
  1814. been bound previously. 
  1815.  
  1816.  
  1817. ΓòÉΓòÉΓòÉ 7.8.6. WHILE ΓòÉΓòÉΓòÉ
  1818.  
  1819. 3.6.6 While 
  1820.  
  1821. The while structure is provided to allow simple looping on the RHS of a rule. 
  1822. Its use is similar to that of if...then...else. 
  1823.  
  1824. Syntax 
  1825.  
  1826.     (while (<predicate-function> [<<args...>>]) [do]
  1827.         [(<<action 1>>)
  1828.             .
  1829.         (<<action n>>)])
  1830.  
  1831. Again, all predicate functions are available for use in while.  Any number of 
  1832. allowable RHS actions may be placed inside the while block, including 
  1833. if...then...else or additional while structures.  The test is performed prior 
  1834. to the first execution of the loop.  The while may optionally include the word 
  1835. do after the predicate function and before the first action. 
  1836.  
  1837.  
  1838. ΓòÉΓòÉΓòÉ 7.8.7. USING_CLIPS_INTERFACE_COMMANDS ΓòÉΓòÉΓòÉ
  1839.  
  1840. 3.6.7 Using CLIPS Interface Commands 
  1841.  
  1842. Most of the commands documented in section 5.1 as part of the CLIPS interactive 
  1843. interface are available on the RHS of a rule.  They may be called just like any 
  1844. other action.  The exceptions are the run, reset, clear, and excise commands. 
  1845. These commands are disabled when called from the RHS of a rule since the 
  1846. consequences are unpredictable.  See section 5.1 for descriptions of the 
  1847. available commands. 
  1848.  
  1849.  
  1850. ΓòÉΓòÉΓòÉ 8. USING_CLIPS ΓòÉΓòÉΓòÉ
  1851.  
  1852. Section 4 - Using CLIPS 
  1853.  
  1854. CLIPS expert systems may be executed in three ways: interactively using a 
  1855. simple, line-type interface, interactively using a window/menu/mouse interface 
  1856. on certain machines, or as embedded expert systems in which the user provides a 
  1857. main program and controls execution of the expert system.  Embedded 
  1858. applications are discussed in the Advanced Programming Guide.  In addition a 
  1859. command line option is available to allow commands normally issued in the 
  1860. line-type interface to be read directly from a file. 
  1861.  
  1862. The generic CLIPS interface is a simple, interactive, line-type interface for 
  1863. high portability.  The standard usage is to create or edit rules using any 
  1864. standard text editor and save the file(s) as a text file, to exit the editor 
  1865. and execute CLIPS, then load rule file(s) into CLIPS.  The interface provides 
  1866. commands for viewing the current state of the system, tracing execution, adding 
  1867. or removing information, or clearing CLIPS. 
  1868.  
  1869. A more sophisticated window interface is available for Macintosh and MS-DOS 
  1870. machines.  All of the interface commands described in this section are 
  1871. available in the window interfaces.  These interfaces are described in more 
  1872. detail in the Utilities and Interfaces Guide. 
  1873.  
  1874. Subtopics : 
  1875. Environment Commands 
  1876. System Status Commands 
  1877. Debugging Commands 
  1878. Memory Management Commands 
  1879. Additional Commands 
  1880.  
  1881.  
  1882. ΓòÉΓòÉΓòÉ 8.1. ENVIRONMENT_COMMANDS ΓòÉΓòÉΓòÉ
  1883.  
  1884. 4.1 Environment Commands The following commands control the CLIPS environment: 
  1885.  
  1886. (bload <file-name>) 
  1887.  
  1888. Loads the rules and deffacts stored in the file specified by <file-name> into 
  1889. the environment. The specified file must have been created by bsave. 
  1890.  
  1891.     Example    (bload "rules.bin")
  1892.  
  1893. (bsave <file-name>) 
  1894.  
  1895. Saves all of the rules and deffacts in the current environment into the file 
  1896. specified by <file-name>. The save file is written using a binary format which 
  1897. results in a smaller file, and faster save/load commands.  The save file must 
  1898. be loaded via the bload command.    Defrelation and deftemplate forms are not 
  1899. saved in the save file. 
  1900.  
  1901.     Example    (bsave "rules.bin")
  1902.  
  1903. (clear) 
  1904.  
  1905. Removes all rules and deffacts from the environment. Removes all activations 
  1906. from the agenda and all facts from the fact-list. 
  1907.  
  1908. (exit) 
  1909.  
  1910. Quit CLIPS. 
  1911.  
  1912. (load-facts <file>) 
  1913.  
  1914. This function will assert a file of information as facts into the CLIPS 
  1915. fact-list.  It can read files created with save-facts or any ASCII text file. 
  1916. Each line is treated as a separate fact. Input lines must be less than 512 
  1917. characters. 
  1918.  
  1919. (load <file-name>) 
  1920.  
  1921. Loads the rules and deffacts stored in the file specified by <file-name> into 
  1922. the environment. Files generated with the save command can not be loaded using 
  1923. load. 
  1924.  
  1925.     Example    (load "rules.txt")
  1926.  
  1927. (reset) 
  1928.  
  1929. Resets CLIPS.  Removes all activations from the agenda and all facts from the 
  1930. fact-list, then asserts all facts listed in deffacts statements into the 
  1931. fact-list. 
  1932.  
  1933. (run [<limit>]) 
  1934.  
  1935. Starts execution of the rules.  If <limit> is positive, execution will cease 
  1936. after <limit> rule firings or when the agenda contains no rule activations.  If 
  1937. <limit> is not specified or is a negative integer, execution will cease when 
  1938. the agenda contains no rule activations. 
  1939.  
  1940.     Example   (run 3)
  1941.  
  1942. (save-facts <file>) 
  1943.  
  1944. This function saves all of the facts in the current fact-list into the file 
  1945. specified by <file>. Printed facts must not exceed 512 characters. 
  1946.  
  1947. (save <file-name>) 
  1948.  
  1949. Saves all of the rules and deffacts in the current environment into the file 
  1950. specified by <file-name>. 
  1951.  
  1952. Example    (save "rules.txt")
  1953.  
  1954.  
  1955. ΓòÉΓòÉΓòÉ 8.2. SYSTEM_STATUS_COMMANDS ΓòÉΓòÉΓòÉ
  1956.  
  1957. 4.2 System Status Commands The following commands display the current CLIPS 
  1958. status: 
  1959.  
  1960. (agenda) 
  1961.  
  1962. Displays all activations on the agenda. 
  1963.  
  1964. (facts [<start> [<end> [<max>]]]) 
  1965.  
  1966. Displays facts stored in the fact-list. Without any arguments, it displays all 
  1967. facts. If only <start> is specified, it displays all facts with id numbers 
  1968. greater than or equal to <start>. If both <start> and <end> are specified, it 
  1969. displays all facts between <start> and <end>, exclusive. If <start>, <end>, and 
  1970. <max> are specified, it displays all facts between <start> and <end> up to a 
  1971. limit of <max> facts. 
  1972.  
  1973. (list-deffacts) 
  1974.  
  1975. Displays the names of all deffact blocks currently loaded in CLIPS. 
  1976.  
  1977. (list-deftemplates) 
  1978.  
  1979. Displays the names of all deftemplate forms currently loaded in CLIPS. 
  1980.  
  1981. (options) 
  1982.  
  1983. Generates a textual description of the status of the CLIPS compiler flags. 
  1984.  
  1985. (ppdeffact <ID>) 
  1986.  
  1987. Displays the text of the deffacts block named <ID>. 
  1988.  
  1989. (ppdeftemplate <ID>) 
  1990.  
  1991. Displays the text of the deftemplate named <ID>. 
  1992.  
  1993. (pprule <rule>) 
  1994.  
  1995. Displays the text of the rule named <rule>. 
  1996.  
  1997.     Example  (pprule bogus-name)
  1998.  
  1999. (rules) 
  2000.  
  2001. Displays the names of all rules stored in the data base. 
  2002.  
  2003. (time) 
  2004.  
  2005. Returns the elapsed seconds since the system reference time. 
  2006.  
  2007.  
  2008. ΓòÉΓòÉΓòÉ 8.3. DEBUGGING_COMMANDS ΓòÉΓòÉΓòÉ
  2009.  
  2010. 4.3 Debugging Commands 
  2011.  
  2012. The following commands control the CLIPS debugging aids: 
  2013.  
  2014. (crsv-trace-off) 
  2015.  
  2016. Stop sending trace information to a file. 
  2017.  
  2018. (crsv-trace-on <file>) 
  2019.  
  2020. Sends all information normally generated by a (watch all) to the specified file 
  2021. using a format that is more efficient for CRSV to read than the format used by 
  2022. watch. 
  2023.  
  2024. (dribble-off) 
  2025.  
  2026. Stops sending watch information to a file. 
  2027.  
  2028. (dribble-on <file>) 
  2029.  
  2030. Sends all information normally sent to the logical names wclips, wdialog, 
  2031. wdisplay, werror, wtrace, wagenda, and stdout to <file> as well as to their 
  2032. normal place.  Additionally, all information received from logical name stdin 
  2033. is also sent to <file> as well as being returned by the requesting function. 
  2034.  
  2035. (matches <rule>) 
  2036.  
  2037. Displays a list of facts which matches each pattern on the LHS of the rule and 
  2038. the combinations, if any. 
  2039.  
  2040. (remove-break [<name>]) 
  2041.  
  2042. Removes a breakpoint for the rule <name>.  If no rule name is given, removes 
  2043. all breakpoints. 
  2044.  
  2045. (set-break <name>) 
  2046.  
  2047. Sets a breakpoint for the rule <name>.  If a breakpoint is set for rule <name> 
  2048. execution will stop prior to executing rule <name>. At least one rule must fire 
  2049. before a breakpoint will stop execution. 
  2050.  
  2051. (show-breaks) 
  2052.  
  2053. Shows all current breakpoints. 
  2054.  
  2055. (unwatch <item>) 
  2056.  
  2057. Deactivates the watch command for <item>. 
  2058.  
  2059.     Example  (unwatch rules)
  2060.  
  2061. (watch <item>) 
  2062.  
  2063. If <item> is facts, all fact assertions and retractions will be displayed.  If 
  2064. <item> is rules, all rule firings will be displayed.  If <item> is activations, 
  2065. all rule activations and deactivations will be displayed.  If <item> is 
  2066. compilations, the progress of rule compilations will be displayed.  If <item> 
  2067. is all, facts, rules, activations, and compilations will all be displayed. 
  2068.  
  2069.     Example  (watch rules)
  2070.  
  2071.  
  2072. ΓòÉΓòÉΓòÉ 8.4. MEMORY_MANAGEMENT_COMMANDS ΓòÉΓòÉΓòÉ
  2073.  
  2074. 4.4 Memory Management Commands 
  2075.  
  2076. The following commands display CLIPS memory status information: 
  2077.  
  2078. (mem-used) 
  2079.  
  2080. Displays the number of bytes CLIPS has currently in-use or held for later use. 
  2081.  
  2082. (mem-requests) 
  2083.  
  2084. Displays the number of times CLIPS has requested memory from the operating 
  2085. system. 
  2086.  
  2087. (release-mem) 
  2088.  
  2089. Releases all free memory held internally by CLIPS back to the operating system. 
  2090.  
  2091. (conserve-mem <arg>) 
  2092.  
  2093. Turns on or off the storage of information used for save and pretty print 
  2094. commands.  <arg> either may be on or off.  This can save considerable memory in 
  2095. a large system.  It should be called prior to loading any rules. 
  2096.  
  2097.     Example  (conserve-mem on)
  2098.  
  2099. These functions generally should not be called unless the user knows exactly 
  2100. what he is doing.  CLIPS memory management is described more fully in the 
  2101. Advanced Programming Guide. 
  2102.  
  2103.  
  2104. ΓòÉΓòÉΓòÉ 8.5. ADDITIONAL_COMMANDS ΓòÉΓòÉΓòÉ
  2105.  
  2106. 4.5 Additional Commands 
  2107.  
  2108. The following commands also are available:  (<name> [<<args>>]) 
  2109.  
  2110. Any function, user-defined or CLIPS-defined, may be called directly from the 
  2111. top level. 
  2112.  
  2113.     Example  (system "dir")
  2114.  
  2115. (assert <<facts>>) 
  2116.  
  2117. Asserts <facts> into the data base. 
  2118.  
  2119.     Example  (assert (this is a fact))
  2120.  
  2121. (batch <file>) 
  2122.  
  2123. Allows "batch" processing of CLIPS interactive commands. Processes all commands 
  2124. stored in <file> as though they had been entered at the top level. All 
  2125. interface commands can be used in a batch file, including rule definitions and 
  2126. responses to read or readline calls.  Full error checking will not be done on 
  2127. rules defined in this manner (Users should use a load command in the batch file 
  2128. rather the explicit defrule commands). Example (batch "rules.bat") where 
  2129. "rules.bat" contains a number of load commands which will cause all rules to be 
  2130. loaded. 
  2131.  
  2132. (deffacts <<facts>>) 
  2133.  
  2134. Defines a new deffacts block, as described in section 2.5.2.  If a deffacts 
  2135. with the same name already exists, the previous deffacts will be excised, even 
  2136. if the new deffacts has errors in it. 
  2137.  
  2138. (defrule <<rule>>) 
  2139.  
  2140. Defines a new rule, as described in section 2.5.1. If a rule with the same name 
  2141. already exists, the previous rule will be excised, even if the new rule has 
  2142. errors in it. 
  2143.  
  2144. (deftemplate <<template>>) 
  2145.  
  2146. Defines a new template, as described in section 2.5.3.  If a template with the 
  2147. same name already exists, the previous template will be excised, even if the 
  2148. new template has errors in it. Furthermore, rules loaded under the old template 
  2149. may not be compatible with the rules loaded under the new template. 
  2150.  
  2151. (excise <rule>) 
  2152.  
  2153. Removes the rule named <rule> from the system. 
  2154.  
  2155. (retract <<fact#>>) 
  2156.  
  2157. Retracts the fact(s) with number(s) <<fact#>> from the data base. 
  2158.  
  2159.     Example    (retract 4)  or  (retract 3 24 7)
  2160.  
  2161. (undeffacts <name>) 
  2162.  
  2163. Reverses the effect of a deffacts statement.  All facts listed in the deffacts 
  2164. construct named <name> will no longer be put into the initial fact-list after a 
  2165. reset. 
  2166.  
  2167. (undeftemplate <name>) 
  2168.  
  2169. Reverses the effect of a deftemplate statement. No further uses of the template 
  2170. <name> are permitted.  Existing <name> facts will be displayed using positional 
  2171. notation.  Rules previously compiled with patterns using template <name> are 
  2172. still valid. 
  2173.  
  2174. In addition to the commands described here, most of the actions described in 
  2175. section 4 can be used.  As mentioned in section 4.5.10, most of the interface 
  2176. commands also can be called from the RHS of a rule, but users must be aware of 
  2177. how to display the information.  Some information, such as from functions like 
  2178. pprule, facts, agenda, and rules, are actual printouts which always are sent 
  2179. through the router system to some output device.  Other information sent to the 
  2180. screen while using the interface is actually a return value from the function 
  2181. call.  Functions such as mem-used and all of the math functions are in this 
  2182. category.  This second kind of function can be used on the RHS, but its value 
  2183. must be captured in a variable using bind and the variable printed. 
  2184.  
  2185. The actions run, reset, excise, or clear commands should not be called from the 
  2186. RHS of a rule since their effects will be unpredictable.  The actions defrule, 
  2187. deffacts and deftemplate will give an error message if they are used on the 
  2188. RHS. 
  2189.  
  2190.  
  2191. ΓòÉΓòÉΓòÉ 8.6. COMMAND-LINE_OPTIONS ΓòÉΓòÉΓòÉ
  2192.  
  2193. 4.6 Command-line Options (Not Yet implemented for PMCLIPS) 
  2194.  
  2195. By using a command-line option, all commands normally input at the CLIPS prompt 
  2196. may be read from a file instead. The syntax is as follows: 
  2197.  
  2198. Syntax 
  2199.  
  2200.     clips -f <filename>
  2201.  
  2202. The -f is required, and <filename> is a file that contains CLIPS commands. If 
  2203. the (exit) command is included in the file then, CLIPS will halt and the user 
  2204. is returned to the operating system after executing the commands in the file. 
  2205. If an (exit) command is not in the file, CLIPS will enter in its interactive 
  2206. state after executing the commands in the file. 
  2207.  
  2208. Unlike batch, reading from the command line file will not replace stdin.  Any 
  2209. read or readline commands in the file which read from stdin (or t) must still 
  2210. be input from the keyboard.  Also, the CLIPS prompt or any commands will not be 
  2211. displayed until CLIPS enters interactive state. 
  2212.  
  2213.  
  2214. ΓòÉΓòÉΓòÉ 9. APPENDICES ΓòÉΓòÉΓòÉ
  2215.  
  2216. Subtopics: 
  2217. Reserved Function Names 
  2218. Integrated Editor 
  2219. Support Information 
  2220.  
  2221.  
  2222. ΓòÉΓòÉΓòÉ 9.1. RESERVED_FUNCTION_NAMES ΓòÉΓòÉΓòÉ
  2223.  
  2224. Appendix A - Reserved Function Names 
  2225.  
  2226. This appendix lists all the functions provided by either standard CLIPS or 
  2227. various CLIPS extensions. They should be considered reserved function names 
  2228. and users should not create user-defined functions with any of these names. 
  2229.  
  2230. Standard functions. 
  2231.  
  2232. The following table lists all of the basic functions provided by standard 
  2233. CLIPS. 
  2234.  
  2235. agenda             mv-subseq
  2236. assert             nth
  2237. batch              open
  2238. bind               ppdeffact
  2239. bload              ppdeftemplate
  2240. bsave              pprule
  2241. call               printout
  2242. clear              read
  2243. close              readline
  2244. conserve-mem       release-mem
  2245. crsv-trace-off     remove-break
  2246. crsv-trace-on      reset
  2247. deffacts           retract
  2248. defrule            rules
  2249. deftemplate        rules-to-c
  2250. dribble-off        run
  2251. dribble-on         save
  2252. edit               save-facts
  2253. eval               set-break
  2254. excise             setgen
  2255. exit               show-breaks
  2256. facts              str-assert
  2257. format             str-cat
  2258. fprintout          str-compare
  2259. gensym             str-explode
  2260. halt               str-implode
  2261. if                 str-index
  2262. length             str-length
  2263. list-deffacts      string_assert
  2264. list-deftemplates  sub-string
  2265. load               subset
  2266. load-facts         system
  2267. lowcase            time
  2268. matches            undeffacts
  2269. mem-requests       undefrule
  2270. mem-used           undeftemplate
  2271. member             unwatch
  2272. modify             upcase
  2273. mv-append          watch
  2274. mv-delete          while
  2275.  
  2276. Logical Functions 
  2277.  
  2278. The following table lists all of the logical functions provided by standard 
  2279. CLIPS. 
  2280.  
  2281. !
  2282. &&
  2283. and
  2284. not
  2285. or
  2286. ||
  2287.  
  2288. Comparison Functions 
  2289.  
  2290. The following table lists all of the comparison functions provided by standard 
  2291. CLIPS. 
  2292.  
  2293. !=
  2294. <
  2295. <=
  2296. =
  2297. >
  2298. >=
  2299. eq
  2300. neq
  2301.  
  2302. Math Functions 
  2303.  
  2304. The following table lists all of the math functions provided by standard CLIPS. 
  2305.  
  2306. *
  2307. +
  2308. -
  2309. /
  2310.  
  2311. On-line Help functions (Not used in PMCLIPS) 
  2312.  
  2313. The following table list the functions available when the on-line help option 
  2314. is used. 
  2315.  
  2316. help
  2317. help-path
  2318.  
  2319. Text Processing functions (Not used in PMCLIPS) 
  2320.  
  2321. The following table list the functions available when either the text 
  2322. processing or the on-line help option is used. 
  2323.  
  2324. fetch
  2325. print-region
  2326. toss
  2327.  
  2328. Extended Math functions 
  2329.  
  2330. The following table list the functions available when the extended math option 
  2331. is used. 
  2332.  
  2333. **
  2334. abs         deg-rad
  2335. acos        exp
  2336. acosh       grad-deg
  2337. acot        integerp
  2338. acoth       log
  2339. acsch       log10
  2340. asec        max
  2341. asech       min
  2342. asin        mod
  2343. asinh       pi
  2344. atan        rad-deg
  2345. atanh       sec
  2346. cos         sech
  2347. cosh        sin
  2348. cot         sinh
  2349. coth        sqrt
  2350. csc         tan
  2351. csch        tanh
  2352. deg-grad    trunc
  2353.  
  2354. Internal functions 
  2355.  
  2356. These functions are used internally by CLIPS.  They can be called from the top 
  2357. level, but would not be useful to most applications. 
  2358.  
  2359. do-nothing
  2360. progn
  2361. show-pn
  2362. slow-assert
  2363.  
  2364.  
  2365. ΓòÉΓòÉΓòÉ 9.2. INTEGRATED_EDITOR ΓòÉΓòÉΓòÉ
  2366.  
  2367. Appendix B - Integrated Editor (Not yet available in PMCLIPS) 
  2368.  
  2369. CLIPS includes a fully integrated version of the full screen MicroEMACS editor. 
  2370. You may call the editor from CLIPS, compile full buffers or just sections of 
  2371. the editor (incremental compile), temporarily exit the editor back to CLIPS, or 
  2372. permanently exit the editor.  Since the editor is full screen, portions of it 
  2373. are highly machine dependent.  As it is currently set up, the editor will run 
  2374. on VAX VMS machines using VT100/VT240-compatible terminals, UNIX systems which 
  2375. support TERMCAP, the IBM PC, and most IBM compatibles. 
  2376.  
  2377. The editor may be called from CLIPS with the following command:    (edit 
  2378. ["<file-name>"]) 
  2379.  
  2380. The file name is optional.  If one is given, that file would be loaded.  If no 
  2381. file name is given, the editor is entered without loading a file.  Once in the 
  2382. file, all of the EMACS commands listed below are applicable.  To exit the 
  2383. editor and clear all buffers, use <Ctrl-Z> or <Ctrl-X><Ctrl-C>.  To temporarily 
  2384. exit the editor and retain the information in the buffers, use <Ctrl-X> Q.  To 
  2385. compile a rules section, mark a region and type <Ctrl-X><Ctrl-T>.  To compile 
  2386. the entire buffer, use <Meta-T>.  The editor can use extensive amounts of 
  2387. memory and a flag is available in clips.h to remove all of the editor code. 
  2388.  
  2389. When using the editor on multiuser machines like the VAX or many UNIX 
  2390. environments, be careful with the control S and control Q commands; they could 
  2391. conflict with terminal XON/XOFF communications.  All of the control S commands 
  2392. have a work around built into the editor.  The save file command, normally 
  2393. <Ctrl-X><Ctrl-S>, is also <Meta> Z.  The forward search command, normally 
  2394. <Ctrl-S>, is also <Meta> J.  The control Q command is rarely needed in a CLIPS 
  2395. file and, therefore, has no substitute. 
  2396.  
  2397. Control Commands
  2398.  <ctrl-@> Set mark at current position.
  2399.  <ctrl-A> Move cursor to beginning of line.
  2400.  <ctrl-B> Move cursor BACK one character.
  2401.  <ctrl-C> Start a new interactive command shell.  Be careful!
  2402.  <ctrl-D> DELETE character under cursor.
  2403.  <ctrl-E> Move cursor to END of line.
  2404.  <ctrl-F> Move cursor FORWARD one character.
  2405.  <ctrl-G> Abort any command.
  2406.  <ctrl-H> (backspace) delete previous character.
  2407.  <ctrl-I> Insert a TAB.
  2408.  <ctrl-J> Insert a CR-LF and indent next line.
  2409.  <ctrl-K> KILL (delete) to end of line.
  2410.  <ctrl-L> Redisplay screen.
  2411.  <ctrl-M> Insert a CR-LF.
  2412.  <ctrl-N> Move cursor to NEXT line.
  2413.  <ctrl-O> OPEN a new line.
  2414.  <ctrl-P> Move to PREVIOUS line.
  2415.  <ctrl-Q> QUOTE the next character (insert next character typed).
  2416.  <ctrl-R> Reverse SEARCH.
  2417.  <ctrl-S> Forward SEARCH (also <Meta-J>).
  2418.  <ctrl-T> TRANSPOSE characters.
  2419.  <ctrl-U> Enter repeat count for next command.
  2420.  <ctrl-V> VIEW the next screen (scroll up one screen).
  2421.  <ctrl-W> KILL region (all text between cursor and last mark set).
  2422.  <ctrl-X> Extended command prefix - see below.
  2423.  <ctrl-Y> YANK (undelete) last text killed.
  2424.  <ctrl-Z> Quick save of file in current buffer (only) and exit.
  2425.  
  2426. Extended (Control-X) Commands
  2427.  <ctrl-X>( Begin keyboard Macro.
  2428.  <ctrl-X>) End keyboard Macro.
  2429.  <ctrl-X>! Execute a single external command.
  2430.  <ctrl-X>= Show current cursor column and line number.
  2431.  <ctrl-X>: Go to a specific line number.
  2432.  <ctrl-X>1 Display current window only.
  2433.  <ctrl-X>2 Split the current window.
  2434.  <ctrl-X>B Switch to a different BUFFER.
  2435.  <ctrl-X>E EXECUTE keyboard Macro.
  2436.  <ctrl-X>F Set FILL column.
  2437.  <ctrl-X>K KILL a buffer (other than current buffer).
  2438.  <ctrl-X>M MATCH parenthesis (or {} or []).
  2439.  <ctrl-X>N Move to NEXT window.
  2440.  <ctrl-X>P Move to PREVIOUS window.
  2441.  <ctrl-X>R Global search and REPLACE (backwards).
  2442.  <ctrl-X>S Global SEARCH and replace (forwards).
  2443.  <ctrl-X>Z Enlarge current window by repeat count <ctrl-U> lines.
  2444.  
  2445.  <ctrl-X><ctrl-B> Show active BUFFERS.
  2446.  <ctrl-X><ctrl-C> Exit without saving buffers.
  2447.  <ctrl-X><ctrl-F> FIND file.  Load if not already in buffer.
  2448.  <ctrl-X><ctrl-N> Scroll current window up by repeat count lines.
  2449.  <ctrl-X><ctrl-P> Scroll current window down by repeat count lines.
  2450.  <ctrl-X><ctrl-R> RENAME file.  Change file name for buffer.
  2451.  <ctrl-X><ctrl-S> SAVE (write) current buffer into its file.
  2452.  <ctrl-X><ctrl-V> VISIT file.  Read file and display in current window.
  2453.  <ctrl-X><ctrl-W> WRITE buffer to file.  Option to change name of file.
  2454.  <ctrl-X><ctrl-Z> Reduce current window by repeat count lines.
  2455.  
  2456. Special characters
  2457.  <del> Delete previous character.
  2458.        (also <ctrl-H> on some terminals)
  2459.  <esc> Meta command prefix.
  2460.        (also <ctrl-[> on some terminals)
  2461.  
  2462. Meta Commands  (Activated by <esc> or <ctrl-[>)
  2463.  <meta>!                Move current line to repeat count lines from top of
  2464.                         window.
  2465.  <meta>> Move cursor to end of buffer.
  2466.  <meta>< Move cursor to beginning of buffer.
  2467.  <meta>. Set mark.
  2468.  <meta>B Move cursor BACK one word.
  2469.  <meta>C CAPITALIZE first letter of word.
  2470.  <meta>D DELETE next word.
  2471.  <meta>F Move cursor FORWARD one word.
  2472.  <meta>J SEARCH forward (same as <ctrl-S>).
  2473.  <meta>L LOWERCASE (lowercase) next word.
  2474.  <meta>R Query search and REPLACE (backwards).
  2475.  <meta>S Query SEARCH and replace (forwards).
  2476.  <meta>U UPPERCASE (uppercase) next word.
  2477.  <meta>V VIEW the previous screen (scroll down one screen).
  2478.  <meta>W COPY region into kill buffer.
  2479.  <meta>Z SAVE current buffer into file (same as
  2480.              <ctrl-X><ctrl-S>).
  2481.  <meta><del> DELETE previous word.
  2482.  
  2483.  
  2484. ΓòÉΓòÉΓòÉ 9.3. SUPPORT_INFORMATION ΓòÉΓòÉΓòÉ
  2485.  
  2486. Appendix E - Support Information 
  2487.  
  2488. PMCLIPS (The GUI Front-End) is a product of Oregon Expert Systems.  Bug 
  2489. reports, enhancement, or other requests may be mailed to: 
  2490.  
  2491.         Oregon Expert Systems
  2492.         6360 COrvallis Rd.
  2493.         Independence, Oregon  97361
  2494. I have not yet (as of July, 1990) decided upon distribution or marketing of 
  2495. this product, so I am currently releasing this BETA VERSION for free 
  2496. distribution.  Oregon Expert Systems however reserves all rights to this 
  2497. product.  It is released with OUT ANY WARANTY implied or otherwise. 
  2498.  
  2499. CLIPS is available through the Computer Software Management and Information 
  2500. Center (COSMIC), the distribution point for NASA software.  The program number 
  2501. is MSC-21208.  The program price is $2OO.OO, and the documentation price is 
  2502. $54.OO (as of September 1987).  The program price is for the source code (at 
  2503. the current time, this does not include PMCLIPS, the OS/2 front end). Further 
  2504. information can be obtained from 
  2505.  
  2506.         COSMIC
  2507.         382 E. Broad St.
  2508.         Athens, GA  30602
  2509.         (404) 542-3265
  2510.  
  2511. If you have problems using or installing CLIPS, a CLIPS Help Line is available 
  2512. from 8:OO a.m.  to 5:OO p.m.  (Central Standard Time).  The number is (713) 
  2513. 280-2233.  Leave your name and number and a support person will get back to 
  2514. you.