CLIPS-返回字段约束

一、

1、使用=表示返回字段约束,如(numberjudge (name ?name) (modnumber =(mod?number 2)))中(modnumber =(mod ?number2))表示modnumber字段的值等于?number被2除的余数。

2、下面完成判断一个数是奇数还是偶数的功能。

二、操作

CLIPS> (clear)
CLIPS> (reset)
CLIPS> (deftemplate numberjudge
(slot name) (slot modnumber)
)
CLIPS> (deffacts numbers (numberjudge(name "evennumber")(modnumber 0))
(numberjudge(name "odd number")(modnumber 1))
)
CLIPS>

(defrule number-input
=>
(printout t "input a number:")
(bind ?number (read))
(assert (input-number ?number)))
CLIPS> (defrule number-judge
?inputnum<-(input-number ?number)
(numberjudge (name ?name) (modnumber =(mod ?number 2)))
=>
(retract ?inputnum)
(printout t ?number " is " ?name crlf)
)
CLIPS> (reset)
CLIPS> (facts)
f-0(initial-fact)
f-1(numberjudge (name "even number") (modnumber 0))
f-2(numberjudge (name "odd number") (modnumber 1))
For a total of 3 facts.
CLIPS> (run)
input a number:90
90 is even number
CLIPS> (reset)
CLIPS> (run)
input a number:99
99 is odd number
CLIPS>

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