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_Search_Printing_Prolog_Items - Fatal编程技术网

List 为什么prolog不是';我不能打印这份名单

List 为什么prolog不是';我不能打印这份名单,list,search,printing,prolog,items,List,Search,Printing,Prolog,Items,下面我有一条序言规则 schedule(mary,[ma424,ma387,eng301]). 我有一个谓词 taking(X,Y):- schedule(X, [Y | L]). 当我试图通过打字找出她在上什么课时 taking(mary,Y). 我要走了 y=ma424 为什么不打印出她所有的课程 我也试过这个和其他的变体 taking(X,Y):- schedule(X,[X|L]),schedule(Y, [Y | L]),schedule(Y,L),X\=Y,X\=L. 但它

下面我有一条序言规则

schedule(mary,[ma424,ma387,eng301]).
我有一个谓词

taking(X,Y):- schedule(X, [Y | L]). 
当我试图通过打字找出她在上什么课时

taking(mary,Y).
我要走了 y=ma424

为什么不打印出她所有的课程

我也试过这个和其他的变体

taking(X,Y):- schedule(X,[X|L]),schedule(Y, [Y | L]),schedule(Y,L),X\=Y,X\=L.
但它不起作用


如何让它打印所有的类,给出规则的定义方式这是由于您定义谓词的方式

taking(X,Y) :-        % X takes class Y if...
    schedule(X,       % in the schedule for X,
             [Y|L]).  % Y is the first element.
如果您不告诉您的程序,它将不会神奇地决定搜索列表
L
。为此,请使用
成员/2
谓词:

taking(Student, Class) :-
    schedule(Student, Classes),
    member(Class, Classes).