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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:48:58+00:00 2026-06-10T10:48:58+00:00

This time I really cannot understand the error: i wrote this code to get

  • 0

This time I really cannot understand the error: i wrote this code to get the list element at a certain position:

take_pos([], _, _) :- fail;
take_pos([H|T], 1, H).
take_pos([H|T], Pos, X) :- Pos2 is Pos - 1, take_pos(T, Pos2, X).

It never terminates; tracing it I can see that it never match the second statement. Also if i query take_pos([1,2,3], 1, 1). it match the last one.

What am I missing?

  • 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-10T10:48:59+00:00Added an answer on June 10, 2026 at 10:48 am

    I think the problem is that you put a semicolon instead of a dot after fail.

    Also consider rewriting the second rule to avoid introducing a singleton:

    take_pos([], _, _) :- fail.
    take_pos([H|_], 1, H).
    take_pos([H|T], Pos, X) :- Pos2 is Pos - 1, take_pos(T, Pos2, X).
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've ignored this topic for really long time and I would like to get
I really need help this time - Joomla 2.5 and latest K2. I'm using
At this time Textmate's official Python bundle is really bare bones, especially in comparison
I'm really only familiar with the C calling convention at this time (as described
I am facing a really tough time doing this. I haven't done much on
I am having a really hard time getting this to work. I have two
I'm having a really difficult time debugging this problem. Whenever I try to establish
I have a really hard time searching for this, because I have no idea
I really didn't want to have to waste people's time and ask this, but
I have looked at this page for some time now. Amazing, really. But I

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.