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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:38:33+00:00 2026-05-13T05:38:33+00:00

I am attempting to get my arms around some basic prolog but struggling a

  • 0

I am attempting to get my arms around some basic prolog but struggling a bit in the process. In specific – I am trying to get through a list of items and copy it, item by item into a new list. I can get it to reverse, but I am finding it trickier doing it without reversing.

Ive been trying the following –

copy(L,R) :- accCp(L,R).

accCp([],R).
accCp([H|T],R) :- accCp(T,H).

When i run a trace on this – i can see the individual items being copied across, but they get ‘lost’, and dont form a growing list (at R, as i was hoping). How could i achivie this?

Many thanks

  • 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-13T05:38:33+00:00Added an answer on May 13, 2026 at 5:38 am

    Your base case needs to set the copy list to empty when the original list is empty. Then, the recursive case needs to take H from list L and add it to the head of list R:

    copy(L,R) :- accCp(L,R).
    accCp([],[]).
    accCp([H|T1],[H|T2]) :- accCp(T1,T2).
    

    When you call copy, it works its way down to the base case, where it sets R to an empty list. Then, as it works back up, it keeps appending the head H of known list [H|T1] to the beginning of variable list [H|T2]. It does that until the original case is reached, at which point R contains a full copy of L.

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

Sidebar

Related Questions

I am attempting to get a list of items along with the order information
I'm attempting to get a set of list items from sharepoint via the WebService.
While attempting to get an old svn dump of a project under git control,
I'm attempting to get my first ASP.NET web page working on windows using Mono
I am attempting to get a DropDownList to AutoPostBack via an UpdatePanel when the
I am attempting to get the information from one table (games) and count the
I get the following error when attempting to install RubyGems . I've tried Googling
When attempting to compile my C# project, I get the following error: 'C:\Documents and
From time to time I get a System.Threading.ThreadStateException when attempting to restart a thread.
I'm attempting to use Assembly.GetType(MyCompany.Class1.Class2) to dynamically get a type from a string. Assembly.GetType(MyCompany.Class1);

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.