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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:27:50+00:00 2026-06-16T00:27:50+00:00

I trying to write a function which gets an integer number , represented by

  • 0

I trying to write a function which gets an integer number , represented by string , and check if all his chars are digits and return #t \ #f accordingly . Thats the code –

(define (splitString str) (list->vector (string->list str)))

(define myVector 0)
(define flag #t)

(define (checkIfStringLegal str) (
(set! myVector (splitString str))
(do (  (i 0 (+ i 1))  )  ; init
  ((= i (vector-length myVector)) flag) ; stop condition
  (cond ((>= 48 (char->integer (vector-ref myVector i)) ) (set! flag #f))
        ((<= 57 (char->integer (vector-ref myVector i)) )(set! flag #f))


  )    
)
) 
) 

Few explanations –

(list->vector (string->list str)) – convert string the char list .

(vector-ref myVector i) – char from the myVector at place i .

Its run OK , but when I try to use this func , like (checkIfStringLegal "444") I get –

application: not a procedure;
 expected a procedure that can be applied to arguments
  given: #<void>
  arguments...:
   #t
  • 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-16T00:27:51+00:00Added an answer on June 16, 2026 at 12:27 am

    Try this:

    (define (checkIfStringLegal str)
      (andmap char-numeric?
              (string->list str)))
    

    This is how the procedure works:

    1. It transforms the string into a list of characters, using string->list
    2. It validates each character in the list to see if it’s a number, applying the predicate char-numeric? to each one
    3. If all the validations returned #t, andmap will return #t. If a single validation failed, andmap will return #f immediately

    That’s a functional-programming solution (and after all, this question is tagged as such), notice that your intended approach looks more like a solution in a C-like programming language – using vectors, explicit looping constructs (do), mutation operations (set!), global mutable definitions … that’s fine and it might eventually work after some tweaking, but it’s not the idiomatic way to do things in Scheme, and it’s not even remotely a functional-programming solution.

    EDIT:

    Oh heck, I give up. If you want to write the solution your way, this will work – you had a parenthesis problem, and please take good notice of the proper way to indent and close parenthesis in Scheme, it will make your code more readable for you and for others:

    (define (splitString str) (list->vector (string->list str)))
    (define myVector 0)
    (define flag #t)
    
    (define (checkIfStringLegal str)
      (set! myVector (splitString str))
      (do ((i 0 (+ i 1)))
        ((= i (vector-length myVector)) flag)
        (cond ((>= 48 (char->integer (vector-ref myVector i)))
               (set! flag #f))
              ((<= 57 (char->integer (vector-ref myVector i)))
               (set! flag #f)))))
    

    Even so, the code could be further improved, I’ll leave that as an exercise for the reader:

    • Both conditions can be collapsed into a single condition, using an or
    • The exit condition should be: end the loop when the end of the vector is reached or the flag is false
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently trying to write a SQL Server 2005 function, which gets a string
i am trying to write one function which return sql statement like function get_sql($name=0,$date_start=0,$date_end=0)
I am trying to write a PHP function which gets the sum of values
I am trying to write a function which returns a string created from two
I am trying to write a jQuery function which searches for all divs on
I'm trying to write a function which gets the domain name from a URL
I'm trying to make it so I can write a function which defines a
I'm trying to write a function that takes multiple arguments, which can come either
I am trying to write a function to determine if a string is a
I'm trying to write a template which gets the type of a functionpointer as

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.