Expected the beginning of a construct clips ошибка

I have this homework(I’m a student), in CLIPS, however I can’t make any progress, despite searching on google, and spending some time on it.

(clear)
(deftemplate book
    (multislot surname)(slot name)(multislot title) 
)

(book (surname J.P.)(name Dubreuil)(title History of francmasons))
(book (surname T.)(name Eker)(title Secrets of millionaire mind))

(defrule find_title
    ?book<-(book(name Eker))
    =>
    (printout t ?book crlf)
)

What I eventually get is this error: «Expected the beginning of a construct».
Any ideas please?

asked Oct 12, 2013 at 10:05

Iacob Eduard's user avatar

If you’re using the load command to load this content, then you’re mixing commands (such as clear) with CLIPS constructs (such as deftemplate and defrule). To fix this, first create a file such as book.clp with just constructs:

(deftemplate book
    (multislot surname)(slot name)(multislot title) 
)

(deffacts initial
(book (surname J.P.)(name Dubreuil)(title History of francmasons))
(book (surname T.)(name Eker)(title Secrets of millionaire mind)))

(defrule find_title
    ?book<-(book(name Eker))
    =>
    (printout t ?book crlf)
)

Then you can use the load command to load the file and run it:

CLIPS> (clear)
CLIPS> (load book.clp)
%$*
TRUE
CLIPS> (reset)
CLIPS> (agenda)
0      find_title: f-2
For a total of 1 activation.
CLIPS> (facts)
f-0     (initial-fact)
f-1     (book (surname J.P.) (name Dubreuil) (title History of francmasons))
f-2     (book (surname T.) (name Eker) (title Secrets of millionaire mind))
For a total of 3 facts.
CLIPS> (run)
<Fact-2>
CLIPS> 

answered Oct 13, 2013 at 15:52

Gary Riley's user avatar

Gary RileyGary Riley

10.1k2 gold badges19 silver badges34 bronze badges

Если вы смотрите компиляции, вы можете увидеть точку, в которой происходит ошибка:

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> 

Проблема возникает после правила UFP. После правила есть лишняя правая скобка. При редактировании правил CLIPS полезно использовать редактор с балансировкой скобок. Это облегчает поиск таких ошибок.

Если вы хотите остановить выполнение CLIPS без выхода из CLIPS, используйте команду (halt). Если вы хотите выйти из CLIPS, используйте команду (выход).

Slenon

5 / 5 / 3

Регистрация: 25.07.2016

Сообщений: 182

1

06.01.2018, 19:36. Показов 5489. Ответов 6

Метки нет (Все метки)


Студворк — интернет-сервис помощи студентам

