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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:17:47+00:00 2026-06-12T00:17:47+00:00

This was given as an example in a professor’s lecture: append([ ], A, A).

  • 0

This was given as an example in a professor’s lecture:

append([ ], A, A).
append([A|B], C, [A|D]) :- append(B,C,D).

Build a list:

?- append([a],[b],Y).
Y = [ a,b ]

Break a list into constituent parts:

?- append(X,[b],[a,b]).
X = [ a ]
?- append([a],Y,[a,b]).
Y = [ b ]

I’ve spent 3 hours trying to grasp it and can’t. Hadn’t had any trouble with any prolog concepts preceding this slide. There is no further explanation provided, no other information. This is all. If someone could walk me through how this procedure works, I would love them til death do us part.

  • 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-12T00:17:48+00:00Added an answer on June 12, 2026 at 12:17 am

    The first thing to understand is the :- operator.

    this_will_be_true :- if_this_is_true
    

    Basically, whatever is on the right of :- is a precondition. A good example is:

    sibling(X, Y) :- parent_child(Z, X), parent_child(Z, Y).
    

    This basically means that X and Y are siblings if there exists a parent Z such that Z is the parent of both X and Y.

    append([ ], A, A).
    

    This line basically means that appending something to an empty list returns the something. It’s the base case in the recursion.

    append([A|B], C, [A|D]) :- append(B,C,D).
    

    This line means that appending C to an existing list with A and B returns a list with A and D given that appending C to B returns D.

    Build a list:
    
    ?- append([a],[b],Y).
    Y = [ a,b ]
    

    So, what’s going on here is that Prolog returns the only possible value of Y that satisfies the two rules given the two initial values. Let’s think about how this happens. This would need to first be evaluated by the second rule. So [A|B] is [a] and C is [b].

    So with [A|B] we have to go back to the first rule because B is empty list (it is [ ]). The first rule basically states that we can write [a] as [a|[ ]] and they are the same thing. So now we can go back to the second rule. A is a, B is [ ], and C is [b].

    So now let’s check the precondition of append(B, C, D). This is append([ ], [b], D). Once again, using the first rule, we can see that D is also [b].

    So Y, by the second rule definition, is [A|D]. Now that we know D is [b], we know that Y is [a, b].

    I’ll only do one of the breaking apart since they’re basically the same thing.

    ?- append(X,[b],[a,b]).
    X = [ a ]
    

    So here, Prolog is going to return the only possible value of X so that the statement returns true. Let’s take a look at the second rule. So we know that [a, b] is [A|D]. This means that A is a and D is [b]. We also know that C is [b]. So now, we need to look at the precondition to figure out what B is. append(B, C, D) translates to append(B, [b], [b]). Now, using the first rule, we know that B has to be [ ]. So now we know that [A|B] is [a|[ ]] which is the same as [a]. Therefore, X must be [a].

    I hope this was a detailed enough explanation.

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

Sidebar

Related Questions

Given this example data set: ----------------------------- | item | date | val | -----------------------------
Given this example XML file: <doc> <tag> Hello ! </tag> <tag> My name is
Given this example, how would I return the result of the equation rather than
I'm trying to solve this problem : http://uva.onlinejudge.org/external/7/732.html . For the given example, they
Given the example below, can someone please show me how this could be called?
This is just an example, but given the following model: class Foo(models.model): bar =
This is easier to explain with an example. Given these two classes: public class
Not really sure how to phrase this other than by example.. Given... DATABASES =
Given I have a long phrase, say, in line :12 , as this example:
Given this example taken from http://php.net/manual/en/function.crypt.php crypt('rasmuslerdorf', '$2a$07$usesomesillystringforsalt$') Firstly: What is the length that

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.