Parts of lists -- library(listparts)

library(listparts) exists to establish a common vocabulary for names of parts of lists among Prolog programmers. You will seldom have occasion to use head/2 or tail/2 in your programs -- pattern matching is clearer and faster -- but you will often use these words when talking about your programs. The predicates provided are


cons(?Head, ?Tail, ?List)
Head is the head of List and Tail is its tail; i.e. append([Head, Tail, List)]. No restrictions.
last(?Fore, ?Last, ?List)
Last is the last element of List and Fore is the list of preceding elements, e.g. append(Fore, [Last, List)]. Fore or Last should be proper. It is expected that List will be proper and Fore unbound, but it will work in reverse too.

The remaining predicates are binary, and part(Whole, Part) is to be read as "Part is the/a part of Whole". When both part/2 and proper_part/2 exist, proper parts are strictly smaller than Whole, whereas Whole may be a part of itself. N is the length of the whole argument, assumed to be a proper list. This order is strictly in accord with the fundamental principle of argument ordering in Prolog: INPUTS BEFORE OUTPUTS.


head(List, Head)
List is a non-empty list and Head is its head. A list has only one head. No restrictions.
tail(List, Tail)
List is a non-empty list and Tail is its tail. A list has only one tail. No restrictions.
prefix(List, Prefix)
List and Prefix are lists and Prefix is a proper prefix of List.
proper_prefix(List, Prefix)
List and Prefix are lists and Prefix is a proper prefix of List. That is, Prefix is a prefix of List but is not List itself. It terminates if either argument is proper, and has at most N solutions. Prefixes are enumerated in ascending order of length.
suffix(List, Suffix)
List and Suffix are lists and Suffix is a suffix of List. It terminates only if List is proper, and has at most N+1 solutions. Suffixes are enumerated in descending order of length.
proper_suffix(List, Suffix)
List and Suffix are lists and Suffix is a proper suffix of List. That is, Suffix is a suffix of List. It terminates only if List is proper, and has at most N+1 solutions. Suffixes are enumerated in descending order of length.
segment(List, Segment)
List and Segment are lists and Segment is a sublist of List.
proper_segment(List, Segment)
List and Segment are lists and Segment is a proper sublist of List.
sublist/2
same as segment/2
proper_sublist/2
same as proper_segment/2