私は持っています:
mymake(Answer_Max):-
findall((Place, Cost), costOfLiving(Place, Cost), ResultList),
delete_over(ResultList, Answer_Max).
costOfLiving
私のデータベースにあり、それぞれの場所とコストによって形成されます。例:
costOfLiving(germany, 500).
costOfLiving(france, 500).
等々。だからそれResultList
は[(germany, 500), (france, 500), ...]
costOfLiving
数を超えているデータベースのすべての要素を削除したいのですAnswer_Max
が、delete_overが正しく機能していません。これは次のようなものです。
delete_over([], _).
delete_over([F|T], Max) :-
F =.. [Place, Cost], % it fails here because the F is not a list, but two atoms I think
((id_state(Place), (Cost > Max)) -> deleteState(Place) ; true),
% id_state and id_region checks that the place is defined in the database
% deleteState and deleteRegion calls a specific retractall for the database
((id_region(Place), (Cost > Max)) -> deleteRegion(Place) ; true),
delete_over(T).
どうすればそれを解決して欲しいものを手に入れることができますか?(他の何かが間違っている場合にも)
私のソリューションで編集 (そして助けを借りて)
mymake(Answer_Max) :- % I don't need the ResultList, but if needed just add as second parameter
findall( (Place, Cost), ( costOfLiving(Place, Cost), Cost > Answer_Max ), ResultList ),
maketolist(ResultList).
maketolist([]).
maketolist([(P,_)|T]) :- % all the elements are for deleting as their Cost is higher than the Max given
(id_state(P) -> deleteState(P) ; true), % deleteState makes a retractall according to my needs on my database
(id_region(P) -> deleteRegion(P); true), % the same for deleteRegion with regions
maketolist(T).