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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:20:13+00:00 2026-05-23T03:20:13+00:00

I have the next function from the book: % Signature: select (X,HasXs,OneLessXs)/3 % purpose:

  • 0

I have the next function from the book:

% Signature: select (X,HasXs,OneLessXs)/3 
% purpose: The list OneLessXs is the result of removing 
 one occurrence of X from the list HasXs. 
select(X,[X|Xs],Xs).  *rule number 1* 
select(X,[Y|Ys],[Y|Zs]) :- select(X,Ys,Zs).  * rule number 2*

?- select(4,[2,3,2,4,5,2,4],X].
X=[2,3,2,5,2,4]

But I didn’t understand how it finds the correct answer. After it removes all the Y=!X, It come to a rule number 1, with: Xs=4,5,2,4, then it return true. and what then? If it continue to rule 2, then he also remove the next “4”. If it doesn’t continue to rule 1, then How Zs is [2,3,2,5,2,4]? I think Im missing a basic rule.

  • 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-23T03:20:14+00:00Added an answer on May 23, 2026 at 3:20 am

    You can understand why this is happening by thinking of how it’s going to be executed.
    So you have:

    % I use K here instead of X, so there is no
    % confusion with the X on the rules
    select(4,[2,3,2,4,5,2,4], K).
    

    First, it will check rule 1, but 4 != 2 so it will continue to rule 2. At rule 2, you have these “bindings”:

    X = 2
    [Y | Ys] = [2, 3, 2, 4, 5, 2, 4] (which means Y = 2, Ys = [3, 2, 4, 5, 2, 4])
    [Y | Zs] = [2 | Zs] (because Y was binded to 2)
    

    And K is binded to [2 | Zs] and not just Zs. The next select call which will be select(4, [3, 2, 4, 5, 2, 4], Zs) finds Zs and so on. That’s why the returned result is:
    K=[2,3,2,5,2,4] and not K=[5, 2, 4] as you was expecting.

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

Sidebar

Related Questions

I have a function, that returns the next higher value of a Dictionary-Keys-List compared
I have next problem, when I'm trying to retrieve value from xforms:select elements I
I have next function for autocomplete an input: $(#auto).autocomplete({ source:/autocomplete.php, minLength: 5, _renderItem: function(
I have the next function: function setImagesWidth(id,width) { var images = document.getElementById(id).getElementsByTagName(img); for(var i
I have coded the next function. But surely someone has a more elegant way
I have the next code: js: $('[id^=check-]').change(function(){ var new_id = this.id.replace(/check/, 'new'), real_id =
I have the following function. $(function() { $(.sectionHeader:gt(0)).click(function() { $(this).next(.fieldset).slideToggle(fast); }); $(img[alt='minimize']).click(function(e) { $(this).closest(table).next(.fieldset).slideUp(fast);
I have the following jQuery which I need adapting: $(document).ready(function(){ $(.rss-popup a).hover(function() { $(this).next(em).stop(true,
The next few lines I'm going to write come from the book The C++
I have next code block: $.post('page.php', function(data) { //data - full page info });

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.