dimanche 29 avril 2018

Use of if-then-else and facts in CLIPS

I want to order 4 letters, [a,b,c,d]. I'll ask some question to the user about some of the letters, and depending on his answers, I build the final order.

My problem is, if I had 2 rules that looked like this:

(defrule rule_1
    =>
(assert (1-a))
)

and

(defrule rule_2
    =>
(assert (2-a))
)

and I want to build an "if" statement where if "a" has to go first then the solution is [1-a, 2-b, 3-c, 4-d]; but if "a" is second, then the solution is [1-b, 2-a, 3-c, 4-d]. My rule is the following:

(defrule rule_3
    =>
    (if (1-a) 
    then (printout t "[1-a, 2-b, 3-c, 4-d]" crlf)
    else (printout t "[1-b, 2-a, 3-c, 4-d]" crlf)
))

The error I get is "Syntax Error", however I've searched through several manuals and I'm 100% sure the syntax follows like that, the difference with my code is that they use "if" on variables, and I want to use "if" as, If I have this fact -> do this. Is that possible?

Aucun commentaire:

Enregistrer un commentaire