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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:44:21+00:00 2026-05-17T19:44:21+00:00

I can write a predicate that is satisfied when two lists are equal e.g.

  • 0

I can write a predicate that is satisfied when two lists are equal e.g. equal([2,3],[2,3]) would be true and equal([2,3],[4,5]). would be false.

However, what if I want to have a list and try and match it with any list in a list of lists e.g. match([2,3],[[5,6],[4,6,2],[2,3]]). would be true because of the last list in the list of lists but match([2,3],[[3,4],[4,2,1]]). would be false because [2,3] doesn’t match anything in the list of lists.

I’m thinking maybe we might need nested recursion here? Any idea how you do this? The problem I’m trying to solve is much larger but just being able to do this would allow me to solve the whole problem.

  • 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-17T19:44:21+00:00Added an answer on May 17, 2026 at 7:44 pm

    Recursive navigation of a Prolog list is usually achieved by means of a couple of clauses: the first is the condition by which the recursion is stopped and a result is returned; the second contains the recursive call. To this aim, in each clause’s head the list on which the recursion has to be performed is typically broken in two parts, isolating the first element (known as head) from the rest of the list (known as tail), such as in the following:

    p(Element, [Head | Tail]) :- % ...
    

    In that recursive clause, you process Head and, depending on the result, you proceed to call your predicate passing Tail as second argument, thus actually navigating the whole list one element at a time.

    In writing such a predicate, you may cut (using !) alternative solutions (that sometimes produce only failures) when you find the result you were looking for, e.g. in your case, once you find a match between the first list and an element in the second list, you don’t need to proceed further, so any possibly open branch in the demonstration tree should be pruned.

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

Sidebar

Related Questions

I was trying to write predicate divide(L,Len,Slist) which will be true when Slist can
I'm trying to write a predicate that divides a list into N parts. This
I have two tables that I would like to get data and from by
I have a linked list that I want to sort part of, eg: std::sort(someIterator,
I can write an assertion message one of two ways. Stating success: assertEquals( objects
Can anyone please tell me how I can write a bash shell script that
Can someone please explain how you can write a url pattern and view that
In C++ one can write any of the following statements: 10; true; someConstant; //if
I want to be able to write something as void Start(some condition that might
I'm trying to write a functor that I can pass to std::sort that will

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.