TL;DR: 私が Prolog から始めて、C から来て、機能するようになったという事実でルールを呼び出すのに助けが必要です...明らかに壊れてしまうまで。この新しい言語を学びながら、自分用に小さな車の塗装プログラムを書いています。
ファクトを使用してルールを呼び出そうとしています (これは可能ですか?)。1 つのファクト「cars」と別のファクト「paint」を使用して、すべての異なるすべての車で構成される 1 つの大きなリストを作成します。塗料。コードを思うように動作させるのに問題があります...見てください
私は事実を持っています:
cars([ferrari, bmw, ford, jaguar]).
paints([red, white, blue, yellow]).
/*Now I wanted to loop through each car, eachtime printing
out the different paint combinations of that car: */
start:- loop_cars(cars(C)). /*starts loop_cars with all the cars e.g [ferrari...]*/
/*but it false here, even if C = [ferrari...]*/
loop_cars([]).
loop_cars([Ca|Rest]):-
loop_paints(Ca,paints(P)), /*The car is sent off for a paint job,...*/
loop_cars(Rest). /*...(cont from above) same false here as before*/
loop_paints(_,[]).
loop_paints(Ca,[Pa|Rest]):- /*This works*/
write([Ca,Pa]), /*Writes it like "[ferrari, white] [ferrari, blue] ..."*/
loop_paints(Ca,Rest).
だから私は2つの問題を解決するのに助けが必要だと思います:
- ファクトカーとペイントの内容を 2 つのループに渡すにはどうすればよいですか?
- すべての組み合わせを入れる「ガレージ」。ガレージは、小さな 2 つの項目リスト (車と塗料) で構成される大きなリストです。