CLIPS 常量编译器指令
Posted
技术标签:
【中文标题】CLIPS 常量编译器指令【英文标题】:CLIPS constant compiler directive 【发布时间】:2014-04-16 19:47:15 【问题描述】:类似于 C 中常量的编译器指令,有没有办法可以在 CLIPS 中执行以下操作?
#define INFINITY 1000000000
(deftemplate foo
(slot num (type INTEGER) (default INFINITY))
)
...
(defrule bar
(foo (num INFINITY))
=>
...
)
【问题讨论】:
【参考方案1】:您可以定义一个全局变量并将其视为常量:
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 常量编译器指令的主要内容,如果未能解决你的问题,请参考以下文章