0
votes

So I'm trying to build a program that takes user's input by displaying a message on the screen “Enter your subject”.

In the second rule, I'm to mention subject names “artificial intelligence”, “operating system” and “compiler construction” and check that entered subject from the first rule matches with the mentioned subjects by displaying this message on the screen. “Your entered subject is true”.

Here is the code:

(deftemplate subject
  (slot subject) 
  (slot artificial intelligence)
  (slot operating system)
  (slot compiler construction)) 

(defrule reading-input
  (printout t "Enter your subject:")
  (assert(var(read))))
  (defrule checking-input
  (var? artificial intelligence)
  (var? operating system)
  (var? compiler construction)
  (com(artificial intelligence ? artificial intelligence))
  (test(=?artificial intelligence ? artificial intelligence))
  (test(=?operating system ? operating system))
  (test(=? compiler construction ? compiler construction)) 
  (=>
  printout t "Your entered subject is true:"))
1
Could the space after the third test(=? be a cause of the trouble? It's an inconsistency in the layout, at any rate. Otherwise, could the newline after (=> be the cause of the trouble? Just guesses from someone who'd never heard of CLIPS until this question crossed their path. It would be easier to see the structure if there was a blank line before each defrule line to segregate different units. But I don't know if CLIPS is space sensitive.Jonathan Leffler
As a general rule, don't tag a question with both C and C++ unless you're particularly fond of downvotes. Unless the question is explicitly about the interworking of C and C++, at most one of the tags is appropriate. In this case, C++ is clearly wrong, and I'm not convinced that C is relevant either, so I removed both tags.Jonathan Leffler
Sorry for adding irrelevant tags, just new to StackOverflow. I was desperate for the solution and I'm entirely new to Clips so I'm keen interested in getting a proper guideline to resolve this.X Raiden
Have a look at some of the other CLIPS questions and see what tags they use; if it seems appropriate, add one or two more tags. I fear that the CLIPS community on SO is quite small. Getting good help may be tricky and/or slower than in more popular tags.Jonathan Leffler

1 Answers

0
votes
         CLIPS (6.31 6/12/19)
CLIPS> 
(defrule reading-input
  =>
  (printout t "Enter your subject: ")
  (assert (var (readline))))
CLIPS>   
(defrule checking-input
  (var "artificial intelligence" |
       "operating system" |
       "compiler construction")
  =>
  (printout t "Your entered subject is true." crlf))
CLIPS> (reset)
CLIPS> (run)
Enter your subject: operating system
Your entered subject is true.
CLIPS> (reset)
CLIPS> (run)
Enter your subject: algorithms
CLIPS>