Page 1 of 1

List handling predicates and unification of variables

Posted: Fri Jul 18, 2008 10:57 am
by Victor NOEL
Hello,

I am currently playing with constraints and as they are manipulated using variables, I had a few problems using existing predicates for manipulating lists.

Some of them unify variables (=), some not, for example in list.lgt, they all unify variable, but sort/2 does not.

And in varlist.lgt, they are not unified (==).

In set.lgt, they seems to be unified ... and so on.

And some times, I don't want neither to unify them (=) nor just compare them (==) but I want to compare them without unifying them (=@= or maybe copy_term/2 (who keep the constraints but duplicate the variables) ?)

All of this is very complex, I am wondering what can be done to simplify all of this.

I don't have currently an answer to this, but maybe a discussion can take place on the subject.

It can be just a better documentation of the libraries, or maybe the creation of a library for each one of the kind of comparison/unification ...

Re: List handling predicates and unification of variables

Posted: Fri Jul 25, 2008 1:17 am
by Paulo Moura
Victor NOEL wrote: I am currently playing with constraints and as they are manipulated using variables, I had a few problems using existing predicates for manipulating lists.

Some of them unify variables (=), some not, for example in list.lgt, they all unify variable, but sort/2 does not.
Currently, the library predicate sort/2 simply uses the Prolog built-in sort predicate.
Victor NOEL wrote: And in varlist.lgt, they are not unified (==).

In set.lgt, they seems to be unified ... and so on.

And some times, I don't want neither to unify them (=) nor just compare them (==) but I want to compare them without unifying them (=@= or maybe copy_term/2 (who keep the constraints but duplicate the variables) ?)

All of this is very complex, I am wondering what can be done to simplify all of this.
One option is defining a parametric object whose parameter would be the predicate that should be used to compare two list elements. Of course, this implies the use of meta-calls with the consequent performance penalties. However, if you limit the possible parameter values, you could go for a simpler solution that does not imply meta-calls. Another option would be to define specialized versions of the library "list" predicate, as you suggested.

Cheers,

Paulo