简体   繁体   English

初始化列表的序言长度将新列表添加到现有列表

[英]Prolog length to initialize list adds new List to existing Lists

puzzle(ListToAdd,ListToAdd1,Res,_,Carry) :-
   length(Res,ResultLength),
   length(Carry,ResultLength),
   domain(Carry,0,1).

First I use length to get the size of the Res list (ResultLength) and then I will use ResultLength to initialize the other list, Carry. 首先,我使用length获取Res列表的大小(ResultLength),然后使用ResultLength初始化另一个列表Carry。 However after I do that both ListoAdd and ListToAdd1 now have the aforementioned Carry list in them, which I belive it shouldn´t happen. 但是,在我这样做之后,ListoAdd和ListToAdd1现在都包含了上述的“携带”列表,我相信这应该不会发生。

Query done: puzzle([D,O,N,A,L,D],[G,E,R,A,L,D],[R,O,B,E,R,T],X,L).


        Before  length(Carry,ResultLength):
        write(ListToAdd):  [_5459,_5499,_5539,_5319]
        write(ListToAdd1): [_5199,_5239,_5279,_5319]

        After  length(Carry,ResultLength):
       write(Carry):      [_12043,_12107,_12171,_12235]
       write(ListToAdd):  [_5459,_5499,_5539, [_12043,_12107,_12171,_12235],_5319]
       write(ListToAdd1): [_5199,_5239,_5279, [_12043,_12107,_12171,_12235],_5319]

I´m using SICStus Prolog 4.3.2. 我正在使用SICStus Prolog 4.3.2。

Does anyone know what's happening? 有人知道发生了什么吗?

The reason for the troubles you are experiencing is this: 您遇到麻烦的原因是:

?- puzzle([D,O,N,A,L,D],[G,E,R,A,L,D],[R,O,B,E,R,T],X,L).

Got it? 得到它了? If not, consider: 如果没有,请考虑:

?- puzzle([D,O,N,A,L,D],[G,E,R,A,L,D],[R,O,B,E,R,T],X,L).
                   ^             ^                    ^
                   +-------------+--------------------+

Those logical variables:) 那些逻辑变量:)

HTH! HTH!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM