0

When I run system, it shows error "expected the beginning of a construct" .. how can I correct this mistake

my rules look like this

(defrule UFP
 (not (repair ?))
   ?f <- (rule1)

   =>
(retract ?f)
(printout t "Finish UFP (y/n)
yes> go to rule 10 - Advise : Select your major
No> go to rule 2 - Advise : please finish all the levels of UFP to enter your major
q>Exit system" crlf)

(bind ?response (check-YNoptions-input))
(if (eq ?response y)
then
(assert (rule10))
)
(if (or(eq ?response q) (eq ?response Q))
    then 
    (output-exitmessage)
)
(if (eq ?response n)
    then



            (assert (rule2))
        )
)
)



; --------------------------------------------------
; Define coleege-system rule2
; --------------------------------------------------
(defrule rule2
?f <- (rule2)
   =>
   (retract ?f)

(bind ?response (ask-question "which level from OET result: (A0 or A1 =level1 ,A2= level2, B1=level3)
 (level1/level2/level3)
level1 > go to rule 3
level2 > go to rule 5
level3 > go to rule 7"


                   level1 level2 level3))
   (if (eq ?response level1)
       then 
      (assert (rule3))
       else (if (eq ?response level2)
                then (assert (rule5))

     else  (assert (rule7))
     )))

second issue:

want to exit system when press "q" key, with each rule, which every rule has y and n keys ..... what is the proper defunction ..

raya ali
  • 3
  • 1
  • 4

1 Answers1

1

If you watch compilations, you can see the point at which the error occurs:

CLIPS> (clear)
CLIPS> (watch compilations)
CLIPS> (load problem.clp)
Defining deffunction: check-YNoptions-input
Defining deffunction: output-exitmessage
Defining deffunction: ask-question
Defining defrule: UFP +j+j+j

[CSTRCPSR1] Expected the beginning of a construct.
Defining defrule: rule2 +j+j
FALSE
CLIPS> 

The issue occurs after the UFP rule. There is an extra right parenthesis after the rule. When editing CLIPS rules, it's helpful to use an editor that has some type of parentheses balancing. It makes it easier to find these types of mistakes.

If you want to halt CLIPS execution without exiting CLIPS, use the (halt) command. If you want to exit CLIPS, use the (exit) command.

Gary Riley
  • 10,130
  • 2
  • 19
  • 34
  • Thanx, I delete right parenthesis and it is show true now, but about exit command, I use halt command but it show "input is invalid" .. why :) – raya ali Jun 16 '15 at 10:25
  • Hard to say without seeing what you did. There's nothing in CLIPS that generates an "input is invalid" message. – Gary Riley Jun 16 '15 at 15:58
  • This is my defunction (deffunction check-YNoptions-input() (bind ?response (read) ) ( while (and (not(eq ?response y)) (not(eq ?response n)) (not(eq ?response q)) ) do (printout t "Input is invalid, please choose your answer again." crlf) (bind ?response (read) ) ) (return ?response) ) – raya ali Jun 16 '15 at 16:35
  • If you're typing (halt) in when you call this function, that's not going to work. When you detect q or h or whatever letter you choose, you need to call the (halt) command: (if (eq ?response q) then (halt)) – Gary Riley Jun 16 '15 at 19:47