Переделываю прогу из Prolog`а (из арабских в римские, и обратно) …

Lisp
1
2
3
4
5
6
7
8
9
10
11
12
(defrule ArabRim  
   =>
(deffacts chisla
(zamena (arab 1000) (rim "M") (q 1))   (zamena (arab 900) (rim "CM") (q 2))
(zamena (arab 500)  (rim "D") (q 1))   (zamena (arab 400) (rim "CD") (q 2))    
(zamena (arab 100)  (rim "C") (q 1))   (zamena (arab 90)  (rim "XC") (q 2))
(zamena (arab 50)   (rim "L") (q 1))   (zamena (arab 40)  (rim "XL") (q 2))
(zamena (arab 10)   (rim "X") (q 1))   (zamena (arab 9)   (rim "IX") (q 2))
(zamena (arab 5)    (rim "V") (q 1))   (zamena (arab 4)   (rim "IV") (q 2))
(zamena (arab 1)    (rim "I") (q 1)))
(zamena (arab ?arab) (rim "D"))
(printout t " arab = " ?arab crlf))

CLIPS> (load «C:/CLIPS/i_programmy/ArabRim.clp»)
*
[EXPRNPSR3] Missing function declaration for deffacts.

ERROR:
(defrule MAIN::ArabRim
=>
(deffacts

FALSE
CLIPS>


Что значит — Missing function declaration for deffacts.(Отсутствует объявление функции для деффактов.)



0



Модератор

Эксперт функциональных языков программированияЭксперт Python

35725 / 19608 / 4119

Регистрация: 12.02.2012

Сообщений: 32,671

Записей в блоге: 13

06.01.2018, 21:05

2

Я думаю, что имя deffacts употреблено, как имя функции, а определения этой функции нет.



0



Slenon

5 / 5 / 3

Регистрация: 25.07.2016

Сообщений: 182

10.01.2018, 18:19

 [ТС]

3

Вот код:

Lisp
1
2
3
4
5
6
7
(defrule ArabRim    =>
;(bind ?arab #)
(assert (slot arab)  (slot rim) (slot q))
(assert (arab 1000)  (rim "M")  (q 1))
(assert (arab 900)   (rim "CM") (q 2))
(assert (arab ?arab) (rim "M"))
(printout t " arab = " ?arab crlf))

при (bind ?arab #)

CLIPS> (load «C:/CLIPS/i_programmy/ArabRim.clp»)
*
TRUE
CLIPS> (reset)
CLIPS> (run)
arab = #
CLIPS>

Таким образом код проходит статическую проверку …
Но при ;(bind ?arab #)

[I]CLIPS> (load «C:/CLIPS/i_programmy/ArabRim.clp»)
*

Lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 Undefined variable arab referenced in RHS of defrule.
 
ERROR:
(defrule MAIN::ArabRim
   =>
   (assert (slot arab)
           (slot rim)
           (slot q))
   (assert (arab 1000)
           (rim "M")
           (q 1))
   (assert (arab 900)
           (rim "CM")
           (q 2))
   (assert (arab ?arab)
           (rim "M"))
   (printout t " arab = " ?arab crlf))
 
FALSE
CLIPS>

Вопрос — почему не работает (assert (arab ?arab) (rim «M»)), и не происходит
присвоение переменной ?arab значения 1000 …



0



Slenon

5 / 5 / 3

Регистрация: 25.07.2016

Сообщений: 182

13.01.2018, 15:05

 [ТС]

4

Lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
(defrule ArabRim  =>
;(load "AR.clp")
;(bind ?arab 0)
 
(assert (deftemplate zamena
(assert (slot arab)  (slot rim) (slot q))))
 
(assert (deffacts chisla
(assert (zamena  (assert (arab 1000) (rim "M")  (q 1))))
(assert (zamena  (assert (arab 900)  (rim "CM") (q 2))))))
 
(assert (zamena (assert (arab ?arab) (rim "M")  (q 1))))
(printout t " arab = "  ?arab crlf))

Вопрос всё тот же …



0



Slenon

5 / 5 / 3

Регистрация: 25.07.2016

Сообщений: 182

16.01.2018, 04:54

 [ТС]

5

Может быть кому то пригодится:

Lisp
1
2
3
4
5
6
7
(deffacts chisla
(zamena (assert
(arab 1000) (rim "M")  (q 1)
(arab 900)  (rim "CM") (q 2)
;....................................................
(arab 1)    (rim "I")  (q 1)
)))

Только одно assert для всех фактов …
Но только если конструкция вынесена в
отдельный файл (load «___.clp») …



1



Slenon

5 / 5 / 3

Регистрация: 25.07.2016

Сообщений: 182

18.01.2018, 01:10

 [ТС]

6

Lisp
1
2
3
4
5
6
7
(defrule ArabRim1  =>
;(bind ?arab 0)
(assert (slot arab) (slot rim) (slot q))
(assert (arab 1000) (rim "M")  (q 1)
        (arab 900)  (rim "CM") (q 2))
(assert (arab ?arab) (rim "M") (q 1))
(printout t " arab = "  ?arab crlf))

Можно и так … А результата всё равно нет!!!



0



Slenon

5 / 5 / 3

Регистрация: 25.07.2016

Сообщений: 182

21.01.2018, 21:24

 [ТС]

7

Lisp
1
2
3
4
5
6
(deffacts chisla
(zamena (arab 1000) (rim "M")  (q 1))
(zamena (arab 900)  (rim "CM") (q 2))
.....................................................
(zamena (arab 4)    (rim "IV") (q 2))
(zamena (arab 1)    (rim "I")  (q 1)))
Lisp
1
2
3
4
5
6
7
8
9
(deftemplate zamena
(slot arab) (slot rim) (slot q))
;------------------------------------
(defrule ArabRim 
(zamena (arab ?arab) (rim ?rim) (q 1))
    =>
(printout t " arab = " ?arab "  rim = " ?rim crlf))
;------------------------------------
(load "chisla.clp")

CLIPS> (load «C:/CLIPS/i_programmy/ArabRim/ArabRim.clp»)

[CSTRCPSR4] Cannot redefine deftemplate zamena while it is in use.

ERROR:
(deftemplate MAIN::zamena
*
[CSTRCPSR1] Expected the beginning of a construct.

FALSE
CLIPS> (reset)
CLIPS> (run)
arab = 1 rim = I
…………………………..
arab = 1000 rim = M
CLIPS>


Вопрос — код выдаёт правильный результат, но при этом пишет
сообщения об ошибках … Почему ?!!! ….



0



Первая ошибка заключается в том, что вы передаете нечисловой аргумент в качестве второго аргумента в функцию >=. Когда в конструкции возникает ошибка, CLIPS покажет вам, что было разобрано, чтобы помочь вам найти проблему:

Как правило, вторая ошибка возникает, когда при загрузке конструкций у вас есть лишняя или недостающая скобка. Например, если вы создадите файл с именем example.clp со следующим содержимым:

Вы получите эту ошибку, когда попытаетесь загрузить его:

Если вы’следите за компиляциями, вы можете лучше понять, где возникает ошибка. В данном случае она находится между правилами example-2 и example-3.

Перейти к контенту

I have this homework(I’m a student), in CLIPS, however I can’t make any progress, despite searching on google, and spending some time on it.

(clear)
(deftemplate book
    (multislot surname)(slot name)(multislot title) 
)

(book (surname J.P.)(name Dubreuil)(title History of francmasons))
(book (surname T.)(name Eker)(title Secrets of millionaire mind))

(defrule find_title
    ?book<-(book(name Eker))
    =>
    (printout t ?book crlf)
)

What I eventually get is this error: «Expected the beginning of a construct».
Any ideas please?

asked Oct 12, 2013 at 10:05

Iacob Eduard's user avatar

If you’re using the load command to load this content, then you’re mixing commands (such as clear) with CLIPS constructs (such as deftemplate and defrule). To fix this, first create a file such as book.clp with just constructs:

(deftemplate book
    (multislot surname)(slot name)(multislot title) 
)

(deffacts initial
(book (surname J.P.)(name Dubreuil)(title History of francmasons))
(book (surname T.)(name Eker)(title Secrets of millionaire mind)))

(defrule find_title
    ?book<-(book(name Eker))
    =>
    (printout t ?book crlf)
)

Then you can use the load command to load the file and run it:

CLIPS> (clear)
CLIPS> (load book.clp)
%$*
TRUE
CLIPS> (reset)
CLIPS> (agenda)
0      find_title: f-2
For a total of 1 activation.
CLIPS> (facts)
f-0     (initial-fact)
f-1     (book (surname J.P.) (name Dubreuil) (title History of francmasons))
f-2     (book (surname T.) (name Eker) (title Secrets of millionaire mind))
For a total of 3 facts.
CLIPS> (run)
<Fact-2>
CLIPS> 

answered Oct 13, 2013 at 15:52

Gary Riley's user avatar

Gary RileyGary Riley

9,9052 gold badges19 silver badges34 bronze badges

Slenon

5 / 5 / 3

Регистрация: 25.07.2016

Сообщений: 182

1

06.01.2018, 19:36. Показов 5015. Ответов 6

Метки нет (Все метки)


Переделываю прогу из Prolog`а (из арабских в римские, и обратно) …

