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

  • Home
  • SEARCH
  • 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 7048803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:56:07+00:00 2026-05-28T02:56:07+00:00

Does anyone know how I could implement I predicate doing what this one does

  • 0

Does anyone know how I could implement I predicate doing what this one does but without “findall”?
Thank you a lot.

domains
    oferta =  rebaixat ; normal
    element = string
        list = element*
database
    producte (string, integer, oferta)
predicates
    nondeterm reduced2(list)

clauses

    producte("Enciam",2,rebaixat). 
    producte("Peix",5,normal).
    producte("Llet",1,rebaixat). 
    producte("Formatge",5,normal).

         reduced2(Vals):-
            findall(Val, producte(Val,_,rebaixat),Vals).
Goal
    write("Amb findall"),nl,
    reduced2(List).
  • 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-28T02:56:08+00:00Added an answer on May 28, 2026 at 2:56 am

    I don’t know much about Visual Prolog, but I will try to give a general answer. It depends on whether you want to find a findall/3 replacement for a specific case or in general, though.

    In the specific case, you can use an accumulator. In your case, this would be a list into which the values are added as you find them. Something like:

    acc(In, List) :-
       ... % do something to generate possible next value
       ... % test if value is already in list In
       !,
       Out = [Val|In], % adds to the head, but is faster than using append
       acc(Out, List).
    acc(List, List).
    

    I.e., when you can’t find another possible value, you return the list of values that you found. Note that this may be slow if you have to accumulate a lot of values and generating the next possible value is done via backtracking. Also, this will not let you generate duplicates, so it’s not an exact replacement for findall/3.

    If you want a general replacement for findall/3, where you can specify a goal and a variable or term that will contain the instance to be accumulated, then you won’t get around using some sort of non-logical global variable. After finding the next value, you add it to what’s been stored in the global variable, and cause backtracking. If generating the next value fails, you retrieve the content of the global variable and return it.

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

Sidebar

Related Questions

Does anyone know in which namespace IObjectContextStorage could be found? or should I implement
Does anyone know how to implement the Sum-of-Subsets problem in Java from this pseudo
does anyone know where I could find the source code for the SandPile (cellular
Does anyone know of a PDF file parser that I could use to pull
Does anyone know of an algorithm that I could use to find an interesting
Does anyone know of an application (hosted or otherwise) that I could use to
Does anyone know of a quick color picker widget that I could grab to
Does anyone know of a good Command Prompt replacement? I've tried bash/Cygwin, but that
I've been thinking about some possible features C++ could have, does anyone know why
Does anyone know of a complete choose file dialog? Maybe one where you can

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.