Lists_Part_3 - prefix(P, L):- append(P, _, L). Is a prefix...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
Append Join two lists: Example: append([1,2], [3,4], [1,2,3,4]) append([], L, L). : boundary condition append([X|L1], L2, [X|L3]) :- append(L1, L2, L3). : recursive case a smaller problem Possible Queries: [Nilsson] :- append([a, b], [c, d], [a, b, c, d]). true :- append([a, b], [c, d], X). X=[a, b, c, d] or even :- append(Y, Z, [a, b, c, d]). York University- CSE 3401 11 05_Lists
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Search tree for append query append([], X, X). append([X|Y], Z, [X|W]) :- append(Y, Z, W). :- append(Y, Z, [a, b, c, d]). York University- CSE 3401 12 05_Lists
Background image of page 2
Prefix with append The list P is a prefix of L, if L can be obtained by appending P to another list. Write prefix(P,L) which is true if P is a prefix of L.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 4
Background image of page 5
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: prefix(P, L):- append(P, _, L). Is a prefix of L? York University- CSE 3401 13 05_Lists Suffix with append The List S is a suffix (or postfix) of L if L can be obtained by appending some other list with S. Write suffix(S,L) which is true if S is a suffix of L suffix(S,L):- append(_, S, L). Exercise: Try writing prefix and suffix without using append. York University- CSE 3401 14 05_Lists More Examples with append sublist(S,L) is true if S is a sublist of L in other words, S is the suffix of a prefix Using append(. .): sublist(S,L):- append(_, S, Left), append(Left, _, L). York University- CSE 3401 15 05_Lists...
View Full Document

Page1 / 5

Lists_Part_3 - prefix(P, L):- append(P, _, L). Is a prefix...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online