Subject: RE: [SWIPL] constraint library?

From: "Douglas R. Miles" <[email-masked]>
Date: Sun, 10 Jun 2001 04:37:15 -0700

Sebastian,

There are not any prologs that I am aware of that supports argument type
checking on predicates (as part of it's kernel).  This is ussually something
we must do ourselves gladly.  If an implementor was to make this part of the
prolog kernel it would potentually create overhead for non typed problems.
Or potentually would not give ususers enough control on how it is done.

Its not too hard to implement as you can see in this simple example bellow:

% nth_domain(+Predicate,+Argument,+Collection)
nth_domain(loves,1,agent).
nth_domain(loves,2,entity).
nth_domain(covets,1,agent).
nth_domain(covets,2,entity).
nth_domain(friends,1,agent).
nth_domain(friends,2,agent).
nth_domain(enemy,1,agent).
nth_domain(enemy,2,agent).

nth_domain(instance_of,1,entity).
nth_domain(instance_of,2,collection).

instance_of(mark,agent).
instance_of(jake,agent).
instance_of(sue,agent).
instance_of(car,entity).
instance_of(X,Class):-subclass_of(Subclass,Class),instance_of(X,Subclass).

subclass_of(agent,entity).

loves(john,car).
enemy(john,jake).

covets(Who,What):-enemy(Who,Someone),loves(Someone,What).

my_call((X,Y)):-my_call(X),my_call(Y).
my_call((X;Y)):-my_call(X);my_call(Y).
my_call(G):-constrained_call(G)

constrained_call(G):-possible(G),chain(G).
constrained_call(not(G)):-possible(G),not(chain(G)).

chain(G):- clause(G,Ants),my_call(Ants).
chain(G):- G.

possible(X):-X=..[F|ARGS],nth_dom_check(F,0,ARGS).

nth_dom_check(_,_,[]).
nth_dom_check(F,N,[A|RGS]):-
		nth_domain(F,N,Class),
		instance_of(A,Class),
		NN is N +1 ,nth_dom_check(F,NN,RGS).

|?- loves(X,Y).

X = john
Y = car

|?- my_call(covets(X,Y)).
...
|?- my_call(non(covets(X,Y))).
...
etc

Douglas

> -----Original Message-----
> From: Sebastian Sardina [mailto:[email-masked]]
> Sent: Friday, June 08, 2001 5:54 AM
> To: Douglas R. Miles
> Subject: Re: [SWIPL] constraint library?
> 
> 
> YES! that's what I want..
> does SWI have something like that? mmm I think it does not right?
> 
> thanks
> 
> sebastian
> 
> "Douglas R. Miles" wrote:
> > 
> > Sebastian,
> > 
> > Are you refering to argument type constraints for 
> predicates?  So one can
> > use a therotical type ontology to define limited 
> possiblities for unbound
> > prolog varibles?
> > 
> > Douglas
> > 
> > > -----Original Message-----
> > > From: Sebastian Sardina [mailto:[email-masked]]
> > > Sent: Thursday, June 07, 2001 1:29 PM
> > > To: [email-masked]
> > > Subject: [SWIPL] constraint library?
> > >
> > >
> > > I have asked this question before.
> > >
> > > Does SWI have any constraint library or module?
> > >
> > > Thanks
> > >
> > > Sebastian
> > >
> > >
> > > ----------------
> > > * To UNSUBSCRIBE, please use the HTML form at
> > >
> > >
> > > 
> http://www.swi.psy.uva.nl/projects/SWI-Prolog/index.html#mailinglist
> > >
> > > or send mail to [email-masked] using the
> > > Subject: "unsubscribe"
> > > (without the quotes) and *no* message body.
> > >
> > > ** An ARCHIVE of this list is maintained at
> > >
> > >     
> http://www.swi.psy.uva.nl/projects/SWI-Prolog/mailinglist/archive/
> > >
> > >
> > >
> 
>