[ library(lists) | Reference Manual | Alphabetic 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]).
   This predicate does not perform any type testing functions.
	
Modes and Determinism
Fail Conditions
   Fails if Reverse does not unify with the reversed version of List.
Resatisfiable
   No.
Examples
Success:
    [eclipse]: reverse([1,2,3,4,5], X).
    X = [5, 4, 3, 2, 1]
    yes.
See Also
append / 3, member / 2