Różnice

Różnice między wybraną wersją a wersją aktualną.

Odnośnik do tego porównania

pl:prolog:pllib:sublists [2019/06/27 15:50] (aktualna)
Linia 1: Linia 1:
 +====== Sublists ======
 +{{tag>​lists}}
 +===== Description =====
 +Determining sublists of lists
 +
 +**Source**: ​ The Art of Prolog
 +===== Download =====
 +Program source code: {{sublists.pl}}
 +===== Listing =====
 +<code prolog>
 +/*
 + sublist(Sub,​List) :- Sub is a sublist of List.
 +*/
 +/*
 + 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).
 +
 + % a: Suffix of a prefix
 + sublist(Xs,​Ys) :- prefix(Ps,​Ys),​ suffix(Xs,​Ps).
 +
 + % b: Prefix of a suffix
 + sublist(Xs,​Ys) :- prefix(Xs,​Ss),​ suffix(Ss,​Ys).
 +
 + % c: Recursive definition of a sublist
 + sublist(Xs,​Ys) :- prefix(Xs,​Ys).
 + sublist(Xs,​[Y|Ys]) :- sublist(Xs,​Ys).
 +
 + % d: Prefix of a suffix, using append
 + sublist(Xs,​AsXsBs) :-
 + append(As,​XsBs,​AsXsBs),​ append(Xs,​Bs,​XsBs).
 +
 + % e: Suffix of a prefix, using append
 + sublist(Xs,​AsXsBs) :-
 + append(AsXs,​Bs,​AsXsBs),​ append(As,​Xs,​AsXs).
 +
 +% Program 3.14: Determining sublists of lists
 +</​code>​
 +===== Comments =====
  
pl/prolog/pllib/sublists.txt · ostatnio zmienione: 2019/06/27 15:50 (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