[ ECLiPSe Lists Library predicate.|Group Index| Full Index]

union(+List1, +List2, ?Union)

Succeeds if Union is the list which contains the union of elements in List1 and those in List2.

+List1
List.
+List2
List.
?Union
List or variable.

Description

Used to create the list of elements in List1 and not in List2, added to those in List2.

The definition of this Prolog library predicate is:

union([], L, L).
union([Head|L1tail], L2, L3) :-
        memberchk(Head, L2),
        !,
        union(L1tail, L2, L3).
union([Head|L1tail], L2, [Head|L3tail]) :-
        union(L1tail, L2, L3tail).
The following should be noted;

1. This predicate does not perform any type testing functions.

2. This predicate is not protected by ECLiPSe and may be redefined without generating a warning message.

3. This predicate works properly for set operations only, so repeated elements and variable elements should not be used.

Fail Conditions

Fails if Union does not unify with the list which contains the union of elements in List1 and those in List2.

Resatisfiable

No.

Exceptions

Examples


Success:
      union([1,2,3],[1,3],L).     (gives L=[2,1,3]).

Fail:
      union([1,2,3,2],[1,3],[1,2,3]).  % repeated elements


See Also

subtract / 3, intersection / 3