我有:
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
超过 number的所有元素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).