Re: Boundary conditions
Alan Baljeu <[email protected]>
| Newsgroups | gmane.comp.ai.prolog.swi |
|---|---|
| Message-ID | <[email protected]> |
> uniques_list(Control, [X|Check], Unique0, Unique) :- > \+ member(X, Control), > !, % you need this so the next clause isn't tried. > Unique0 = [X|Unique1], > uniques_list(Control, Check, Unique1, Unique). > >*The theory (and Alan Baljeu) say that the cut is needed here but even >without the !, my procedure now works fine. Is this just plain luck?* To illustrate that it doesn't work fine without the cut, try this query: ?- uniques_list([1,2,3,4], [4,5,6], Unique), length(Unique, 1). You expect a list of 2 elements, but this gives a list of 1. This is because your program, without the cut, has multiple potential solutions, and Prolog will try each of them until something succeeds. -------------- next part -------------- HTML attachment scrubbed and removed