Lisp
1
2
3
4
5
6
7
8
9
10
11
12
(defrule ArabRim  
   =>
(deffacts chisla
(zamena (arab 1000) (rim "M") (q 1))   (zamena (arab 900) (rim "CM") (q 2))
(zamena (arab 500)  (rim "D") (q 1))   (zamena (arab 400) (rim "CD") (q 2))    
(zamena (arab 100)  (rim "C") (q 1))   (zamena (arab 90)  (rim "XC") (q 2))
(zamena (arab 50)   (rim "L") (q 1))   (zamena (arab 40)  (rim "XL") (q 2))
(zamena (arab 10)   (rim "X") (q 1))   (zamena (arab 9)   (rim "IX") (q 2))
(zamena (arab 5)    (rim "V") (q 1))   (zamena (arab 4)   (rim "IV") (q 2))
(zamena (arab 1)    (rim "I") (q 1)))
(zamena (arab ?arab) (rim "D"))
(printout t " arab = " ?arab crlf))

CLIPS> (load «C:/CLIPS/i_programmy/ArabRim.clp»)
*
[EXPRNPSR3] Missing function declaration for deffacts.

ERROR:
(defrule MAIN::ArabRim
=>
(deffacts

FALSE
CLIPS>


Что значит — Missing function declaration for deffacts.(Отсутствует объявление функции для деффактов.)

__________________
Помощь в написании контрольных, курсовых и дипломных работ, диссертаций здесь

0

Модератор

Эксперт функциональных языков программированияЭксперт Python

33778 / 18815 / 3968

Регистрация: 12.02.2012

Сообщений: 31,559

Записей в блоге: 12

06.01.2018, 21:05

2

Я думаю, что имя deffacts употреблено, как имя функции, а определения этой функции нет.

0

Slenon

5 / 5 / 3

Регистрация: 25.07.2016

Сообщений: 182

10.01.2018, 18:19

 [ТС]

3

Вот код:

Lisp
1
2
3
4
5
6
7
(defrule ArabRim    =>
;(bind ?arab #)
(assert (slot arab)  (slot rim) (slot q))
(assert (arab 1000)  (rim "M")  (q 1))
(assert (arab 900)   (rim "CM") (q 2))
(assert (arab ?arab) (rim "M"))
(printout t " arab = " ?arab crlf))

при (bind ?arab #)

CLIPS> (load «C:/CLIPS/i_programmy/ArabRim.clp»)
*
TRUE
CLIPS> (reset)
CLIPS> (run)
arab = #
CLIPS>

Таким образом код проходит статическую проверку …
Но при ;(bind ?arab #)

[I]CLIPS> (load «C:/CLIPS/i_programmy/ArabRim.clp»)
*

Lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 Undefined variable arab referenced in RHS of defrule.
 
ERROR:
(defrule MAIN::ArabRim
   =>
   (assert (slot arab)
           (slot rim)
           (slot q))
   (assert (arab 1000)
           (rim "M")
           (q 1))
   (assert (arab 900)
           (rim "CM")
           (q 2))
   (assert (arab ?arab)
           (rim "M"))
   (printout t " arab = " ?arab crlf))
 
FALSE
CLIPS>

Вопрос — почему не работает (assert (arab ?arab) (rim «M»)), и не происходит
присвоение переменной ?arab значения 1000 …

0

Slenon

5 / 5 / 3

Регистрация: 25.07.2016

Сообщений: 182

13.01.2018, 15:05

 [ТС]

4

Lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
(defrule ArabRim  =>
;(load "AR.clp")
;(bind ?arab 0)
 
(assert (deftemplate zamena
(assert (slot arab)  (slot rim) (slot q))))
 
(assert (deffacts chisla
(assert (zamena  (assert (arab 1000) (rim "M")  (q 1))))
(assert (zamena  (assert (arab 900)  (rim "CM") (q 2))))))
 
(assert (zamena (assert (arab ?arab) (rim "M")  (q 1))))
(printout t " arab = "  ?arab crlf))

Вопрос всё тот же …

0

Slenon

5 / 5 / 3

Регистрация: 25.07.2016

Сообщений: 182

16.01.2018, 04:54

 [ТС]

5

Может быть кому то пригодится:

Lisp
1
2
3
4
5
6
7
(deffacts chisla
(zamena (assert
(arab 1000) (rim "M")  (q 1)
(arab 900)  (rim "CM") (q 2)
;....................................................
(arab 1)    (rim "I")  (q 1)
)))

Только одно assert для всех фактов …
Но только если конструкция вынесена в
отдельный файл (load «___.clp») …

1

Slenon

5 / 5 / 3

Регистрация: 25.07.2016

Сообщений: 182

18.01.2018, 01:10

 [ТС]

6

Lisp
1
2
3
4
5
6
7
(defrule ArabRim1  =>
;(bind ?arab 0)
(assert (slot arab) (slot rim) (slot q))
(assert (arab 1000) (rim "M")  (q 1)
        (arab 900)  (rim "CM") (q 2))
(assert (arab ?arab) (rim "M") (q 1))
(printout t " arab = "  ?arab crlf))

Можно и так … А результата всё равно нет!!!

0

Slenon

5 / 5 / 3

Регистрация: 25.07.2016

Сообщений: 182

21.01.2018, 21:24

 [ТС]

7

Lisp
1
2
3
4
5
6
(deffacts chisla
(zamena (arab 1000) (rim "M")  (q 1))
(zamena (arab 900)  (rim "CM") (q 2))
.....................................................
(zamena (arab 4)    (rim "IV") (q 2))
(zamena (arab 1)    (rim "I")  (q 1)))
Lisp
1
2
3
4
5
6
7
8
9
(deftemplate zamena
(slot arab) (slot rim) (slot q))
;------------------------------------
(defrule ArabRim 
(zamena (arab ?arab) (rim ?rim) (q 1))
    =>
(printout t " arab = " ?arab "  rim = " ?rim crlf))
;------------------------------------
(load "chisla.clp")

CLIPS> (load «C:/CLIPS/i_programmy/ArabRim/ArabRim.clp»)

[CSTRCPSR4] Cannot redefine deftemplate zamena while it is in use.

ERROR:
(deftemplate MAIN::zamena
*
[CSTRCPSR1] Expected the beginning of a construct.

FALSE
CLIPS> (reset)
CLIPS> (run)
arab = 1 rim = I
…………………………..
arab = 1000 rim = M
CLIPS>


Вопрос — код выдаёт правильный результат, но при этом пишет
сообщения об ошибках … Почему ?!!! ….

0

Thank you so much for your urgent reply. That’s very kind of you.

I went to the address you gave and currently trying to understand the examples. But may I kindly request a «simplest» example please?

I am trying to load a clp file and assert a fact but I can’t run even this!

***********************************
VB version:

Dim klips As New CLIPSNet.Environment
klips.Load(«blahblah.clp»)
klips.EnvReset()
Fact.AssertString(klips, «(so and so)»)
klips.EnvRun()

***********************************

C# version:
CLIPSNet.Environment klips = new CLIPSNet.Environment();
klips.Load(«blahblah.clp»);
Fact.AssertString(klips, «(so and so)»);
klips.EnvRun();
***********************************

Visual C# doesn’t have a problem with «Fact» and ultimately prints the result.

Visual Basic doesn’t accept to use «Fact» because it is «Firend».

BUT…

Both VB and C# complain in a console window:

[CSTRCPSR1] Expected the beginning of a construct

VB says that and that’s all, it halts.
C# first says that but somehow shows the result in a second line.

Now:

1. Isn’t is possible to use CLIPS .NET dll with VB?
2. What is this «[CSTRCPSR1] Expected the beginning of a construct»?
3. If C# «expected» something and seemingly could not find, how can it run anyway?

I am still crawling, please help me walking :-)

Thanks.

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

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.

Related

Using variables in salience declaration in a rule definition

I want to use a variable bound in the LHS to declare the salience of a rule in order to prioritize rules with a stricter time limit defined in the fact database. I figured the following should work:
(set-salience-evaluation when-activated)
(deffunction testsal (?a ?b) (integer (+ ?a ?b)))
(defrule testr
(declare (salience (testsal ?a 4)))
(sal ?a)
?tf <- (fire testr)
=>
(printout t "Running testr")
(retract ?tf)
)
(assert (sal 3))
(assert (fire testr))
But this fails with an error:
[EVALUATN1] Variable a is unbound
[PRCCODE6] This error occurred while evaluating arguments for the deffunction testsal.
[PRNTUTIL8] This error occurred while evaluating the salience for defrule testr.
ERROR:
(defrule MAIN::testr
(declare (salience (testsal ?a 4)
Is there a way to use a variable that is bound in the LHS in the salience declaration of the rule?
If not, what is the common way to prioritize depending on some facts in the fact base? Note that I do not want to disallow the rule to fire, I just want to prioritize other rules, so simply adding a constraint to the LHS would probably not work.
Use a global variable rather than a fact:
CLIPS> (set-salience-evaluation when-activated)
when-activated
CLIPS> (defglobal ?*sal-a* = 0)
CLIPS>
(defrule testr
(declare (salience (+ ?*sal-a* 4)))
?tf <- (fire testr)
=>
(printout t "Running testr")
(retract ?tf))
CLIPS> (bind ?*sal-a* 3)
3
CLIPS> (assert (fire testr))
<Fact-1>
CLIPS> (agenda)
7 testr: f-1
For a total of 1 activation.
CLIPS>

How to debug “Check appropriate syntax for defrule” in Clips rule engine?

(deftemplate illness
(slot sickness)
(multislot keywords))
(deffacts qestion-refrences
(illness (sickness stunted-Groth)(keywords stunted groth))
(illness (sickness pale-Yellow) (keywords pale yellow))
(illness (sickness reddish-Brown)(keywords reddish brown))
(illness (sickness stunted-Root)(keywords stunted root)))
(deffunction askquestion (?question)
(printout t ?question)
(bind ?answer (read))
(if (lexemep ?answer)
then (bind ?answer (lowcase ?answer)))
?answer)
(defrule determineSickness
(bind ?f (askquestion "whot Does the plant seem to have ? "))
(illness (keywords ?kw) (sickness ?sk))
(while (not (subsetp ?kw ?f ))
(bind ?f (askquestion "whot Does the plant seem to have ? ")))
=>
(assert ?sk))
What I am trying to do is simply ask the user what is wrong with their plant and using the keywords to identify the problem and then assert the problem. However I keep getting the following error.
Defining defrule: determineSickness
[PRNTUTIL2] Syntax Error: Check appropriate syntax for defrule.
ERROR:
(defrule MAIN::determineSickness
(bind ?f (
FALSE
CLIPS>
There's a BNF specification of valid CLIPS syntax in the CLIPS Basic Programming Guide. A relevant portion for defrules is:
<defrule-construct> ::=
(defrule <rule-name> [<comment>]
[<declaration>]
<conditional-element>*
=>
<action>*)
<action> ::= <expression>
<expression> ::= <constant> | <variable> | <function-call>
<function-call> ::= (<function-name> <expression>*)
<conditional-element> ::=
<pattern-CE> |
<assigned-pattern-CE> |
<not-CE> |
<and-CE> |
<or-CE> |
<logical-CE> |
<test-CE> |
<exists-CE> |
<forall-CE>
The when portion of the rule (the part before the =>) consists of conditions that must be matched by facts/instances in order for the rule to be applicable. You can make function calls from the conditions of the rule, but not using the syntax you've attempted. In addition, since conditions can be activated in a non-sequential order, procedural code that must be executed sequentially needs to be specified in the actions of the rule (the part after the =>).
You can make your original code syntactically correct with a few changes:
(defrule determineSickness
(illness (keywords $?kw) (sickness ?sk))
=>
(bind ?f (askquestion "whot Does the plant seem to have ? "))
(while (not (member$ ?f ?kw))
(bind ?f (askquestion "whot Does the plant seem to have ? ")))
(assert (diagnosis ?sk)))
Your rule(s) are still semantically incorrect. This is what they currently do:
For every illness, ask the user to specify one of the symptoms for that illness.
This is what they need to do:
For every symptom specified by the user, find every illness having that symptom.

Clips OR Statement not firing

Unsure why this isn't working.
(defrule contain-red?
(initial-fact)
=>
(bind ?reply (get-text-from-user "Does it contain x (y/n?"))
(assert (existing-text ?reply )))
(defrule partOne
(existing-text "y")
=>
(bind ?reply (get-text-from-user "give me a number"))
(assert (credit-value-bsc-first-result (explode$ ?reply ))))
(defrule partTwo
(existing-text "n")
=>
(bind ?reply (get-text-from-user "give me a number"))
(assert (credit-value-bsc-second-result (explode$ ?reply ))))
(defrule learn-about-120?
(credit-value-bsc-first-result ?n)
(credit-value-bsc-second-result ?x)
(test (or (<= ?n 20) (<= ?x 20)))
=>
(bind ?reply (get-text-from-user "Reponse here)"))
(assert (learn-about-120-response ?reply )))
I can get the final rule to work using an and in a different scenario. When loading this into wxCLIPS no errors appear, but when I run it and enter the relevant data the final rule doesn't fire.
The fact credit-value-bc-first-result is only created if existing-text is "y". The fact credit-value-bc-second-result is only created if existing-text is "n". If only one existing-text fact exists, then these conditions are mutually exclusive. Since rule learn-about-120? requires both of these facts it will not fire.
Writing the rule this way is probably what you want:
(defrule learn-about-120?
(or (credit-value-bsc-first-result ?n)
(credit-value-bsc-second-result ?n))
(test (<= ?n 20))
=>
(bind ?reply (get-text-from-user "Reponse here)"))
(assert (learn-about-120-response ?reply )))

Illogical unmatch in clips

i have a problem with a rule match in Clips, in particular i can't understand why this rule doesn't actives!.
I have a module called REASONING where i defined a fact with this deftemplate
(deftemplate planning (slot value (allowed-values start stop))).
First time i focus on this module i assert this fact with this rule
(defrule start-reasoning
(declare (salience 90))
(not (planning))
=>
(assert (planning (value start)))
)
Nextly, this fact will be never retract but only modified its slot.
In the same module where i defined planning i have an other rule, where it's changed value from start to stop.
(defrule plan-done
(declare (salience 60))
?<-(planning(value start)
=>
(modify ?p (value stop))
)
This is the last rule activated by this module. After that Clips execute a pop-focus. Now when it's the turn to get focus again on this module, i find
(planning (value stop))
f-4839 (explore-memory (pos-r 2) (pos-c 5) (direction west)(action turnleft)
(param1 nil) (param2 nil) (param3 nil) (open-depth 0) (ident 0))
f-4843 (planning (value stop))
f-4845 (exec (step 0)(action turnleft)(param1 nil)(param2 nil) (param3 nil))
f-5029 (exec (step 1)(action turnright)(param1 nil)(param2 nil)(param3 nil))
So i expect that rule written under must be actived but it doesn't happen!
The condition to change again slot value it's inside module PLAN_MANAGER, whereby i can active no other rules inside REASONING until Clips doesn't exec focus on PLAN_MANAGER.
(defrule go-to-plan-manager
(declare (salience 90))
(planning (value stop))
=>
(focus PLAN_MANAGER)
)
The strange thing it's that if i call matches function i obtain this output.
>(matches go-to-plan-manager)
Matches for Pattern 1
f-4843
Activations
None
Anybody can help me to understand why CLIPS doesn't puts in agenda go-to-plan-manager ? Where i'm wrong?
Given the lack of a reproducible example to demonstrate otherwise, the most likely explanation is that the go-to-plan-manager executed at some point before the focus was originally popped. Refocusing on a module only changes the agenda from which activations are pulled, but it doesn't reactivate rules that have previously been executed.
The simplest example I can create based on the code fragments you included suggests that your go-to-plan-manager rule is going to execute immediately after the plan-done rule unless there's some other rule with a salience of 90 or higher that pops the focus before the go-to-plan-manager rule can execute.
CLIPS> (deftemplate planning (slot value (allowed-values start stop)))
CLIPS>
(defrule start-reasoning
(declare (salience 90))
(not (planning))
=>
(assert (planning (value start))))
CLIPS>
(defrule plan-done
(declare (salience 60))
?p<-(planning(value start))
=>
(modify ?p (value stop)))
CLIPS>
(defrule go-to-plan-manager
(declare (salience 90))
(planning (value stop))
=>
(printout t "go-to-plan-manager executed" crlf))
CLIPS> (reset)
CLIPS> (watch rules)
CLIPS> (run)
FIRE 1 start-reasoning: *
FIRE 2 plan-done: f-1
FIRE 3 go-to-plan-manager: f-2
go-to-plan-manager executed
CLIPS> (matches go-to-plan-manager)
Matches for Pattern 1
f-2
Activations
None
(1 0 0)
CLIPS>

Get back to above rule in clips

when I try to call a defrule that have been used already, clips stop..
some defrule need to be used more than one time, is there any way to do it
here is an example
(
defrule choice-in-powerPlant2
(powerPlant2-question)
=>
(printout t "Are Filter and Carburetor Air working fine(y/n)?" crlf)
(bind ?response (check-YNoptions-input)); Get user input on type of questions
(if (eq ?response y)
then
(assert (powerPlant1-question)
)
)
(if (or(eq ?response q) (eq ?response Q))
then
(output-exitmessage)
)
(if (eq ?response n)
then
(printout t "Have you fixed this(y/n)?" crlf)
(bind ?response (check-YNoptions-input)); Get user input on type of questions
(if (eq ?response y)
then
(assert (powerPlant1-question)
)
)
(if (eq ?response n)
then
(printout req "Please replace Filter and Carburetor Air " crlf)
(assert (powerPlant3-question))
)
)
)
in rule 2
I want to go back to rule 1 when I enter "y"=yes
" running stopped once I enterd "y" "
If you want to retrigger a rule that matches a specific fact, retract that fact as part of the rule action. If another rule then asserts that specific fact, the rule will be retriggered. For example:
(defrule choice-in-powerPlant2
?f <- (powerPlant2-question)
=>
(retract ?f)
(printout t "Are Filter and Carburetor Air working fine(y/n)?" crlf)
.
.
.
)

jv

unread,

Jul 13, 2007, 3:08:27 PM7/13/07

to CLIPSESG

Hello,

I’m a first time CLIPS user off to a shaky start. I’m running CLIPS
v6.24 on a Microsoft Windows XP machine.
When I manually enter the following in the CLIPS interactive
interpreter:

;<code>
(clear)
(defrule take-a-walk
(status walking)
(walk-sign walk)
=>
(printout t «Go» crlf))
(assert (status walking))
(assert (walk-sign walk))
(run)
;</code>
it works as expected. However, it I save the above to a file and load
it, here is the result:

CLIPS (V6.24 06/15/06)
CLIPS> (load «C:/Documents and Settings/jim.vickroy/My Documents/
Projects/CLIPSWin/traffic-robot.clp»)

[CSTRCPSR1] Expected the beginning of a construct.
Defining defrule: take-a-walk +j+j

[CSTRCPSR1] Expected the beginning of a construct.
FALSE
CLIPS>

What mistake(s) have I made?

Thanks,

— jv

Johan Lindberg

unread,

Jul 13, 2007, 7:06:33 PM7/13/07

to CLIP…@googlegroups.com

Hi,

> … However, it I save the above to a file and load

> it, here is the result:
>
> CLIPS (V6.24 06/15/06)
> CLIPS> (load «C:/Documents and Settings/jim.vickroy/My Documents/
> Projects/CLIPSWin/traffic-robot.clp»)
>
> [CSTRCPSR1] Expected the beginning of a construct.
> Defining defrule: take-a-walk +j+j
>
> [CSTRCPSR1] Expected the beginning of a construct.
> FALSE
> CLIPS>
>
> What mistake(s) have I made?

I think you want the batch command («File/Load batch…» if you’re
using the GUI). Try:

CLIPS> (batch «C:/Documents and Settings/jim.vickroy/My
Documents/Projects/CLIPSWin/traffic-robot.clp»)

instead and it will work without problems.

The load command is used to load constructs from a file — rules,
facts, globals, methods and such (things that start with «def») and
the batch command basically loads and runs everything in the file as
if it was entered into the interpreter.

You can read more about both commands in the Clips docs. See Basic
Programming Guide chapters 13.1.1 Loading Constructs From A File and
13.1.9 Executing Commands From a File.

HTH
Johan Lindberg
jo…@pulp.se

Johan Lindberg

unread,

Feb 13, 2009, 5:50:57 PM2/13/09

to Dana, CLIPSESG

Hi,

> I saw your answer on this matter 3 years ago.
> Could you please take a look of my program below {which I type in
> CLIPS text editor (& save in clp extension) then I load it into CLIPS
> dialog (CLIPS 6.24)}, as I also get the same problem ( Expected the
> beginning of a construct error when load the program).
> 1. do you think the source of the problem & the solution are the same?
> 2. And while the loading process return in False, I could still
> running the program, is it always the case when [CSTRCPSR1] happen?
> Thanks in advance.
>
> …
> CLIPS (V6.24 06/15/06)
> CLIPS> (load «C:/Documents and Settings/Dana/My Documents/CLIPS/
> Research_prototype/cobacheckquestion.CLP»)
> Defining deffunction: ask-question
> Defining defrule: start +j

>
> [CSTRCPSR1] Expected the beginning of a construct.

> Defining defrule: designtype +j

>
> [CSTRCPSR1] Expected the beginning of a construct.

> Defining defrule: designtypejuga +j

>
> [CSTRCPSR1] Expected the beginning of a construct.

> Defining defrule: Stop1 +j
> Defining defrule: Stop2 +j
> FALSE
> …

1. Your problem is different from the one I replied to in 2007. You
have an extra closing parenthesis in each of the rules: start,
designtype and designtypejuga and that is the source of the error
messages you’re seeing.

2. CSTRCPSR1 means that CLIPS has failed to load a specific construct.
In this particular case it had no effect since those extra parenthesis
weren’t meant to be loaded anyway but I think that it is wise to
always assume that the program is invalid if load returns false and
instead try to fix it.

HTH
Johan Lindberg
jo…@pulp.se

  • Expected initializer before token ошибка
  • Expected initializer before int ошибка
  • Expected function or variable vba ошибка
  • Expected end with ошибка
  • Expected end sub ошибка vba