[ library(lists) | Reference Manual | Alphabetic Index ]

append(?List1, ?List2, ?List3)

Succeeds if List3 is the result of appending List2 to List1.
?List1
List or variable.
?List2
List or variable.
?List3
List or variable.

Description

Unifies List3 to the result of appending List2 to List1. On backtracking append/3 gives all possible solutions for List1 and List2, if both are uninstantiated.

The definition of this Prolog library predicate is:

append([],X,X).
append([X|L1],L2,[X|L3]):-
        append(L1,L2,L3).
This predicate does not perform any type testing functions.

Modes and Determinism

Fail Conditions

Fails if List3 does not unify with the result of appending List2 to List1.

Resatisfiable

Yes.

Examples

Success:
  append([1,2],L2,[1,2,3,4]). (gives L2=[3,4]).
  append([1,B],L2,[A,2,3,4]). (gives B=2 L2=[3,4] A=1).
  append([1,2],L2,L3).        (gives L2=_g70 L3=[1,2|_g70]).
  append([1]),[2,3]),L3).     (gives L3=[1,2,3]).

  [eclipse]: append(L1,L2,[1,2]), writeln((L1,L2)), fail.
  [] , [1, 2]
  [1] , [2]
  [1, 2] , []
  no (more) solution.
Fail:
  append(L1,[3],[1,2,3,4]).
  append(1,L2,[1,2]).


See Also

union / 3