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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:49:40+00:00 2026-06-14T21:49:40+00:00

I am just trying to randomly make a list and use it in a

  • 0

I am just trying to randomly make a list and use it in a larger function.

        (define make-random-list
        (if
          (= (random 2) 0) (list 2 3)
                           (list 3 2)))

This only produces the list (2 3) and I am not sure why. What is happening to cause this?

I can make the function work if I write it like this

  (define make-random-list
   (lambda (x)
   (if
    (= (random x) 0) (list 2 3)
                     (list 3 2))))

and calling (make-random-list 2)

but I do not understand why that would work and the other one would not. What is going on with scheme that would not allow the first function to produce random results?

  • 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-14T21:49:42+00:00Added an answer on June 14, 2026 at 9:49 pm

    In your first snippet, you’re assigning the result of a one-time computation to a variable. What you need here is to define a function that will be evaluated every time it’s invoked. Your second snippet does exactly that, but there is a shorter way to express the same:

    (define (make-random-list x)
    (if
      (= (random x) 0) (list 2 3)
                       (list 3 2)))
    

    Note the difference in the syntax: a function definition encloses the function definition together with the formal argument names in parentheses, while there are no parentheses around the name of a variable.

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

Sidebar

Related Questions

in this program I'm trying to shuffle a list by randomly choosing two items
I can usually get the behavior I desire by just randomly trying different permutations
just trying to test for equality in this piece of code, but getting a
Just additional information: this is for a game project I'm working on. I'm trying
I'm trying to make a site where users can submit photos, and then randomly
Just learning this stuff, so bear with any ignorance... In what I'm trying to
This problem is going to be the death of me. I'm trying to make
Just trying to get diff to work better for certain kinds of documents. With
Just trying to still get my head around IOC principles. Q1: Static Methods -
Just trying to establish whether prototype can do something like $$('#ID a:last').css('color','#111'); Any ideas

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.