Recent Changes - Search:

edit SideBar

ConstraintsOnLists

The file list_constraints.ecl contains sample implementations of these constraints on lists:

len(List,Length)
a constraint version of the length/2 built-in predicate
app(Xs,Ys,Zs)
a constraint version of the append/3 predicate
left(Xs,LeftLength,Ls)
constrains Ls to contain the leftmost LeftLength elements of Xs
right(Xs,RightLength,Rs)
constrains Rs to contain the rightmost RightLength elements of Xs
min(Xs,Pos,Length,Ms)
constrains Ms to contain the Length elements of Xs starting at position Pos
sub(Xs,Before,Length,After,Ms)
constrains Ms to contain a sublist of Xs of length Length, such that there are Before elements in Xs before and After elements after

These predicates all delay instead of making choices. They propagate changes in the list skeletons and the length bounds. Lengths are represented as lib(ic) integer variables.

Basic examples:

?- len([a, b, c|Xs], L).
L = L{3 .. 1.0Inf}
There is 1 delayed goal.
Yes (0.00s cpu)

?- len([a, b, c|Xs], L), L = 5.
Xs = [_529, _533]
L = 5
Yes (0.00s cpu)

?- app([1, 2|Xs], [4, 5|Ys], Zs).
Xs = Xs
Ys = Ys
Zs = [1, 2, _272, _274|_327]
There is 1 delayed goal.
Yes (0.00s cpu)

?- app([1, 2|Xs], [4, 5|Ys], Zs), len(Zs,5).
Zs = [1, 2, _106, _108, _110]
There is 1 delayed goal.
Yes (0.00s cpu)

?- app([1, 2|Xs], [4, 5|Ys], Zs), len(Zs,5), Ys = [].
Xs = [_107]
Ys = []
Zs = [1, 2, _107, 4, 5]
Yes (0.00s cpu)
Edit - History - Print - Recent Changes - Search
Page last modified on January 08, 2016, at 02:10 AM