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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T10:24:33+00:00 2026-06-02T10:24:33+00:00

I want it to be working like this so then d disappears etc. ?-

  • 0

I want it to be working like this so then d disappears etc.

?- remove_last_item([a,b,c,d], L).    
L = [a, b, c] ?    

Does anyone know how to do this as I got this line
but what other line should I add to this so then the
above can be achieved.

  • 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-02T10:24:35+00:00Added an answer on June 2, 2026 at 10:24 am

    In Prolog usually, to understand the question is to have your answer already. So you need to define a predicate, remove_last_item(A,B) such that B is A without the last item. So what is list in Prolog? Like in Lisp, it is recursively defined on top of pairs, with special symbol – empty list – signifying the “end of list”.

    What does that mean? A pair, '.'(A,B), obviously has two parts. The list [a,b,c,d] is then encoded as '.'(a,'.'(b,'.'(c,'.'(d,[])))). This can also be written as [a|[b,c,d]], or [a,b|[c,d]], or [a,b,c|[d]], or [a,b,c,d|[]]. Here a is what’s known as “head” and [b,c,d] a “tail” or “rest” of the list [a,b,c,d].

    So now we just write down what we want our predicate to say, from the simplest case up:

    remove_last_item([_A],[]).
    remove_last_item([A|B],[A|C]):- B=[_|_], remove_last_item(B,C).
    

    It reads, “removing last item from a singleton list leaves us with an empty list; removing last item from a list of more than one element means removing the last item from the rest of the list, coming after its head”.

    edit: Another way to look at it is by “starting from the top”: writing down some equivalency “law”, which the predicate must follow:

    remove_last_item(L,R):- is_list(L), is_list(R), same_head(L,R),
                            tail(L,L1), tail(R,R1), 
      remove_last_item(L1,R1).
    

    We still don’t “know” what remove_last_item “does”, we just wrote down an equivalency law that it must follow, right? But then it becomes the very definition itself that we’re after. Fleshing out all the suggestive names, it becomes the (familiar)

    remove_last_item(L,R):- L=[A|L1], R=[A|R1], remove_last_item(L1,R1).
    

    So now we can recognize this as structural recursion over lists, and just add a termination clause, to add some “substance” to it.

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

Sidebar

Related Questions

I know I've done something like this before, but I have no idea why
want to rewrite urls like site.com/software to wp-content/themes/dir/software.php and something is not working.. Here's
I'm working on a JSON API and I want to do something like Facebook's
Currently my AJAX is working like this: index.php <a href='one.php' class='ajax'>One</a> <div id=workspace>workspace</div> one.php
I feel like this is a silly question but I always find that modifying
I think questions like this are the reason why I don't like working with
This seems really easy, but it's definitely not working as expected. In WPF 4.0,
I have a sql good working like this. SELECT B.HESAP_NO, A.TEKLIF_NO1 + '/' +
I working on a web page which has a similar structure like this: <div
This is something i just can't figure out working with Core Data. I want

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.