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 8014725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:01:48+00:00 2026-06-04T20:01:48+00:00

After I have seen these question , I have tried to solve below problem.

  • 0

After I have seen these question, I have tried to solve below problem. But I could not solve it. Can anyone help me ?

predefined :

   foo( X, Y )        bar( Y, Z )
        ^  ^               ^  ^
      all of them is atomic, that is they only return or take one value at a time

   sample example:

      foo(john, brad).
      bar(john, marry).

      foo( Y, brad)   

      Y = john   % after pressing a, all possibilities will be seen at terminal

      bar(Y, Z )

      Z = marry  % after pressing a, all possibilities will be seen at terminal

   %..................

For these case how can I run bar with all possibilities of Y, resulted after eash run of foo ?

  • 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-04T20:01:50+00:00Added an answer on June 4, 2026 at 8:01 pm

    If bar/2 is a predicate that results in certain side effects, such as input-output, being produced, then that is what backtracking is for.

    You just say:

       ?- foo(X,Y),bar(Y,Z).
    

    And get all the possibilities, pressing a or ; depending on your implementation.

    Alternatively, you can write

       ?- foo(X,Y),bar(Y,Z),write(bar(Y,Z)),nl,fail.
    

    On the other hand, if you need to check if there is a bar(Y,Z) pair for every Y that satisfies foo(X,Y), than you can use Prolog forall/2 facility. For instance, the following goal will be true only if for every Y that results from foo(X,Y), there exists a Z that satisfies bar(Y,Z).

       ?- forall(foo(X,Y),bar(Y,Z)).
    

    Examples

    Given the following facts

    foo(a,b).
    foo(a,c).
    bar(c,x).
    bar(c,y).
    

    With the first goal you get

    ?- foo(X,Y),bar(Y,Z),write(bar(Y,Z)),nl,fail.
    bar(c,x)
    bar(c,y)
    false.
    

    With the second goal:

    ?- forall(foo(X,Y),bar(Y,Z)).
    false.
    

    Since the goal bar(b,Z). fails.

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

Sidebar

Related Questions

after installing XAMPP on linux i have seen the folder htdocs belongs to nobody.
I'm not quite sure stackoverflow is a place for such a general question, but
I've seen a lot of questions regarding this topic, but going through these didn't
OLD QUESTION, SEE BELOW FOR THE UPDATED VERSION My development environment is not the
I've seen similar questions asked and the answers were not quite what I'm after.
Problem I'm doing some maintenance and changes on a Drupal site, but I'm not
Note: I have seen this and tried to take as much from it as
After I have seen a lot of questions here using the DATE_SUB() or DATE_ADD()
The question can be seen as both practical and theoretical. I am designing a
This seemed like a common question but after doing some searching, I wasn't really

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.