一、
1、指定非空:(default?NONE)
2、指定默认值动态获得: (default-dynamic (time))取得事实增加的时间
3、指定多字段槽的字段数目:(multislot name (cardinality 1 4)),指定为1-4个
4、指定类型,如(type INTEGER)指定为整形
5、指定字段范围:(range 18 ?VARIABLE) ?VARIABLE表示无上限
(range 0 100)表0-100内
6、指定字段允许值,如:(allowed-values male female)
7、(set-dynamic-constraint-checking TRUE)为指定动态约束检查,在打开此参数之后,
name:li jun
age:12
这种错误才能被动态检查到
[CSTRNCHK1] Slot value 12 found in factf-10
does not fall in the allowed range 18 to +oo for slot age.
[PRCCODE4] Execution halted during the actions of defruleinput-student.
8、
CLIPS> (run)
name:liu jun ju
age:24
f-4(student (addtime 229.65) (name liu) (age 29) (mark 0) (gendermale))
这种情况的发生是因为read只能读到第一个字段
9、
(defrule input-student
=>
(printout t "name:")
(bind $?name (readline))
(printout t "age:")
(bind ?age (read))
(assert (student (name $?name)(age ?age))))
readline把读入内容做为文本串做为一个字段
(run)
name:li hui
age:22
f-7(student (addtime 388.698) (name "li hui") (age 22) (mark 0)(gender male))
10、使用(bind ?name (explode$(readline)))中的explode$将文本串分成多个字段
二、
CLIPS (Quicksilver Beta 09/24/07)
CLIPS> (deftemplate student
(slot addtime (default-dynamic (time)))
(multislot name (cardinality 1 4))
(slot age (default ?NONE)(type INTEGER) (range 18 ?VARIABLE))
(slot mark (type INTEGER)(range 0 100))
(slot gender (allowed-values male female))
)
CLIPS> (assert (student (name hua jun)(age22)))
<Fact-1>
CLIPS> (assert (student (name hua jun)(age 12)))
[CSTRNCHK1] A literal slot value found in the assertcommand
does not fall in the allowed range 18 to +oo for slot age.
CLIPS> (assert (student (name liu hua jun jun)(age22)))
<Fact-2>
CLIPS> (assert (student (name liu hua jun hui )(age22)(mark 120)))
[CSTRNCHK1] A literal slot value found in the assertcommand
does not fall in the allowed range 0 to 100 for slot mark.
CLIPS> (assert (student (name liu hua jun jun hui)(age 22)))
[CSTRNCHK1] Literal slot values found in the assertcommand
does not satisfy the cardinality restrictions for slot name.
CLIPS> (assert (student (name liu hua jun hui )(age22)(mark 100)(gender male)))
<Fact-3>
CLIPS> (assert (student (name liu hua jun hui )(age22)(mark 100)(gender fffmale)))
[CSTRNCHK1] A literal slot value found in the assertcommand
does not match the allowed values for slot gender.
CLIPS> (assert (student (name liu hua hui )))
[TMPLTRHS1] Slot age requires a value because of its (default?NONE) attribute.
CLIPS> (facts)
f-0(initial-fact)
f-1(student (addtime 18.416) (name hua jun) (age 22) (mark 0) (gendermale))
f-2(student (addtime 46.677) (name liu hua jun jun) (age 22) (mark 0)(gender male))
f-3(student (addtime 78.653) (name liu hua jun hui) (age 22) (mark100) (gender male))
For a total of 4 facts.
CLIPS> (defrule input-student
=>
(printout t "name:")
(bind ?name (read))
(printout t "age:")
(bind ?age (read))
(assert (student (name ?name)(age ?age))))
CLIPS> (run)
name:liu hui ju
age:29
CLIPS> (facts)
f-0(initial-fact)
f-1(student (addtime 18.416) (name hua jun) (age 22) (mark 0) (gendermale))
f-2(student (addtime 46.677) (name liu hua jun jun) (age 22) (mark 0)(gender male))
f-3(student (addtime 78.653) (name liu hua jun hui) (age 22) (mark100) (gender male))
f-4(student (addtime 229.65) (name liu) (age 29) (mark 0) (gendermale))
For a total of 5 facts.
CLIPS> (undefrule input-student)
CLIPS> (defrule input-student
=>
(printout t "name:")
(bind $?name (read))
(printout t "age:")
(bind ?age (read))
(assert (student (name ?name)(age ?age))))
CLIPS> (run)
name:liu jun ju
age:24
CLIPS> (facts)
f-0(initial-fact)
f-1(student (addtime 18.416) (name hua jun) (age 22) (mark 0) (gendermale))
f-2(student (addtime 46.677) (name liu hua jun jun) (age 22) (mark 0)(gender male))
f-3(student (addtime 78.653) (name liu hua jun hui) (age 22) (mark100) (gender male))
f-4(student (addtime 229.65) (name liu) (age 29) (mark 0) (gendermale))
f-5(student (addtime 317.105) (name liu) (age 24) (mark 0) (gendermale))
For a total of 6 facts.
CLIPS> (undefrule input-student)
CLIPS> (defrule input-student
=>
(printout t "name:")
(bind $?name (read))
(printout t "age:")
(bind ?age (read))
(assert (student (name $?name)(age ?age))))
CLIPS> (run)
name:liu hu ju
age:24
CLIPS> (facts)
f-0(initial-fact)
f-1(student (addtime 18.416) (name hua jun) (age 22) (mark 0) (gendermale))
f-2(student (addtime 46.677) (name liu hua jun jun) (age 22) (mark 0)(gender male))
f-3(student (addtime 78.653) (name liu hua jun hui) (age 22) (mark100) (gender male))
f-4(student (addtime 229.65) (name liu) (age 29) (mark 0) (gendermale))
f-5(student (addtime 317.105) (name liu) (age 24) (mark 0) (gendermale))
f-6(student (addtime 352.096) (name liu) (age 24) (mark 0) (gendermale))
For a total of 7 facts.
CLIPS> (undefrule input-student)
CLIPS> (defrule input-student
=>
(printout t "name:")
(bind $?name (readline))
(printout t "age:")
(bind ?age (read))
(assert (student (name $?name)(age ?age))))
CLIPS> (run)
name:li hui
age:22
CLIPS> (facts)
f-0(initial-fact)
f-1(student (addtime 18.416) (name hua jun) (age 22) (mark 0) (gendermale))
f-2(student (addtime 46.677) (name liu hua jun jun) (age 22) (mark 0)(gender male))
f-3(student (addtime 78.653) (name liu hua jun hui) (age 22) (mark100) (gender male))
f-4(student (addtime 229.65) (name liu) (age 29) (mark 0) (gendermale))
f-5(student (addtime 317.105) (name liu) (age 24) (mark 0) (gendermale))
f-6(student (addtime 352.096) (name liu) (age 24) (mark 0) (gendermale))
f-7(student (addtime 388.698) (name "li hui") (age 22) (mark 0)(gender male))
For a total of 8 facts.
CLIPS> (undefrule input-student)
CLIPS> (defrule input-student
=>
(printout t "name:")
(bind ?name (explode$ (readline)))
(printout t "age:")
(bind ?age (read))
(assert (student (name ?name)(age ?age)))
)
CLIPS> (run)
name:liu li hua
age:27
CLIPS> (defrule input-student
=>
(printout t "name:")
(bind ?name (explode$ (readline)))
(printout t "age:")
(bind ?age (read))
(assert (student (name ?name)(age ?age)))
)
CLIPS> (defrule input-student
=>
(printout t "name:")
(bind ?name (explode$ (readline)))
(printout t "age:")
(bind ?age (read))
(assert (student (name ?name)(age ?age)))
)
CLIPS> (facts)
f-0(initial-fact)
f-1(student (addtime 18.416) (name hua jun) (age 22) (mark 0) (gendermale))
f-2(student (addtime 46.677) (name liu hua jun jun) (age 22) (mark 0)(gender male))
f-3(student (addtime 78.653) (name liu hua jun hui) (age 22) (mark100) (gender male))
f-4(student (addtime 229.65) (name liu) (age 29) (mark 0) (gendermale))
f-5(student (addtime 317.105) (name liu) (age 24) (mark 0) (gendermale))
f-6(student (addtime 352.096) (name liu) (age 24) (mark 0) (gendermale))
f-7(student (addtime 388.698) (name "li hui") (age 22) (mark 0)(gender male))
f-8(student (addtime 1237.889) (name liu li hua) (age 27) (mark 0)(gender male))
For a total of 9 facts.
CLIPS> (run)
name:li hui hui
age:12
CLIPS> (facts)
f-0(initial-fact)
f-1(student (addtime 18.416) (name hua jun) (age 22) (mark 0) (gendermale))
f-2(student (addtime 46.677) (name liu hua jun jun) (age 22) (mark 0)(gender male))
f-3(student (addtime 78.653) (name liu hua jun hui) (age 22) (mark100) (gender male))
f-4(student (addtime 229.65) (name liu) (age 29) (mark 0) (gendermale))
f-5(student (addtime 317.105) (name liu) (age 24) (mark 0) (gendermale))
f-6(student (addtime 352.096) (name liu) (age 24) (mark 0) (gendermale))
f-7(student (addtime 388.698) (name "li hui") (age 22) (mark 0)(gender male))
f-8(student (addtime 1237.889) (name liu li hua) (age 27) (mark 0)(gender male))
f-9(student (addtime 1265.579) (name li hui hui) (age 12) (mark 0)(gender male))
For a total of 10 facts.
CLIPS> (retract 9)
CLIPS> (set-dynamic-constraint-checking TRUE)
FALSE
CLIPS> (run)
CLIPS> (agenda)
CLIPS> (refresh input-student)
CLIPS> (run)
name:li jun
age:12
[CSTRNCHK1] Slot value 12 found in factf-10
does not fall in the allowed range 18 to +oo for slot age.
[PRCCODE4] Execution halted during the actions of defruleinput-student.
CLIPS>