Re: [eclipse-clp-users] Problem formulating simple ic_sets test

From: Joachim Schimpf <joachim.schimpf_at_infotech.monash.edu.au>
Date: Fri, 07 Aug 2009 10:47:28 +0100
David Pautler wrote:
> I'm new to ECLiPSe, and I'm trying simple tests to acquaint myself with
> its features. In this test, I'm experimenting with a variable representing
> a member of a finite set. My understanding is that I should be able to
> define the set, then create a variable representing a member, and then use
> that variable to reduce the size of the search space for a query (compared
> to using a simple variable and then testing the variable after it's
> bound).
> 
> In this test, I expected to limit the search for my atLoc/3 query to just
> those atLoc clauses whose 3rd arg is in the set {1917,1918,1919}.
> 
> Why does the query fail?
> 
> 
> ?- lib(ic_sets), assert(atLoc(blueObj, 32, 1918)), TargetObjPos :: [] ..
> [1917, 1918, 1919], atLoc(TargetObjId, EndingFrameId, TargetObjPos).
> No


Hi David,

you seem to want a simple integer-valued variable.  Just use lib(ic):

?- lib(ic).
Yes (0.58s cpu)

?- X :: [1917, 1918, 1919], X = 1918.
X = 1918
Yes (0.00s cpu)

?- X :: [1917, 1918, 1919], X = 1916.
No (0.00s cpu)


The library lib(ic_sets) that you have used implements set-valued
variables, which can be instantiated to lists of integers:

?- lib(ic_sets).
Yes (0.91s cpu)

?- X in_set_range []..[1917,1918,1919], X = [1918, 1919].
X = [1918, 1919]
Yes (0.00s cpu)

The variable here can take any set (=ordered list) value that
is a superset of [] and subset of [1917,1918,1919].
Note that the use of ic_set's version of :: is deprecated because of
the confusingly similar but different semantics that you have noticed.


Generally, have a look at the tutorial http://eclipse-clp.org/doc/tutorial/
and the examples at http://eclipse-clp.org/examples



-- Joachim
Received on Fri Aug 07 2009 - 09:47:58 CEST

This archive was generated by hypermail 2.2.0 : Thu Feb 02 2012 - 02:31:58 CET