Search code examples
prolog

How to restrict values of an argument in Prolog using a series of facts?


I want to restrict the query property(X, use, Y) to values of Y in the list [a,b,c]. c/1 is true for only those values of Y. I thought the following would work, but it doesn't.

c(a).
c(b).
c(c). 

property(X, use, Y).
c(Y).

The following statements yield only false.

     person(1).
     property(1, use, _).

I'm using Problog, but I'm not using any Problog functions here, so I think I am misunderstanding something about unification.

I thought c(Y) would generate the list and Y would be unified across the facts.

Update This does seem to be an Problog-specific issue as the following illustrates.

substance(methadone). 
substance(heroin).

P::property(X,use,nicotine) :-  %doesn't work
    property(X,use,Z),
    substance(Z),
    P is 0.8.

property(X,use,nicotine) :-  %works
    property(X,use,Z),
    substance(Z).

person(1).
substance(Y).
property(1, use, Y).

Solution

  • You can write:

    property(_X, use, Y) :-
        c(Y).