Advertisement Jump to content
Sign in to follow this  

Prolog Question

This topic is 3647 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am trying to formulate a simple dependency expression in Prolog after not having used it for a long time. I express two facts and a rule.
a( 1).
a( 2).
b( X) :- a( X), a( X + 1).
testing this gives no match
  ?- b( What).
My intention is that b( What) should match when What = 1 as the only case, since both a(1) and a(2) are satisfied. I am using Yap, and while the manual indicates that it supports arithmetic operators like '+' I suspect that I am doing something wrong conceptually.

Share this post

Link to post
Share on other sites
AFAIK prolog arithmetics are done through the 'is' operator, so you would have to do something like this:

b(X) :- a(X), Y is X + 1, a(Y).

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!