Prolog append with cut operator

前端 未结 4 1498
别跟我提以往
别跟我提以往 2020-12-01 17:07

What problem can occur when we use append with cut operator?

   append2([],L,L):-!.
   append2([H|T],L,[H|TL]):-append2(T,L,TL).

I have tri

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-01 17:43

    It won't work when the first two arguments are variable:

    ?- append(X, Y, [1, 2, 3]).
    X = [],
    Y = [1, 2, 3] ;
    X = [1],
    Y = [2, 3] ;
    X = [1, 2],
    Y = [3] ;
    X = [1, 2, 3],
    Y = [] ;
    false.
    
    ?- append2(X, Y, [1, 2, 3]).
    X = [],
    Y = [1, 2, 3].
    

提交回复
热议问题