本文介绍了CLIPS常数编译器指令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
类似于C中常量的编译器指令,有什么办法可以在CLIPS中执行以下操作?
Similar to the compiler directive for constants in C, is there a way I can do the following in CLIPS?
#define INFINITY 1000000000
(deftemplate foo
(slot num (type INTEGER) (default INFINITY))
)
...
(defrule bar
(foo (num INFINITY))
=>
...
)
推荐答案
您可以定义全局变量并将其视为常量:
You can define a global variable and treat it as a constant:
CLIPS> (defglobal ?*INFINITY* = 1000000000)
CLIPS>
(deftemplate foo
(slot num (type INTEGER) (default ?*INFINITY*)))
CLIPS>
(defrule bar
(foo (num ?num&:(eq ?num ?*INFINITY*)))
=>)
CLIPS> (assert (foo))
<Fact-1>
CLIPS> (facts)
f-0 (initial-fact)
f-1 (foo (num 1000000000))
For a total of 2 facts.
CLIPS> (agenda)
0 bar: f-1
For a total of 1 activation.
CLIPS>
这篇关于CLIPS常数编译器指令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!