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)
append([
Head
, Tail, List)].
No restrictions.
last(
?Fore,
?Last,
?List)
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)
tail(
List,
Tail)
prefix(
List,
Prefix)
proper_prefix(
List,
Prefix)
suffix(
List,
Suffix)
proper_suffix(
List,
Suffix)
segment(
List,
Segment)
proper_segment(
List,
Segment)
sublist/2
segment/2
proper_sublist/2
proper_segment/2