Question

I am trying to return a message if the user types in a value within certain range. Is this possible on CLIPS? In addition the system should only accept values in increments of 10.

If the user types in a number less or equal to 10 it should say "A"
If the user types in a number greater than 10 and less than 40 it should say "B" 
- so it should only accept values 10,20,30,40

This is the code I have so far:

(defrule b-a1
(b-a "a")
=>
(bind ?reply (get-text-from-user "How many points did you achieve?"))
(assert (b-a1 ?reply )))

(defrule b-a2
(b-a1 <= 10)
=>
(assert (conclusion "A")))

(defrule b-a2
(10 < b-a1 < 40)
=>
(assert (conclusion "B")))

Any ideas on how I can get this working?

Was it helpful?

Solution

CLIPS> 
(defrule b-a1
   (b-a "a")
   =>
   (printout t "How many points did you achieve? ")
   (bind ?reply (read))
   (assert (b-a1 ?reply )))
CLIPS> 
(defrule b-a2
   (b-a1 ?v&:(<= ?v 10))
   =>
   (assert (conclusion "A")))
CLIPS> 
(defrule b-a2
   (b-a1 ?v&:(< 10 ?v)&:(< ?v 40))
   =>
   (assert (conclusion "B")))
CLIPS> (assert (b-a "a"))
<Fact-1>
CLIPS> (run)
How many points did you achieve? 24
CLIPS> (facts)
f-0     (initial-fact)
f-1     (b-a "a")
f-2     (b-a1 24)
f-3     (conclusion "B")
For a total of 4 facts.
CLIPS> 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top