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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:56:32+00:00 2026-06-13T07:56:32+00:00

My rule is supposed to unify the first parameter with the third element in

  • 0

My rule is supposed to unify the first parameter with the third element in the list. The list is the second parameter in the rule. If there is no third element, this should fail.

After many examples and confusion i have created this rule.

third(X,[_|T]):-
    [_,Y] = T,!,fail,
    (Y,X).

So my understanding, which i believe is incorrect, it will set Y to the third element of the list T, since T is the tail part of the initial list. then it will unify Y with X.

Still confused about the code that ‘unifies’ these elements

  • 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-13T07:56:33+00:00Added an answer on June 13, 2026 at 7:56 am

    The fail after the cut ! assures that your procedure will never succeed, because you are commiting choices with the cut and then failing.

    You can access the third element of the list the way you try to do it only if the list has exactly three elements: you skip the first element in the head of the procedure, then take the second element from the tail.

    third(X,[_|T]):-
        [_,X] = T.
    

    Note that this procedure will fail if the list does not have exactly three elements.

    However, it is more straightforward to access directly the third element in the head of the procedure, e.g:

    third(X, [_, _, X|_]).
    

    This will unify X with the third element of the list from the second argument. The |_ part allows the list to have more elements (it unifies the tail with an anonymous variable).

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

Sidebar

Related Questions

How should I use callback functions in parsekit? suppose I have the following rule:
This rule works fine for http://foo.com/page/contact RewriteRule ^page/([^/\.]+)/?$ index.php?page=$1 [L] But what I want
What rule should I write for redirection in htaccess so that http://abc.com/http://xyz.com/path/ redirects to
Is there a rule regarding which statements don't need to be terminated with a
I have this rule in my .htaccess RewriteRule ^([^/\.]+)/?$ ?page=user&id=$1 [L] It rewrite a
There is a rewrite rule ensuring that all URL's head to index.php and maintain
I have this simple rule in my Makefile : PP=g++ -std=c++0x %.o: $.cpp $(PP)
We have a rewrite rule that looks like this: RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}
I don't really know what's causing this problem but my program, which is supposed
my boss insisting on the following rule: all variables passed into constructor should be

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.