prefix(+PrefixList, ?List)
prefix(?PrefixList, +List)

Determine if a list is a prefix of another List (second parameter). If the first parameter is a variable then prefix/2 will produce the next possible prefix of a list per call to prefix/2.

This predicate is located in the file 'list.txt', use ensure_loaded/1 to include this file.

see also: conc/3 del/3 largest_number/2 last/2 lengthlist/2 member/2 reverse/2 smallest_number/2 sublist/2 suffix/2 sum_list/2 sum_list_integer/2

Example
prefix([], []). succeeds because [] is a prefix of the list []
prefix([], [a]). succeeds because [] is a prefix of the list [a]
prefix([a], [a, b]). succeeds because [a] is a prefix of the list [a, b]
prefix([b], [a, b]). fails because [b] is not a prefix of the list [a, b]
prefix(A, [a, b]). succeeds and per call to prefix/2 another possible prefix of [a, b] is unified with the variable A:
A=[]

A=[a]

A=[a, b]

 

 

info@trinc-prolog.com