剪辑对我来说是很新的--我已经试着深入挖掘这门语言2天了。一个问题浮现在我的脑海中,即:如何(如果可能的话)动态地创建/添加新规则?例如,我想做这样的事情:
(deftemplate action
(slot prev)
(slot curr)
)
(defrule test
(action (prev ?p))
=>
(defrule test_inner
(action (curr ?p))
=>
(printout t "Result of a newly created rule.")
)
)请不要特别注意这些规则的逻辑--这只是一个例子。调用上述命令后,我将收到以下命令:
[EXPRNPSR3] Missing function declaration for defrule.
ERROR:
(defrule MAIN::test
(action (prev ?p))
=>
(defrule这个错误,是命令语法的问题,还是我不能“动态”定义新规则?
发布于 2013-11-10 17:42:09
首先创建包含规则(或任何其他构造)的字符串,然后使用build函数:
CLIPS>
(deftemplate action
(slot prev)
(slot curr)
)
CLIPS>
(defrule test
(action (prev ?p))
=>
(build (str-cat
"(defrule test_inner
(action (curr " ?p "))
=>
(printout t \"Result of a newly created rule.\")
)"
)
)
)
CLIPS> (reset)
CLIPS> (assert (action (prev move)))
<Fact-1>
CLIPS> (agenda)
0 test: f-1
For a total of 1 activation.
CLIPS> (run)
CLIPS> (rules)
test
test_inner
For a total of 2 defrules.
CLIPS> (ppdefrule test_inner)
(defrule MAIN::test_inner
(action (curr move))
=>
(printout t "Result of a newly created rule."))
CLIPS> https://stackoverflow.com/questions/19888074
复制相似问题