TL的規則; DR:需要幫助調用規則與事實
從來就開始了序言,由C來和得到的東西的工作...直到他們顯然得到打破。我正在爲自己寫一個小型汽車塗料程序,因爲我正在學習這門新語言序言 - 調用與事實
我想用事實調用規則(這是可能的嗎?),我想要做的是使用一個事實上「汽車」和另一個事實「油漆」,使所有不同的塗料中的所有汽車組成一個大名單。我無法使代碼工作,因爲我想...看看
從來就得到了事實:
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項目列表(汽車和油漆)。
我,由於我不知道任何的Prolog覺得不夠用。這是正常的嗎? – JAL 2010-10-24 01:13:06