Download CLIPS User's Guide 6
Transcript
— 39 — Chapter 4 Variable Interests Nothing changes more than change The type of rules that you've seen so far illustrates simple matching of patterns to facts. In this chapter, you'll learn very powerful ways to match and manipulate facts. Let's Get Variable Just as with other programming languages, CLIPS has variables to store values. Unlike a fact, which is static or unchanging, the contents of a variable are dynamic as the values assigned to it change. In contrast, once a fact is asserted, it's fields can only be modified by retracting and asserting a new fact with the changed fields, Even the modify action (described later in the chapter on deftemplate) acts by retracting and asserting a modified fact, as you can see by checking the fact-index. The name of a variable, or variable identifier, is always written by a question mark followed by a symbol that is the name of the variable. The general format is ?<variable-name> Global variables, to be described in more detail later, have a slightly different syntax. Just as in other programming languages, variable names should be meaningful for good style. Some examples of valid variable names follow. ?x ?sensor ?noun ?valve ?color ?ducks-eaten Before a variable can be used, it should be assigned a value. As an example of a case where a value is not assigned, try to enter the following and CLIPS will respond with the error message shown.