如何使用 deftemplate 将结果存储在 CLIPS 中?

发布于 2024-12-20 23:15:18 字数 1120 浏览 2 评论 0原文

我试图构建一个模板来存储我计算的一些结果,所以我做了这个初始化:

(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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

淡淡の花香 2024-12-27 23:15:18

通读用户指南会很有帮助,因为它涵盖了基本语法。我纠正了你的一些错误:

(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))
    )   
    ; (/ )  What's this for?  
    (modify ?tmpA (nota-media-total (/ ?suma ?i)))
    (assert (calcula-nota-media ok))
)

Reading through the User's Guide would be helpful as it covers the basic syntax. I've corrected some of your errors:

(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))
    )   
    ; (/ )  What's this for?  
    (modify ?tmpA (nota-media-total (/ ?suma ?i)))
    (assert (calcula-nota-media ok))
)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文