expected the beginning of a construct error

3k views Asked by At

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 ..

1

There are 1 answers

4
Gary Riley On BEST ANSWER

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.