append(?List1, ?List2, ?List1_then_List2)succeeds if
List2 = List1_then_List2. Examples:
?- append([a, b], [c, d, e], Result). Result = [a, b, c, d, e]. true. ?- append([a, b], SecondBit, [a, b, c, d, e]). SecondBit = [c, d, e] true. ?- append(FirstBit, [c, d, e], [a, b, c, d, e]). FirstBit = [a, b] true.
A not uncommon beginner's mistake is to use
append([Head], Tail, List)
to build a list
instead of something like
List = [Head | Tail].
This will work, but is like using a bulldozer to dig a
hole to plant out a seedling.
Note: there is also an unrelated version of
that takes a single parameter. This is described under
files, and is referred to as
append/1 - i.e. 1 argument,
append in this article is referred
append/3 - 3 arguments.