Rule is not working

2 views
Skip to first unread message

richa

unread,
May 12, 2008, 5:03:50 AM5/12/08
to CLIPSESG
Hi all,
I am making these rules but rule (defrule ck-select.....is not
working.
It should print "*** your selection must be either 1,2,3 or 4***" if
either option has been chosen rather than 1,2,3 or4. Please find out
my mistake and please suggest me how to make is working.Here is the
Rule


(deffacts init
(troubleshoot-mode bus)
(menu-level bus main))

;rules for selecting option

(defrule main-menu
(declare (salience 500))
(troubleshoot-mode bus)
?ml <- (menu-level bus main)
=>
(retract ?ml)
(printout t crlf crlf crlf)
(printout t
" Which one of the following you want to engage :-" crlf
crlf
" 1.)EPG" crlf
" 2.)CRUISE CONTROL" crlf
" 3.)ACCELERATOR" crlf
" 4.)Quit the program" crlf crlf
" Choose 1-4 -> ")
(bind ?response (read))
(assert (problem-response bus ?response))
(printout t crlf))

;;If option is not between 1-4


(defrule ck-select
(troubleshoot-mode bus)
?response <- (option ?ch)
(test (or (not (numberp ?ch))
(<= ?ch 0)
(> ?ch 4)))
=>
(printout t crlf crlf "*** your selection must be either 1,2,3 or
4***" crlf)
(retract ?response))
(assert (init)))


Johan Lindberg

unread,
May 12, 2008, 5:18:17 AM5/12/08
to CLIPSESG
Hi,

> I am making these rules but rule (defrule ck-select.....is not
> working.
> It should print "*** your selection must be either 1,2,3 or 4***" if
> either option has been chosen rather than 1,2,3 or4. Please find out
> my mistake and please suggest me how to make is working.Here is the
> Rule
> ...

Your main-menu rule asserts (problem-response bus ?response) but you
pattern-match against (option ?ch) in ck-select.

They have to match (both in name and position) if you want the ck-
select rule to trigger. Changing (option ?ch) to (problem-response
bus ?ch) "fixes" the problem but I really think you should try to make
a reusable structure based on *defined* templates.

HTH
Johan Lindberg
jo...@pulp.se

richa

unread,
May 12, 2008, 7:24:33 AM5/12/08
to CLIPSESG

Hi Johan,
My rule is working now by matching the pattern.And I'll keep in mind
your suggestion.I am not very good in CLIPS but want to be very good
in Rule making.
Reply all
Reply to author
Forward
0 new messages