列表阅读并将其传递给Prolog中的右子句Functor

时间:2015-06-02 08:06:54

标签: prolog

这是我的代码:

functor1(Action,[Action|_]) :-
    functor2(container(Action)). 
functor1(Action,[_|OtherActions]) :-
    functor1(Action,OtherActions).
functor2(container([Abc,Def])):- 
    append([Abc],[Def],Z),write(Z).

现在,当我尝试查询时,

functor1(X,[[first,   sign],[second, sign]]).

我对此查询的期望是,首先X应该阅读X = [first,sign],然后传递到functor2's容器,以便我的functor2可以发挥作用。但它不断给我false

1 个答案:

答案 0 :(得分:2)

对我来说似乎很好......问题是什么?

$ swipl
Welcome to SWI-Prolog (Multi-threaded, 64 bits, Version 7.1.37)
Copyright (c) 1990-2015 University of Amsterdam, VU Amsterdam
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to redistribute it under certain conditions.
Please visit http://www.swi-prolog.org for details.

For help, use ?- help(Topic). or ?- apropos(Word).

?- [f].
true.

?- functor1(X,[[first,   sign],[second, sign]]).
[first,sign]
X = [first, sign] ;
[second,sign]
X = [second, sign] ;
false.