List prefix suffix

Description

Prefixes and suffixes of a list

Source: The Art of Prolog

Download

Program source code: list_prefix_suffix.pl

Listing

/*
	prefix(Prefix,List) :- Prefix is a prefix of List.
*/
 
	prefix([],Ys).
	prefix([X|Xs],[X|Ys]) :- prefix(Xs,Ys).
 
/*
	suffix(Suffix,List) :- Suffix is a suffix of List.
*/
 
	suffix(Xs,Xs).
	suffix(Xs,[Y|Ys]) :- suffix(Xs,Ys).
 
%	Program 3.13: Prefixes and suffixes of a list

Comments

pl/prolog/pllib/list_prefix_suffix.txt · ostatnio zmienione: 2017/07/17 08:08 (edycja zewnętrzna)
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0