AccDiff_p2 3 - Difference List Why is it called a...

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

View Full Document Right Arrow Icon
Difference List Why is it called a difference list? The name comes from list differences: [a,b,c,d,e] [d,e] = [a,b,c] [a,b,c|X]- X = [a,b,c] [L|Hole]- Hole= L for any list L and any list assigned to Hole The idea is to have a HOLE in the tail of a list to be instantiated later by Prolog. A list L is represented by the difference between another list in the form [L|Hole] and one of its sublists (the tail of the list, Hole) that must be an unknown. The empty list is represented by X-X [a,b,c] is represented by [a,b,c|X]-X York University- CSE 3401- V. Movahedi 22 06_AccDiff
Background image of page 1

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

View Full Document Right Arrow Icon
Reverse using difference lists reverse(L,R) :- rev(L, R-[]). rev([], W-W). rev([X|T], Z-W) :- rev(T, Z- [X|W]). :- reverse([a,b], R). :- rev([a,b], R-[]). :- rev([b], R-[a]). :- rev([], R- [b,a]). R=[b,a] Can reverse a list of n elements in n+2 resolution steps. York University- CSE 3401- V. Movahedi 23 06_AccDiff
Background image of page 2
Reverse using difference lists (cont.) reverse(L,R) :- rev(L, R-[]). rev([], W-W).
Background image of page 3

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

View Full Document Right Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 5

AccDiff_p2 3 - Difference List Why is it called a...

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

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