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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:07:41+00:00 2026-06-01T02:07:41+00:00

I was trying to write predicate divide(L,Len,Slist) which will be true when Slist can

  • 0

I was trying to write predicate divide(L,Len,Slist) which will be true when Slist can unify with a List of length Len allocated from List L. for example

divide([1,2,3,4,5,6,7],3,Slist).

Should give such answers

Slist=[1,2,3];
Slist=[2,3,4];
Slist=[3,4,5];
Slist=[4,5,6];
Slist=[5,6,7];

But i couldn’t find a better way then length(X,Len), sublist(L,X). but it does work too slow.
How should look divide predicate?

  • 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-01T02:07:42+00:00Added an answer on June 1, 2026 at 2:07 am

    sublist/2 doesn’t seems to work as expected:

    ?- [library(dialect/sicstus/lists)].
    % library(dialect/sicstus/lists) compiled into sicstus_lists 0,00 sec, 14 clauses
    true.
    
    ?- L=[1,2,3,4,5,6], length(T, 3),sublist(T,L).
    L = [1, 2, 3, 4, 5, 6],
    T = [1, 2, 3] ;
    L = [1, 2, 3, 4, 5, 6],
    T = [1, 2, 4] ;
    L = [1, 2, 3, 4, 5, 6],
    T = [1, 2, 5] ;
    ....
    

    You could use append/3 instead:

    ?- L=[1,2,3,4,5,6], length(T, 3), append(_, Q, L), append(T, _, Q).
    L = [1, 2, 3, 4, 5, 6],
    T = [1, 2, 3],
    Q = [1, 2, 3, 4, 5, 6] ;
    L = [1, 2, 3, 4, 5, 6],
    T = [2, 3, 4],
    Q = [2, 3, 4, 5, 6] ;
    L = [1, 2, 3, 4, 5, 6],
    T = [3, 4, 5],
    Q = [3, 4, 5, 6] ;
    L = [1, 2, 3, 4, 5, 6],
    T = Q, Q = [4, 5, 6] ;
    false.
    

    I don’t think it’s very fast, just essential…

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

Sidebar

Related Questions

I'm trying to write a predicate that divides a list into N parts. This
I'm trying to write a functor that I can pass to std::sort that will
I'm trying to write a function that will produce the combinations of list elements
I've been trying to write an extension method to mimic List.RemoveAll(Predicate). So far I've
I'm having some difficulties in prolog, I'm trying to write a predicate that will
Trying to write a regular expression for java that will return true ONLY if
I am trying to write a predicate palindrome/1 in Prolog that is true if
I'm trying write a query to find records which don't have a matching record
Trying to write a PowerShell cmdlet that will mute the sound at start, unless
Trying to write a couple of functions that will encrypt or decrypt a file

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.