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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:29:30+00:00 2026-06-13T20:29:30+00:00

I have a predicate lookupOptions which returns one by one some lists (Menus). I’m

  • 0

I have a predicate “lookupOptions” which returns one by one some lists (Menus).

I’m trying to get it to satisfy the case of multiple inputs. I can return a single set of options as follows, by reading the head of the “list_places” list.

find_options(Restaurant,Town,Menu) :- lookupOptions(Restaurant,H,Menu), list_places(Town,[H|T])

But, I’m not able to get it to iterate.

I have tried a lot of things, these were my best efforts so far.

a) standard enough iteration, but it wont resolve …

doStuff(X,[],_).
doStuff(Restaurant,[H|T],_):-  lookupOptions(Resturant,H,_), doStuff(Restaurant,T,_).
find_options(Restaurant,Town,Menu) :- doStuff(Restaurant,[H|T],Menu), list_places(Town,[H|T]).

b) expanding the goal predicate …

find_options(_,Town,[H|T],_)
find_options(Restaurant,Town,Menu) :- find_options(Restaurant,Town,[],Menu).
find_options(Restaurant,Town,X,Menu) :- list_places(Town,X).
find_options(Restaurant,Town,[H|T],Menu) :- lookupOptions(Restaurant,[H],Menu), find_options(Restaurant,Town,T,Menu).

Would either of these work ? if the pattern was written correctly. Or if there was an appropriate cut put in place?

Any help most appreciated …

  • 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-13T20:29:31+00:00Added an answer on June 13, 2026 at 8:29 pm

    It’s no clear on what you want iterate. Prolog uses backtracking to examine all alternatives, then you should start backtracking if you are after some alternative, or use the all solutions family.

    Now I think you want simply declare there could be more find_options(Restaurant,Town,Menu). Then try replacing the head match [H|T] with this:

    find_options(Restaurant,Town,Menu) :-
       lookupOptions(Restaurant,H,Menu),
       list_places(Town, Places),
       member(H, Places).
    

    BTW T is a singleton in your original rule. This could be a hint for the need of generalize it.

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

Sidebar

Related Questions

I have written a predicate common_participant(Person, PairEvent) . which returns pairs of facts from
I have a base case in my predicate in which I have to assign
I have predicate P1 that returns values one after the other like this: -?
For example I have: pos(10, 20). How can i write the predicate which returns
I have a C# method which accepts a Predicate<Foo> and returns a list of
I want a simple predicate that returns me all the groups which have mode
I am going through the code which uses Predicate in Java. I have never
I use a findall predicate findall(A,getzoo(B,A),MyList) which returns this list A = [[[ant,bear,crab,tortoise,lion],230], [[lion,tiger,bear],560],
I have a problem with prolog predicate. I have one board and i want
I'm trying to get my head around the Predicate<T> type and I can understand

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.