专家系统-CLIPS-事实的增加与删除

一、说明

1、(facts)为查看事实

2、(deftemplate person
(slot name)
.....)

为定义自定义模板,slot表示槽,person为一个自定义结构

3、(assert (person
(name "zhanghua")
(age 25)
(eye-color blue)
(hair-color red) ) )
增加person结构的事实

4、 (assert (person
(name "zhouhua")
(age 65)
(eye-color blue)
(hair-color red) )
(person
(name "liujun")
(age 45)
(eye-color black)
(hair-color black) ) )
可以同时增加2个或多个事实

5、(retract 2 )为删除事实,可同时删除多个事实(retract 3 5)

6、重复的事实不能反复增加

二、操作

CLIPS (Quicksilver Beta09/24/07)
CLIPS> (facts)
f-0(initial-fact)
For a total of 1 fact.
CLIPS> (deftemplate person
(slot name)
(slot age)
(slot eye-color)
(slot hair-color))
CLIPS> (assert (person
(name "zhangsan")
(age 25)
(eye-color blue)
(hair-color black) ) )

CLIPS> (assert (person
(name "zhanghua")
(age 25)
(eye-color blue)
(hair-color red) ) )

CLIPS> (assert (person
(name "zhanghua")
(age 25)
(eye-color blue)
(hair-color red) )
(person
(name "zhouhui")
(age 45)
(eye-color black)
(hair-color black) ) )

CLIPS> (facts)
f-0(initial-fact)
f-1(person (name "zhangsan") (age 25) (eye-color blue) (hair-colorblack))
f-2(person (name "zhanghua") (age 25) (eye-color blue) (hair-colorred))
f-3(person (name "zhouhui") (age 45) (eye-color black) (hair-colorblack))
For a total of 4 facts.
CLIPS> (assert (person
(name "zhouhua")
(age 65)
(eye-color blue)
(hair-color red) )
(person
(name "liujun")
(age 45)
(eye-color black)
(hair-color black) ) )

CLIPS> (facts)
f-0(initial-fact)
f-1(person (name "zhangsan") (age 25) (eye-color blue) (hair-colorblack))
f-2(person (name "zhanghua") (age 25) (eye-color blue) (hair-colorred))
f-3(person (name "zhouhui") (age 45) (eye-color black) (hair-colorblack))
f-4(person (name "zhouhua") (age 65) (eye-color blue) (hair-colorred))
f-5(person (name "liujun") (age 45) (eye-color black) (hair-colorblack))
For a total of 6 facts

CLIPS> (retract 2 )
CLIPS> (facts)
f-0(initial-fact)
f-1(person (name "zhangsan") (age 25) (eye-color blue) (hair-colorblack))
f-3(person (name "zhouhui") (age 45) (eye-color black) (hair-colorblack))
f-4(person (name "zhouhua") (age 65) (eye-color blue) (hair-colorred))
f-5(person (name "liujun") (age 45) (eye-color black) (hair-colorblack))
For a total of 5 facts.
CLIPS> (retract 3 5)
CLIPS> (facts)
f-0(initial-fact)
f-1(person (name "zhangsan") (age 25) (eye-color blue) (hair-colorblack))
f-4(person (name "zhouhua") (age 65) (eye-color blue) (hair-colorred))
For a total of 3 facts.
CLIPS>

你可能感兴趣的:(F#)