Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
186 views
in Technique[技术] by (71.8m points)

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).
question from:https://stackoverflow.com/questions/65862141/how-to-restrict-values-of-an-argument-in-prolog-using-a-series-of-facts

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can write:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...