Reputation: 701
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.
Upvotes: 0
Views: 1129
Reputation: 10757
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))
)
Upvotes: 1