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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:23:00+00:00 2026-06-14T03:23:00+00:00

How to check if the given value is a number in Prolog without using

  • 0

How to check if the given value is a number in Prolog without using built-in predicates like number?

Let’s say I have a list [a, 1, 2, 3]. I need a way to check if every element within this list is a number. The only part of the problem that bothers me is how to do the check itself without using the number predicate.

The reason why I’m trying to figure this out is that I’ve got a college assignment where it’s specifically said not to use any of the built-in predicates.

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

    You need some built-in predicate to solve this problem – unless you enumerate all numbers explicitly (which is not practical since there are infinitely many of them).

    1

    The most straight-forward would be:

    maplist(number, L).
    

    Or, recursively

    allnumbers([]).
    allnumbers([N|Ns]) :-
       number(N),
       allnumbers(Ns).
    

    2

    In a comment you say that “the value is given as an atom”. That could mean that you get either [a, ‘1’, ‘2’] or ‘[a, 1, 2]`. I assume the first. Here again, you need a built-in predicate to analyze the name. Relying on ISO-Prolog’s errors we write:

    numberatom(Atom) :-
       atom_chars(Atom, Chs),
        catch(number_chars(_, Chs), error(syntax_error(_),_), false).
    

    Use numberatom/1 in place of number/1, So write a recurse rule or use maplist/2

    3

    You might want to write a grammar instead of the catch... goal. There have been many such definitions recently, you may look at this question.

    4

    If the entire “value” is given as an atom, you will need again atom_chars/2or you might want some implementation specific solution like atom_to_term/3 and then apply one of the solutions above.

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

Sidebar

Related Questions

I need to check a variable vi_theIndex for its value. At the given moment
Given the following code: $(.force-selection).blur(function() { var value = $('matched-item').val(); //check if the input's
How can I check the given email id is valid or not using ELIPS
I need to check whether a given date is in the preceding month for
I am trying to find the fastest way to check whether a given number
Possible Duplicate: check number of a given character occurence in a String I'm trying
I need to check a given byte or series of bytes for a particular
Given a number, I have to find out all possible index-pairs in a given
I have developed an algorithm to find factors of a given number. Thus it
What I'm trying to do, is, given a list with an arbitrary number of

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.