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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:02:35+00:00 2026-05-25T15:02:35+00:00

So I have the predicate which returns true several time. % true returns several

  • 0

So I have the predicate which returns true several time.

% true returns several times and i need to press ';'
?- get_all_transformed_moves.
true ;
true ;
true.

Is the swi prolog have some method which can help me to run this predicate without typing’;’?

% Wished version 
?- get_all_transformed_moves.
true.
  • 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-05-25T15:02:36+00:00Added an answer on May 25, 2026 at 3:02 pm

    Consider the following:

    likes(prolog).
    likes(haskell).
    likes(erlang).
    
    likes_something:-
        likes(_Something).
    

    if now you ask:

    ?- likes_something.
    

    you will get

    true ;
    true ;
    true.
    

    this happens because prolog finds three ways to satisfy the likes_something/0 predicate (with prolog, haskell and erlang) so it answers true for three times.

    this isn’t exactly a problem; at any time you can press and prolog will stop trying to find answers (this is quite handy when there are a lot of results).

    the same thing happens to your predicate: there are three solutions and by pressing ; you force prolog to find them all. as Rocha suggested you could use findall/3. For example, you could write:

    likes_something:-
       findall(X, likes(X), _).
    

    and this will return just one yes

    however, it doesn’t offer more information than the previous version; instead it hides the fact that there are 3 solutions and wastes time trying to find more while the answer wont change.
    For that reason I think that you should use findall/3 if you actually want to see the results:

    likes_all(L):-
       findall(X,likes(X),L).
    

    of course, the decision of whether you need to see the results or not is up to you (or rather to the problem you are trying to solve :p)

    another option is to use a cut: !/0
    for example:

    likes_something:-
       likes(_Something),
       !.
    

    this will stop prolog from searching for more solutions and you will get just one true.
    note however that cuts can be tricky.

    All in all:
    if you want prolog to search for all the answers (if you decide to put them in a list or you have side-effects in your predicates or if you just want it): use findall/3

    if you don’t want to have the option to search for more answers: use a cut (!/0)

    else just press enter instead of ;

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

Sidebar

Related Questions

I have a C# method which accepts a Predicate<Foo> and returns a list of
I have written a predicate common_participant(Person, PairEvent) . which returns pairs of facts from
i have the following linq extension method, which returns an IEnumerable. This means, that
For example I have: pos(10, 20). How can i write the predicate which returns
Suppose I have a function which takes some form of predicate: void Foo( boost::function<bool(int,int,int)>
I have a Repository Class with the following method... public T Single<T>(Predicate<T> expression) {
I have a large Prolog program with lots of predicates. I need to connect
We have a project using LINQ to SQL, for which I need to rewrite
I have this if statement, which returns the result as a AsQueryable to an
I'm trying to create a method which create the where predicate to use later

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.