The following post provides instructions on installing and configuring CLIPS on Ubuntu, as well as a guide on basic syntax and commands in the CLIPS language.
The Use of CLIPS
C Language Integrated Production System (CLIPS) is a tool for creating expert systems, which are computer programs designed to model the reasoning and expertise of a human. CLIPS programs, unlike those of other programming languages such as C++ or Java, consist of a series of ‘rules’, which execute concurrently. Because of this, we can model human intelligence far more easily through CLIPS than we could through conventional languages.
Configuring CLIPS in Ubuntu
We can install the necessary packages for CLIPS using the following command in Ubuntu’s terminal:
$ sudo apt-get install clips
Necessary packages to install include clips
, clips-common
, libc6
, libclips
, and clips-doc
. For C++ interfacing later we will need to install the autoconf
, libtool
, libncurses5-dev
, build-essential
, libgtkmm-2.4-dev
, libxt-dev
, libxaw7-dev
, and libsigc++
packages.
Another way to install the latest CLIPS is from here.
Once these are installed we can execute the CLIPS shell by the command:
clip
We can then begin coding in CLIPS in the command shell. To exit CLIPS, simply type:
CLIPS> (exit)
The Structure of CLIPS
CLIPS uses a ‘shell’ to perform inferences and reasoning. This shell consists of 3 parts: the fact-list, which functions as a database; the knowledge-base, which contains all ‘rules’; and the inference engine, which controls the execution of rules. As mentioned previously, the inference engine processes rules concurrently, determining which rules to execute based on ‘salience’ in an attempt to model human reasoning.
In the typical CLIPS program, the user enters a series of commands which insert rules and facts into the CLIPS system. Once done, the user enters the (run) command, which tells the shell to start processing the user’s entered command.
Coding in CLIPS – Getting Started
For a more detailed guide on CLIPS, please visit http://clipsrules.sourceforge.net/documentation/v630/ug.pdf.
CLIPS follows similar syntax to that of Lisp, where commands are surrounded by parenthesis. In addition, CLIPS uses prefix notation. This means that all CLIPS commands follow the following format:
(<command> <argument 1> <argument 2> ... <argument n>)
Note that arguments can themselves be commands, so CLIPS code can contain nested parenthesis.
A few commands include:
- (facts) – displays the fact-list
- (assert (<fact>)) – adds a fact to the fact-list
- (retract <index>) – removes the fact with the given index from the fact-list
- (clear)
- (exit)
- (reset)
- (watch facts)
- ; – a semicolon marks a comment in CLIPS.
In addition, we can define a rule like this:
(defrule () () ... () => () () ... ())
Example Code
The following code takes in as input an integer N, and prints the integers 1 through N:
CLIPS> (defrule foo1 => (assert (stop (read))) (assert (count 0))) CLIPS> (defrule foo2 ?stop-mem <- (stop ?stop-val) ?count-mem <- (count ?count-val&~?stop-val) => (retract ?count-mem) (printout t "Count: " (+ ?count-val 1) crlf) (assert (count (+ ?count-val 1)))) CLIPS> (run) 4 Count: 1 Count: 2 Count: 3 Count: 4 CLIPS>
Note that this code covers content not covered in this post, such as pattern matching syntax and defining variables. Again, for more detailed instruction the previously mentioned link should be consulted.