问题
I need to take in input from the user which color and then output the flags that contain that color. I have this so far. I am pretty sure that the setup of my templates is correct. I just seem to be having issues with the input and the comparison and output part. Any help would be appreciated. I looked at a couple of other posts and used what I could be it still is not working. Thank you.
(deftemplate country-info
(slot country)
(multislot color)
)
; setting the template for flags taking the country name and color of the flags
(deffacts country
(country-info (country usa) (color red | white | blue))
(country-info (country belgium) (color black | yellow | red))
(country-info (country poland) (color white | red))
(country-info (country monaco) (color white | red))
(country-info (country sweden) (color yellow | blue))
(country-info (country Panama) (color white | blue | red))
(country-info (country jamacia) (color black | yellow | green))
(country-info (country colombia) (color blue | yellow | red))
(country-info (country italy) (color black | yellow | red))
(country-info (country ireland) (color green | white | orange))
(country-info (country botswana) (color blue | white | black))
)
(defrule color
(color ? name)
(not (color ? name ?))
=>
(printout t "What color is it you are looking for?")
(defrule check-input
(var ?color)
(country-info (country ?country1) (color $?color1))
(test (member$ ?color ?color1))
=>(printout t "Countries are" ? country crlf)
)
回答1:
CLIPS> (clear)
CLIPS>
(deftemplate country-info
(slot country)
(multislot color))
CLIPS>
(deffacts country
(country-info (country USA) (color red white blue))
(country-info (country Belgium) (color black yellow red))
(country-info (country Poland) (color white red))
(country-info (country Monaco) (color white red))
(country-info (country Sweden) (color yellow blue))
(country-info (country Panama) (color white blue red))
(country-info (country Jamacia) (color black yellow green))
(country-info (country Colombia) (color blue yellow red))
(country-info (country Italy) (color black yellow red))
(country-info (country Ireland) (color green white orange))
(country-info (country Botswana) (color blue white black)))
CLIPS>
(defrule color
=>
(printout t "Color? ")
(assert (color (read))))
CLIPS>
(defrule check-input
(color ?color)
(country-info (country ?country) (color $? ?color $?))
=>
(printout t " " ?country crlf))
CLIPS> (reset)
CLIPS> (run)
Color? red
Italy
Colombia
Panama
Monaco
Poland
Belgium
USA
CLIPS>
来源:https://stackoverflow.com/questions/30588104/clips-input-taking-and-comparison