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

reverse(+List, ?Reversed)

Succeeds if Reversed is the reversed list List.

+List
Ground List.
?Reversed
List or variable.

Description

The List is reversed and the resulting list is unified with Reverse.

The definition of this Prolog library predicate is:

reverse(List, Rev) :-
        reverse(List, Rev, []).

reverse([], L, L).
reverse([H|T], L, SoFar) :-
        reverse(T, L, [H|SoFar]).
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.

Fail Conditions

Fails if Reverse does not unify with the reversed version of List.

Resatisfiable

No.

Exceptions

Examples


Success:
    [eclipse]: reverse([1,2,3,4,5], X).
    X = [5, 4, 3, 2, 1]
    yes.



See Also

append / 3, member / 2