Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8772219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:59:10+00:00 2026-06-13T17:59:10+00:00

I have a simple predicate in prolog that when MaxScore >0, it gives yes,

  • 0

I have a simple predicate in prolog that when MaxScore >0, it gives yes, otherwise is no. So if MaxScore is 0, then obviously the result is No. But this doesn’t happen. Look closer at this: https://dl.dropbox.com/u/18710637/prologIsInsane.png

Or corresponding code:

aiPlay(PlayerNum, Board, Pos, BotType) :-
    aiTryAll(Board, PlayerNum, ScoreList, 0),
    scoreListGetPos(ScoreList, 1, Pos, MaxScore),
    write('MaxScore: '), write(MaxScore), nl,
    MaxScore > 0.

And corresponding output:

| ? myQuery(Pos).
MaxScore: 0
MaxScore: 0
MaxScore: 1
Pos = 6 ?
yes
| ?

I am getting insane with this. Anyone have a clue about what is happening?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T17:59:11+00:00Added an answer on June 13, 2026 at 5:59 pm

    There isn’t really a problem; consider this code:

    foo(0).
    foo(0).
    foo(1).
    
    bar:-
        foo(X),
        write(X), nl,
        X > 0.
    

    Prolog will first unify X with 0 (from the first foo(0)), will print the output and then fail since 0 > 0 is false. Then prolog will backtrack and pick the second foo(0); again the same. Finally, X will be unified with 1 and bar will return true.

    Naturall, side-effects like printing cannot be reversed/backtracked, so in the terminal you will see:

    0
    0
    1
    true
    

    How you solve it depends on what you want to do; if you want to print just Max Core = 1 then you can do the printing after you check if MaxScore>0. Generally though, it’s better to do the printing (if it’s required) at the very end, and not in a predicate deep in the program.

    Oh, by the way, it’s better to post the actual code and the output instead of a screenshot; it makes it easier to copy-paste-debug your code. Also, it is advised to give a runnable example: half of the predicates you use in aiPlay/4 are undefined so I’m just guessing that the problem is what I mentioned above :p

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple predicate function that follows as: [totalSentences addObjectsFromArray:[firstLangEx filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@(SELF contains[c]
I'm in the process of learning Prolog. I have this recursive predicate: add(0,Y,Y). add(succ(X),Y,succ(Z))
If I have a simple predicate in the database, is there a way that
I'm having some trouble writing a relatively simple predicate in Prolog. This predicate is
I want a simple predicate that returns me all the groups which have mode
I have simple php validation form that is halfway working. If you leave the
I have simple win service, that executes few tasks periodically. How should I pass
I have a simple base entity type called EntityBase that implements IEquatable<EntityBase>. I've used
I have a very simple app that has one CoreData Entity with a circular
It is probably pretty simple but I cannot figure it out: Say I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.