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

The Archive Base Latest Questions

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

Pretty new to Prolog. I’m trying to give two lists and have the difference

  • 0

Pretty new to Prolog. I’m trying to give two lists and have the difference of the two returned to me. The second list can have bound variables and unbound variables in it. I’ve tried tracing this and it recurses all the way through and gives me a correct list in NewL, but then on the way back it negates all the deletes I’ve made. What is going wrong ? Thanks for the help!

% Find difference between two lists, return result in Difference
difference(List,[H|T],Difference) :-   % When H is unbound var, use Tail
    var(H),!,difference(List,T,Difference),!.

difference(List,[H|T],Difference) :- % When H is bound var, remove from List.
    subtract(List,[H],NewL),
    difference(NewL,T,Difference),!.
  • 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:46:17+00:00Added an answer on June 4, 2026 at 8:46 pm

    Assuming that subtract/3 comes from SWI-Prolog library, and thus is correct, you are left with just one possibility: you forgot to declare the base case on the second argument, that drives the recursion.

    And take in account the comment from @mog, cuts should be used just when required. Of course, to decide when are required can be difficult…

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

Sidebar

Related Questions

Pretty new to ASP.NET and trying to figure out how to have the code
Am pretty new to web services and have been trying to implement Soap Faults.
Pretty new with java/eclipse. Problem: I have two packages in one android project. I
Im pretty new to Dreamweaver. Im having a problem. I have a website that
I'm pretty new to c# and I'm trying to make a function that checks
Pretty new to dependency injection and I'm trying to figure out if this is
Pretty new to sqlite (and sql). Trying to modify one table using another. create
Pretty new to the Magento e-commerce solution. Have it up and running for a
still pretty new to android I have to clone an iphone application. Im having
Im pretty new to jQuery (since a week) and don't understand why I can't

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.