Dinossssssssssss
Dinossssssssssss

Reputation: 1

I need help comparing numbers in defrule with multislot objects in CLIPS

I have the following code

(deftemplate choice-evaluation
(slot x_front)
(slot y_left)



(deftemplate es_result
(slot classp)
(slot classr)
(slot nr) )

(defrule MAIN::one
    (x_front ?val)
    (bind ?temp 1)
    (choice-evaluation(y_left -1) (test (<= ?val ?temp ))(class ?x))
?c<-(choice-evaluation(y_left -1) (test(<= ?val ?temp ))(class ?x))
=>
(assert (es_result (classp 0) (classr ?x) (nr 1)))
(retract ?c))  

and I get the error : ERROR: (defrule MAIN::one (x_front ?val) (choice-evaluation (y_left -1) (test

I have tried a lot of things but I will always either get the error above or syntax error for defrules . I do not understand how I can have a comparison in defrules with multislot objects.

I tried creating a rule like the examples here :https://www.csie.ntu.edu.tw/~sylee/courses/clips/advpattern.htm and they do work but it doesnt work for my particular case.

Upvotes: 0

Views: 236

Answers (2)

Dinossssssssssss
Dinossssssssssss

Reputation: 1

@Gary Riley thanks for your input it helped a lot!

    (choice-evaluation (x_front ?val) (y_left -1) (class ?x))
               (test (<= ?val 1 ))
              ?c <- (choice-evaluation (x_front ?val) (y_left -1) (class ?x))
=>
(assert (es_result (classp 0) (classr ?x) (nr 1)))
(retract ?c))

So turns out this is how it is supposed to be used. Leaving it here in case someone else in the future has a similar problem credits : I. Xatziligeroudis

Upvotes: 0

Gary Riley
Gary Riley

Reputation: 10757

There are several errors in your code which are easier to see if you ident the code:

(defrule MAIN::one
   (x_front ?val)
   (bind ?temp 1)
   (choice-evaluation (y_left -1) 
                      (test (<= ?val ?temp)) 
                      (class ?x))
   ?c <- (choice-evaluation (y_left -1) 
                            (test (<= ?val ?temp))
                            (class ?x))
   =>
   (assert (es_result (classp 0) (classr ?x) (nr 1)))
   (retract ?c))

You've placed test conditional elements inside choice-evaluation conditional elements so the parser treats the test symbols as slot names and since the choice-evaluation deftemplate has no slot named test you get an error. You'll also get an error for using class as a slot name since this slot is also not defined in the choice-evaluation deftemplate.

Also, (bind ?temp 1) will be treated as a fact pattern, not a function call. If you want to retrieve a value in the conditions of a rule, assert a fact containing that value and assign it to a variable using a pattern like the x_front pattern in your rule. Duplication of the choice-evaluation pattern serves no purpose--Just keep the 2nd one since it binds ?c to the fact-address matching the pattern which is need by the retract command in the actions of the rule.

Upvotes: 0

Related Questions