如何使用 deftemplate 将结果存储在 CLIPS 中?
我试图构建一个模板来存储我计算的一些结果,所以我做了这个初始化:
(deftemplate tempAlumne
(slot nota-media-total)
(slot nota-media-obligatorias)
(slot nota-media-optativas)
(slot nota-media-ales)
)
(deffacts tempAlumneFacts
(tempAlumne
(nota-media-total -1)
(nota-media-obligatorias -1)
(nota-media-optativas -1)
(nota-media-ales -1)
)
)
然后我尝试使用该结构来存储值,但我需要它可以从许多规则访问,所以我决定将其推向全球。所以我尝试存储这样的值:
(defrule calcula-nota-media ""
(not calcula-nota-media ok)
?*tmpA* <- (tempAlumne )
=>
(bind ?llista_convocs (send ?*alumne* get-IConvocatoria))
(bind ?suma 0)
(bind ?i 0)
(while(< ?i (length$ ?llista_convocs)) do
(bind ?convoc_actual (nth$ ?i ?llista_convocs))
(bind ?suma (+ ?suma (send ?convoc_actual get-Nota)))
(bind ?i (+ ?i 1))
)
(/ )
(modify (?*tmpA* (nota-media-total (/ ?suma ?i))
(assert calcula-nota-media ok)
)
因为我希望 ?*tmpA* 具有初始值,然后为每个值分配修改(这里我分配 nota-media-total),但它说“[PRNTUTIL2] 语法错误:检查defrule 的适当语法。”,所以我不知道出了什么问题,或者我是否走错了路。
I was trying to build a template for storing some of the results I calculate, so I made this for initialization:
(deftemplate tempAlumne
(slot nota-media-total)
(slot nota-media-obligatorias)
(slot nota-media-optativas)
(slot nota-media-ales)
)
(deffacts tempAlumneFacts
(tempAlumne
(nota-media-total -1)
(nota-media-obligatorias -1)
(nota-media-optativas -1)
(nota-media-ales -1)
)
)
And then I'm trying to use that structure to store values, but I need it to be accesible from many rules, so I decided to make it global. So I tried to store values like this:
(defrule calcula-nota-media ""
(not calcula-nota-media ok)
?*tmpA* <- (tempAlumne )
=>
(bind ?llista_convocs (send ?*alumne* get-IConvocatoria))
(bind ?suma 0)
(bind ?i 0)
(while(< ?i (length$ ?llista_convocs)) do
(bind ?convoc_actual (nth$ ?i ?llista_convocs))
(bind ?suma (+ ?suma (send ?convoc_actual get-Nota)))
(bind ?i (+ ?i 1))
)
(/ )
(modify (?*tmpA* (nota-media-total (/ ?suma ?i))
(assert calcula-nota-media ok)
)
because I want ?*tmpA* to have the initial values and then assign each one with modify (here I assign nota-media-total), but it says "[PRNTUTIL2] Syntax Error: Check appropriate syntax for defrule.", so I don't know what is wrong or if I'm taking the wrong path.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通读用户指南会很有帮助,因为它涵盖了基本语法。我纠正了你的一些错误:
Reading through the User's Guide would be helpful as it covers the basic syntax. I've corrected some of your errors: