CLIPS constant compiler directive

≯℡__Kan透↙ 提交于 2019-12-25 00:37:52

问题


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))
    =>
    ...
)

回答1:


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> 


来源:https://stackoverflow.com/questions/23118807/clips-constant-compiler-directive

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!