next up previous

2.3.1 Data Types

CLIPS provides eight primitive data types for representing information. These types are float, integer, symbol, string, externaladdress, factaddress, instancename and instanceaddress. Numeric information can be represented using floats and integers. Symbolic information can be represented using symbols and strings.

A number consists only of digits (09), a decimal point (.), a sign (+ or ), and, optionally, an (e) for exponential notation with its corresponding sign. A number is either stored as a float or an integer. Any number consisting of an optional sign followed by only digits is stored as an integer (represented internally by CLIPS as a C long integer). All other numbers are stored as floats (represented internally by CLIPS as a C doubleprecision float). The number of significant digits will depend on the machine implementation. Roundoff errors also may occur, again depending on the machine implementation. As with any computer language, care should be taken when comparing floatingpoint values to each other or comparing integers to floatingpoint values. Some examples of integers are

237	15	+12	-32

Some examples of floats are

237e3	15.09	+12.0	-32.3e-7

Specifically, integers use the following format:

<integer> ::= [+ | -] <digit>+
<digit> ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9

Floating point numbers use the following format:

<float> ::= <integer> <exponent> |
            <integer> . [exponent]
            . <unsigned integer> [exponent]
            <integer> . <unsigned integer> [exponent]
<unsigned-integer> ::= <digit>+
<exponent> ::= e | E <integer>

A sequence of characters which does not exactly follow the format of a number is treated as a symbol (see the next paragraph).

A symbol in CLIPS is any sequence of characters that starts with any printable ASCII character and is followed by zero or more printable ASCII characters. When a delimiter is found, the symbol is ended. The following characters act as delimiters: any nonprintable ASCII character (including spaces, tabs, carriage returns, and line feeds), a double quote, opening and closing parentheses ì(î and ì)î, an ampersand ì&î, a vertical bar ì|î, a less than ì<î, and a tilde ì~î. A semicolon ì;î starts a CLIPS comment (see section 2.3.3) and also acts as a delimiter. Delimiters may not be included in symbols with the exception of the ì<ì character which may be the first character in a symbol. In addition, a symbol may not begin with either the ì?î character or the ì$?î sequence of characters (although a symbol may contain these characters). These characters are reserved for variables (which are discussed later in this section). CLIPS is case sensitive (i.e. uppercase letters will match only uppercase letters). Note that numbers are a special case of symbols (i.e. they satisfy the definition of a symbol, but they are treated as a different data type). Some simple examples of symbols are

foo	Hello	B76-HI	bad_value
127A	456-93-039	@+=-%	2each

A string is a set of characters that starts with a double quote (") and is followed by zero or more printable characters. A string ends with double quotes. Double quotes may be embedded within a string by placing a backslash (\) in front of the character. A backslash may be embedded by placing two consecutive backslash characters in the string. Some examples are

"foo"	"a and b"	"1 number"	"a\"quote"

Note that the string ìabcd" is not the same as the symbol abcd. They both contain the same characters, but are of different types. The same holds true for the instance name [abcd].

An externaladdress is the address of an external data structure returned by a function (written in a language such as C or Ada) that has been integrated with CLIPS. This data type can only be created by calling a function (i.e. it is not possible to specify an externaladdress by typing the value). In the basic version of CLIPS (which has no user defined external functions), it is not possible to create this data type. Externaladdresses are discussed in further detail in the Advanced Programming Guide. Within CLIPS, the printed representation of an externaladdress is

<Pointer-XXXXXX>

where XXXXXX is the externaladdress.

A fact is a list of atomic values that are either referenced positionally (ordered facts) or by name (nonordered or template facts). Facts are referred to by index or address; section 2.4.1 gives more details. The printed format of a factaddress is:

<Fact-XXX>

where XXX is the factindex.

An instance is an object that is an instantiation or specific example of a class. Objects in CLIPS are defined to be floats, integers, symbols, strings, multifield values, externaladdresses, factaddresses or instances of a userdefined class. A class is created using the defclass construct. An instance of a userdefined class is created with the makeinstance function, and such an instance can be referred to uniquely by address. Within the scope of a module (see section 10.5.1), an instance can also be uniquely referred to by name. All of these definitions will be covered in more detail in Sections 2.4.2, 2.5.2.3, 2.6 and 9. An instancename is formed by enclosing a symbol within left and right brackets. Thus, pure symbols may not be surrounded by brackets. If the CLIPS Object Oriented Language (COOL) is not included in a particular CLIPS configuration, then brackets may be wrapped around symbols. Some examples of instancenames are:

[pump-1]	[foo]	[+++]	[123-890]

Note that the brackets are not part of the name of the instance; they merely indicate that the enclosed symbol is an instancename. An instanceaddress can only be obtained by binding the return value of a function called instanceaddress or by binding a variable to an instance matching an object pattern on the LHS of a rule (i.e., it is not possible to specify an instanceaddress by typing the value). A to an instance of a userdefined class can either be by name or address; instanceaddresses should only be used when speed is critical. Within CLIPS, the printed representation of an instanceaddress is

<Instance-XXX>

where XXX is the name of the instance.

In CLIPS, a placeholder that has a value (one of the primitive data types) is referred to as a field. The primitive data types are referred to as singlefield values. A constant is a nonvarying single field value directly expressed as a series of characters (which means that externaladdresses, factaddresses and instanceaddresses cannot be expressed as constants because they can only be obtained through function calls and variable bindings). A multifield value is a sequence of zero or more single field values. When displayed by CLIPS, multifield values are enclosed in parentheses. Collectively, single and multifield values are referred to as values. Some examples of multifield values are

(a)	(1 bar foo)	()	(x 3.0 "red" 567)

Note that the multifield value (a) is not the same as the single field value a. Multifield values are created either by calling functions which return multifield values, by using wildcard arguments in a deffunction, object messagehandler, or method, or by binding variables during the patternmatching process for rules. In CLIPS, a variable is a symbolic location that is used to store values. Variables are used by many of the CLIPS constructs (such as defrule, deffunction, defmethod, and defmessagehandler) and their usage is explained in the sections describing each of these constructs.


next up previous