swipl 在遇到列表中的变量时出错

swipl gives an error on encountering variables in lists

代码:

[mia, vincent, jules, yolanda]. 
[mia, [vincent, jules], [butch, girlfriend(butch)]].

% uncommenting the below line gives an error: 
% [mia, vincent, X]. 

根据我的书和互联网上的不同网站,在序言列表中包含变量是完全没问题的,但在加载上述知识库时我收到以下错误:

ERROR: /home/user/Prolog/det/lists.pl:7:
        Arguments are not sufficiently instantiated
ERROR: /home/user/Prolog/det/lists.pl:7:
        Arguments are not sufficiently instantiated
        In:
   Arguments are not sufficiently instantiated
   Arguments are not sufficiently instantiated
        In:
          [31] throw(error(instantiation_error,_4850))

 [27] '$load_file'('/home/user/Prolog/det/lists.pl','/home/user/Prolog/det/lists.pl',_4878,[expand(false),...]) at /usr/lib/swi-prolog/boot/init.pl:2507
          [26] setup_call_catcher_cleanup(system:true,system:'$load_file'('/home/user/Prolog/det/lists.pl','/home/user/Prolog/lab4/lists.pl',_4946,...),_4924,system:'$end_consult'(...,user)) at /usr/lib/swi-prolog/boot/init.pl:443
          [22] '$do_load_file_2'(lists,'/home/user/Prolog/lab4/lists.pl',user,compiled,[expand(false),...]) at /usr/lib/swi-prolog/boot/init.pl:2124
          [19] '$mt_do_load'(<clause>(0x55a555ed3400),lists,'/home/user/Prolog/lab4/lists.pl',user,[expand(false),...]) at /usr/lib/swi-prolog/boot/init.pl:2070
          [18] setup_call_catcher_cleanup(system:with_mutex('$load_file',...),system:'$mt_do_load'(<clause>(0x55a555ed3400),lists,'/home/user/Prolog/det/lists.pl',user,...),_5084,system:'$mt_end_load'(<clause>(0x55a555ed3400))) at /usr/lib/swi-prolog/boot/init.pl:443
           [7] <user>

在列表中包含变量当然没问题,但列表需要放在上下文中。

只写[mia, vincent, jules, yolanda].其实是加载文件的快捷方式,如consult/1.

您必须使用这些列表作为术语的参数,例如:

list_of_people([mia, vincent, jules, yolanda]).

也许写得更好

person(mia).
person(vincent).
person(jules).
person(yolanda).

然后收藏

?- bagof(P,person(P),PersonList).
PersonList = [mia,vincent,jules,yolanda].