CLIPS-变量

一、

1、变量声明方式为?加变量名,如?name

2、一个变量首次约束于某一值时,该变量在此规则内使保持该值。其他同名的变量必须约束为第一个变量的值,如下面操作中的?eyes

3、在LHS(前件)没有约束,但在RHS引用,将会报错。

4、下列例子查找所有眼睛为蓝色的人。CLIPS (Quicksilver Beta 09/24/07)
CLIPS> (clear)
CLIPS> (reset)
CLIPS> (deftemplate find (slot eye))
CLIPS> (deftemplate person(slot name)(sloteye))
CLIPS> (defrule findeye
(find (eye ?eyes))
(person (name ?name)(eye ?eyes))
=>
(printout t ?name " has" ?eyes " eyes." crlf)
)
CLIPS> (save "D:\VV.CLP")
TRUE
CLIPS> (run)
CLIPS> (agenda)
CLIPS> (facts)
f-0(initial-fact)
For a total of 1 fact.
CLIPS> (assert (person (name "zhangsan") (eyeblue))
(person (name "zhanghua") (eye blue))
(person (name "zhengyu") ( eye black)))
<Fact-3>
CLIPS> (facts)
f-0(initial-fact)
f-1(person (name "zhangsan") (eye blue))
f-2(person (name "zhanghua") (eye blue))
f-3(person (name "zhengyu") (eye black))
For a total of 4 facts.
CLIPS> (assert (find (eye blue)))
<Fact-4>
CLIPS> (facts)
f-0(initial-fact)
f-1(person (name "zhangsan") (eye blue))
f-2(person (name "zhanghua") (eye blue))
f-3(person (name "zhengyu") (eye black))
f-4(find (eye blue))
For a total of 5 facts.
CLIPS> (agenda)
0findeye: f-4,f-2
0findeye: f-4,f-1
For a total of 2 activations.
CLIPS> (run)
zhanghua has blue eyes.
zhangsan has blue eyes.

二、操作

CLIPS (Quicksilver Beta 09/24/07)
CLIPS> (clear)
CLIPS> (reset)
CLIPS> (deftemplate find (slot eye))
CLIPS> (defrule findeye
(find eye ?eyes)
(person (name ?name)(eyes ?eyes))
=>
(printout t ?name "has" ?eyes "eyes." crlf)
)

[PRNTUTIL2] Syntax Error: Check appropriatesyntax for deftemplate patterns.

ERROR:
(defrule MAIN::findeye
(find eye
CLIPS> (defrule findeye
(find (eye ?eyes))
(person (name ?name)(eyes ?eyes))
=>
(printout t ?name "has" ?eyes "eyes." crlf)
)

[PRNTUTIL2] Syntax Error: Check appropriatesyntax for defrule.

ERROR:
(defrule MAIN::findeye
(find (eye ?eyes))
(person (
CLIPS> (deftemplate person(slot name)(sloteye))
CLIPS> (defrule findeye
(find (eye ?eyes))
(person (name ?name)(eyes ?eyes))
=>
(printout t ?name "has" ?eyes "eyes." crlf)
)

[TMPLTDEF1] Invalid slot eyes not defined in correspondingdeftemplate person.

ERROR:
(defrule MAIN::findeye
(find (eye ?eyes))
(person (name ?name)(eyes
CLIPS> (defrule findeye
(find (eye ?eyes))
(person (name ?name)(eye ?eyes))
=>
(printout t ?name "has" ?eyes "eyes." crlf)
)
CLIPS> (save "D:\VV.CLP")
TRUE
CLIPS> (run)
CLIPS> (agenda)
CLIPS> (facts)
f-0(initial-fact)
For a total of 1 fact.
CLIPS> (assert person (name "zhangsan" eyeblue)
person (name "zhanghua" eye blue)
person (name "zhengyu" eye black))

[PRNTUTIL2] Syntax Error: Check appropriatesyntax for RHS patterns.
CLIPS> (assert (person (name "zhangsan") (eyeblue))
(person (name "zhanghua") (eye blue))
(person (name "zhengyu") ( eye black)))
<Fact-3>
CLIPS> (facts)
f-0(initial-fact)
f-1(person (name "zhangsan") (eye blue))
f-2(person (name "zhanghua") (eye blue))
f-3(person (name "zhengyu") (eye black))
For a total of 4 facts.
CLIPS> (assert find (eye blue))

[PRNTUTIL2] Syntax Error: Check appropriatesyntax for RHS patterns.
CLIPS> (assert (find (eye blue)))
<Fact-4>
CLIPS> (facts)
f-0(initial-fact)
f-1(person (name "zhangsan") (eye blue))
f-2(person (name "zhanghua") (eye blue))
f-3(person (name "zhengyu") (eye black))
f-4(find (eye blue))
For a total of 5 facts.
CLIPS> (agenda)
0findeye: f-4,f-2
0findeye: f-4,f-1
For a total of 2 activations.
CLIPS> (run)
zhanghuahasblueeyes.
zhangsanhasblueeyes.

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