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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:44:28+00:00 2026-06-15T22:44:28+00:00

I am working on writing an insert function that takes two arguments, a number

  • 0

I am working on writing an insert function that takes two arguments, a number and a sorted list and it should produce that same list with the number included in its proper position.
Here’s what I got so far:

insert1(X,[]) :-
   [X].

insert1(X, [H|T]) :-
   X > H,
   insert1(X,T).

insert1(X,[H|_T]) :-
   X < H,
   T is [X|T]. 

I am getting the following error:

ERROR: '.'/2: Arguments are not sufficiently instantiated ("x" must hold one character)
Exception: (6) insert1(2, [1, 4, 5]) ? creep

I would appreciate your help folks.

  • 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-15T22:44:29+00:00Added an answer on June 15, 2026 at 10:44 pm

    The error message it’s rather cryptic: ‘.’/2 it’s the list constructor, and you’re calling it. See this question for a detailed explanation of the syntax.

    Also the last clause is wrong, because is/2 must be used only for arithmetic.

    But generally you are approaching the problem from a wrong ‘perspective’. Arguments in Prolog are immutable. You need another argument to hold the modified list.

    Here is a possible workaround for the first and third clause

    insert1(X, [], [X]).
    ...
    insert1(X, [H|T], [X,H|T]) :-
      X < H.
    

    You will need to adjust the second clause and invoke insert1 in this way

    ?- insert1(3, [1,2,3,4], L).
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Writing a function to do a head insert on a linked-list. It's half working
I am writing a function to insert register N. The problem is that when
We have a situation where two web applications are working on the same database.
I'm new to PL/SQL and I'm working on writing a bulk insert. I have
I'm writing a program that calls a function in main that creates a node
I'm working on writing a simple database that uses Google Fusion Tables to store
So i'm writing a function that will allow me to add an ID from
I'm working on a project that needs to automatically load content and insert it
I'm writing a plugin for FCKeditor that's meant to insert placeholders for dynamic content
I'm writing a Java application that's working with Apache Derby via JDBC. I'm having

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.