List Prolog-访问列表的第二项
我有个问题,我有这个:List Prolog-访问列表的第二项,list,prolog,List,Prolog,我有个问题,我有这个: start :- welcome, make_conf, undo. 请确认以下内容: make_conf :- interface, define_motherboard(Use, Price_range), define_processor(Use, Price_range, Best_processor, Price_bestprocessor, Best_motherboard)
start :- welcome,
make_conf,
undo.
请确认以下内容:
make_conf :-
interface,
define_motherboard(Use, Price_range),
define_processor(Use, Price_range, Best_processor, Price_bestprocessor, Best_motherboard),
...
定义处理器是这样的:
define_processor(Use, Price_range, Best_processor, Price_bestprocessor, Best_motherboard) :-
% find the best processor
setof(Score-Nome-Price,Price_range^Use^processor(Nome, Price, Price_range, Use, Score),Pairs2),
sort(1,@>,Pairs2,[_-Best_processor-Price_bestprocessor|Rest]),
%check compatibility between processor and motherboard
(motherboard_processor(Best_motherboard, Best_processor) -> write('');
choose_another_processor(Rest, Best_motherboard, Best_processor, Price_bestprocessor)),
write('proc2:'),write(Best_processor),nl.
choose_another_processor(Rest, Best_motherboard, Best_processor, Price_bestprocessor) :-
[_-Best_processor-Price_bestprocessor|Rest2] = Rest,
write('bestproc:'),write(Best_processor),nl,
(motherboard_processor(Best_motherboard,Best_processor) -> write('');
choose_another_processor(Rest2, Best_motherboard, Best_processor, Price_bestprocessor)).
问题在于选择另一个处理器,我应该检查列表第二项和主板之间的兼容性,但在打印bestproc之前我失败了,所以问题是这一行:
[_-Best_processor-Price_bestprocessor|Rest2] = Rest,
如果在
中选择另一个处理器
您想找到第二个最好的处理器,并且最好的处理器
及其价格已经被称为谓词的参数,那么这一行应该是[\uuu-Secondbest\uProcessor-price\usecondbestProcessor | Rest2]=Rest,
。要详细说明Isabelle的观点,[\uu-Best\u processor-Price\u bestprocessor | Rest2]=Rest
尝试将变量Rest
与术语[\uu-Best\u processor-Price\u bestprocessor | Rest2]统一起来
。为了使统一成功,Rest
必须是一个列表,其第一个元素能够与-Best\u processor-Price\u bestprocessor
统一。如果变量Best\u processor
和Price\u bestprocessor
已绑定到特定值,则这些变量必须与