.\" ------------------------- seca3.t ----------------------- .sh 1 "Other Library Utilities" .pp The SB-Prolog library contains various other utilities, some of which are listed below. .lp \fB$append\fR(\fIX\fR, \fIY\fR, \fIZ\fR) .ip Succeeds if list \fIZ\fR is the concatenation of lists \fIX\fR and \fIY\fR. .(x b (L) $append/3 .)x .lp \fB$member\fR(\fIX\fR, \fIL\fR) .ip Checks whether \fIX\fR unifies with any element of list \fIL\fR, succeeding more than once if there are multiple such elements. .(x b (L) $member/2 .)x .lp \fB$memberchk\fR(\fIX\fR, \fIL\fR) .ip Similar to $\fImember\fR/2, except that $\fImemberchk\fR/2 is deterministic, i.e. does not succeed more than once for any call. .lp \fB$reverse\fR(\fIL\fR, \fIR\fR) .ip Succeeds if \fIR\fR is the reverse of list \fIL\fR. If \fIL\fR is not a fully determined list, i.e. if the tail of \fIL\fR is a variable, this predicate can succeed arbitrarily many times. .(x b (L) $reverse/2 .)x .lp \fB$merge\fR(\fIX\fR, \fIY\fR, \fIZ\fR\^) .ip Succeeds if \fIZ\fR is the list resulting from ``merging'' lists \fIX\fR and \fIY\fR, i.e. the elements of \fIX\fR together with any element of \fIY\fR not occurring in \fIX\fR. If \fIX\fR or \fIY\fR contain duplicates, \fIZ\fR may also contain duplicates. .(x b (L) $merge/3 .)x .lp \fB$absmember\fR(\fIX\fR, \fIL\fR\^) .ip Similar to \fI$member\fR/2, except that it checks for identity (through ==/2) rather than unifiability (through =/2) of \fIX\fR with elements of \fIL\fR. .(x b (L) $absmember/2 .)x .lp \fB$nthmember\fR(\fIX\fR, \fIL\fR, \fIN\fR) .ip Succeeds if the \fIN\fR\*[th.\*] element of the list \fIL\fR unifies with \fIX\fR. Fails if \fIN\fR is greater than the length of \fIL\fR. Either \fIX\fR and \fIL\fR, or \fIL\fR and \fIN\fR, should be instantiated at the time of the call. .(x b (L) $nthmember/3 .)x .lp \fB$member2\fR(\fIX\fR, \fIL\fR) .ip Checks whether \fIX\fR unifies with any of the actual elements of \fIL\fR. The only difference between this and \fI$member\fR/2 is on lists with a variable tail, e.g. [a, b, c | _ ]: while \fI$member\fR/2 would insert \fIX\fR at the end of such a list if it did not find it, \fI$member2\fR/2 only checks for membership but does not insert it into the list if it is not there. .lp \fBlength\fR(\fIL\fR, \fIN\fR\^) .(x b (L) length/2 .)x .ip Succeeds if the length of the list \fIL\fR is \fIN\fR. This predicate is deterministic if \fIL\fR is instantiated to a list of definite length, but is nondeterministic if \fIL\fR is a variable or has a variable tail. .lp \fBsubsumes\fR(\fIX\fR, \fIY\fR\^) .(x b (L) subsumes/2 .)x Succeeds if the term \fIX\fR subsumes the term \fIY\fR (i.e. if \fIY\fR is an instance of \fIX\fR). .\" ----------------------- end of section seca3.t -----------------------