Jump to content
  • Advertisement
Sign in to follow this  
chairthrower

Prolog Question

This topic is 3410 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).
no
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
Advertisement
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 GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!