Prolog - 访问列表的第二项

时间:2018-06-12 12:46:04

标签: list prolog

我有问题,我有这个:

start :- welcome,
         make_conf,
         undo.

make_conf是这样的:

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)).    

问题在于choose_another_processor,我应该检查列表的第二项和主板之间的兼容性,但是在打印bestproc之前我遇到了问题,所以问题是这一行:

[_-Best_processor-Price_bestprocessor|Rest2] = Rest,

0 个答案:

没有答案