0

类似于 C 中常量的编译器指令,有没有办法可以在 CLIPS 中执行以下操作?

#define INFINITY 1000000000

(deftemplate foo
    (slot num (type INTEGER) (default INFINITY))
)

...

(defrule bar
    (foo (num INFINITY))
    =>
    ...
)
4

1 回答 1

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> 
于 2014-04-18T16:57:55.877 回答