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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:45:04+00:00 2026-06-12T07:45:04+00:00

I am trying to make a function that takes 2 numbers and will create

  • 0

I am trying to make a function that takes 2 numbers and will create a list using the first number as a starting number and the second number as the ending value while filling in the values between the starting and ending numbers.

For example:

User passes in 3 and 7:

the output should be (3 4 5 6)

I was trying to do this and use recursion but I am struggling:

 (define (createlist start end)
   (if(= start end)
      '())
   (cons start '())
    (createlist (+ 1 start) end))
  • 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-12T07:45:05+00:00Added an answer on June 12, 2026 at 7:45 am

    There’s a repeating pattern found in the solution to this sort of problems where you have to build a list along the way using recursion. Let me illustrate the general steps, I’ll let you fill-in the blanks:

    (define (createlist start end)
      (if (= <???> <???>) ; the problem is solved when start and end are the same
          '()             ; lists end in null
          (cons <???>  ; if we are not done yet, we `cons` the current value of start
                (createlist <???> end)))) ; with the result of calling the recursion
                ; notice that start is one step closer to the end, so we increment it
    

    The idea of the algorithm is that at each step we add the current start value to the list that is being built with cons, and increment start until it reaches end, at this point the recursion ends.

    You should take a look at either The Little Schemer or How to Design Programs, both books will teach you how to structure the solution for this kind of recursive problems over lists.

    UPDATE:

    Now that you’ve posted the code you’ve written so far, I can show you the right answer. Please be very careful with parenthesis [ the closing parenthesis of an if goes after the else part ] and white spaces [ if( is not the same as if ( ], they matter a lot in Scheme. Also indent correctly your code, it’ll help you find a lot of bugs:

    (define (createlist start end)
      (if (= start end)
          '()
          (cons start
                (createlist (+ 1 start) end))))
    

    Now you can see how the <???> get correctly filled.

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

Sidebar

Related Questions

I'm trying to make a function in SML that takes a list and an
I'm trying to make a function in standard ml that takes a list of
Hi there i'm trying to make a function in C++ that takes a number,
Im trying to make a function, that takes an input, determines its value, and
I'm trying to make a function that will take short hand hex color to
I'm trying to make a Javascript function that will take a mathematical expression and
Im trying to make a function that will return an element of type point:
I'm trying to create a function (in Python) that takes its input (a chemical
I'm trying to make a function that takes a character, then returns a pointer
I'm trying to make a function that takes two data types, each of which

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.