Re: [eclipse-clp-users] Implying Initial Domains for Certain Arguments of Predicates

From: Joachim Schimpf <>
Date: Fri, 2 Oct 2015 22:49:54 +0100
On 02/10/15 14:48, Gkhan Solak wrote:
> Hello,
> First of all, I would like to inform that I'm a novice in Prolog.
> What I want to do is to imply predefined domains for the variables which takes
> part in arguments of certain predicates.
> For example, for the custom predicate *age( A, X)*, which means in my model
> /"age of the object A is X"/, it follows that X is an integer. Moreover if A is
> a human, domain of X is [1,130] (broadly speaking).
> In predicate logic with constraints, I think this can be defined by the
> following clauses:
> age(A, X) -> integer(X).
> age(A, X) and human(A) -> X  [1,130].
> I translated this into Prolog program as:
> integer(X) :- age( _, X).
> X :: 1..130 :- age( _A, X), human( _A).
> age/2 and human/1 are defined in the same file. lib(ic) is imported.

You should probably start with some further reading on Prolog, in particular
the differences between a predicate definition and a goal/query.  What you
write on the left hand side of :- is what you *define*.  When you write

   integer(X) :- age( _, X).

you are defining a predicate integer/1 by saying that for every X, if X is
an age, then it is an integer.  While this statement may be true, it is is
certainly not the definition of what an integer is.  And of course the
system already knows what an integer is, you don't need to define that.

It is not completely clear to me what you want to achieve, but you may
try to define database-style predicates like the following:

   lifespan(human,    Age) :- Age :: 0..130.
   lifespan(mouse,    Age) :- Age :: 0..4.
   lifespan(tortoise, Age) :- Age :: 0..200.

   type(fred, human).
   type(wilma, human).
   type(toto, tortoise).
   type(charlie, mouse).

then you can ask queries like

?- X = charlie, type(X, T), lifespan(T, A).
X = charlie
T = mouse
A = A{0 .. 4}
Yes (0.00s cpu)

Received on Fri Oct 02 2015 - 21:50:11 CEST

This archive was generated by hypermail 2.2.0 : Tue Oct 06 2015 - 21:13:14 CEST