Re: clpfd constraints not taking effect

Markus Triska <[email protected]>
Newsgroups gmane.comp.ai.prolog.swi
Message-ID <[email protected]>
Hi James,

James Hogan <[email protected]> writes:

> Ah, I think I get it, so in the apply_preargs example, SWI's shallow
> look at apply_preargs sees the latter two functors as taking the same
> argument types, so it has to remember it in case the first fails or
> other solutions required.

Yes, with your current version, the second argument of both clauses is a
term of the form [_|_] (functor '.', arity 2), so SWI's current, shallow
indexing cannot distinguish them, and choice-points are left behind.
Relatedly, tail call optimization cannot be applied as a consequence.

>>    ?- person(enosh).
>>    true ;
>>    true ;
>>    false.
>
> yes, I've been trying to get rid of these cases, especially the final
> false (which now makes much more sense).

It probably makes sense to precompute the definition of person/1 before
your actual constraint solving: You can use setof/3 to collect
everything you consider a person, using the various rules you defined,
and then use assertz/1 to create a single clause for each person. This
makes further uses of person/1 deterministic when the argument is bound.

All the best,
Markus
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.