Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
List Prolog-访问列表的第二项_List_Prolog - Fatal编程技术网

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
已绑定到特定值,则这些变量必须与的第一个元素匹配ode>Rest成功统一。如果他们不统一,统一将失败。谢谢你们,成功了!