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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:43:01+00:00 2026-06-12T17:43:01+00:00

I need a subroutine for my program written in scheme that takes an integer,

  • 0

I need a subroutine for my program written in scheme that takes an integer, say 34109, and puts it into a list with elements 3, 4, 1, 0, 9. The integer can be any length. Does anyone have a trick for this? I’ve thought about using modulo for every place, but I don’t think it should be that complicated.

  • 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-12T17:43:02+00:00Added an answer on June 12, 2026 at 5:43 pm

    The simplest way I can think of, is by using arithmetic operations and a named let for implementing a tail-recursion:

    (define (number->list num)
      (let loop ((num num)
                 (acc '()))
        (if (< num 10)
            (cons num acc)
            (loop (quotient num 10)
                  (cons (remainder num 10) acc)))))
    

    Alternatively, you can solve this problem using string operations:

    (define char-zero (char->integer #\0))
    
    (define (char->digit c)
      (- (char->integer c) char-zero))
    
    (define (number->list num)
      (map char->digit
           (string->list (number->string num))))
    

    This can be compressed into a single function, but I believe it’s easier to understand if we split the problem in subparts as above.

    (define (number->list num)
      (map (lambda (c) (- (char->integer c) (char->integer #\0)))
           (string->list
            (number->string num))))
    

    Anyway, the results are as expected:

    (number->list 34109)
    > '(3 4 1 0 9)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In a shell-script (or Perl) I need a subroutine that returns for all my
I need to run a VBA subroutine 4 seconds later. The subroutine takes one
I've inherited a 10K-line program written in 8051 assembly language that requires some changes.
I need a subroutine that completely removes an array element in place . The
I have a Perl program that I've written that parses SQL-like statements and creates
I have a variable that I need to pass to a subroutine. It is
Need help with a query that I wrote: I have three tables Company id
Sometimes I need a useful utility function, like List::Util::max in the middle of a
I have a mission critical Perl-CGI server-side application that I need to extend or
I think title says what I need. I know we can use asd function

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.