2016-05-03 29 views
1

次のコードを実行すると、出力が得られません。 Flagの色が印刷されます(終わりまで)?私が何が欠けているか分からない。どんな助けもありがとうございます。ありがとうございます出力を生成できません

(deftemplate flag (slot country) (multislot colors)) 

(deffacts countries 
    (flag (country USA) (colors red white blue)) 
    (flag (country Belgium) (colors black yellow red)) 
    (flag (country Poland) (colors white red)) 
    (flag (country Monaco) (colors white red)) 
    (flag (country Sweden) (colors yellow blued)) 
    (flag (country Panama) (colors red white blue)) 
    (flag (country Jamaica) (colors black yellow green)) 
    (flag (country Columbia) (colors yellow blue red)) 
    (flag (country Italy) (colors green white red)) 
    (flag (country Greece) (colors blue white)) 
    (flag (country Botswana) (colors blue white black))) 

(deffacts start 
    (get-color)) 

(defrule get-colors 
    ?f <- (get-color) 
    => 
    (retract ?f) 
    (printout t "Flag color (done to end)?") 
    (assert (new-color (read)))) 

(defrule find-matches 
    (find-flag) 
    (exists (color ?)) 
    (flag (country ?country)) 
    (forall (color ?color) 
      (flag (country ?country) (colors $? ?color $?))) 
    => 
    (printout t ?country " 's flag contains the specified colors." crlf)) 

(defrule no-matches 
    (find-flag) 
    (not (and (flag (country ?country)) 
      (forall (color ?color) 
        (flag (country ?country) (colors $? ?color $?))))) 
    => 
    (printout t "No country's flag contains the specified colors." crlf)) 

(defrule all-flags-match 
    (find-flag) 
    (not (color ?)) 
    => 
    (printout t "No search colors were specified." crlf)) 

(defrule look-for-flags 
    ?f <- (new-color done) 
    => 
    (retract ?f) 
    (assert (find-flag))) 

(defrule look-for-another-color 
    ?f <- (new-color ?color&~done) 
    => 
    (assert (color ?color)) 
    (retract ?f) 
    (assert (get-color))) 

答えて

0

プログラムでは、1つ以上の色を入力することを想定しています。すべての色を指定したら、プロンプトに「done」と入力します。次に、それらの色を含むフラグを持つ国の名前を表示します。

CLIPS> (reset) 
CLIPS> (run) 
Flag color (done to end)?red 
Flag color (done to end)?done 
Italy 's flag contains the specified colors. 
Columbia 's flag contains the specified colors. 
Panama 's flag contains the specified colors. 
Monaco 's flag contains the specified colors. 
Poland 's flag contains the specified colors. 
Belgium 's flag contains the specified colors. 
USA 's flag contains the specified colors. 
CLIPS> (reset) 
CLIPS> (run) 
Flag color (done to end)?red 
Flag color (done to end)?white 
Flag color (done to end)?done 
Italy 's flag contains the specified colors. 
Panama 's flag contains the specified colors. 
Monaco 's flag contains the specified colors. 
Poland 's flag contains the specified colors. 
USA 's flag contains the specified colors. 
CLIPS> (reset) 
CLIPS> (run) 
Flag color (done to end)?red 
Flag color (done to end)?white 
Flag color (done to end)?blue 
Flag color (done to end)?done 
Panama 's flag contains the specified colors. 
USA 's flag contains the specified colors. 
CLIPS> 
関連する問題