Documentation Prolog Predicate Reference lists last/2

last/2

Last element of a list.

Description

last( ?list, ?last )

last(List, Last) is true if and only if Last is the last element on the list List.

Examples

Example #1 Example of last/2

?- last([1,2,3], 3). % true. ?- last([1,2,3], 4). % false. ?- last(List, 3). % List = [3] ; % List = [_2, 3] ; % List = [_2, _6, 3] ; % List = [_2, _6, _10, 3] ; % ... ?- last([1,2,3], Last) % Last = 3.

Implementation