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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T10:18:37+00:00 2026-06-08T10:18:37+00:00

started learning racket today. I was attempting to find the correct way to append

  • 0

started learning racket today. I was attempting to find the correct way to append via a loop but could not find the answer or figure out the syntax myself.

For example, if I want a row of nine circles using hc-append, how can I do this without manually typing out nine nested hc-append procedures?

  • 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-08T10:18:39+00:00Added an answer on June 8, 2026 at 10:18 am

    The first thing you need to realize is that “looping” in Racket is really just recursion. In this case, you want to chain a bunch of drawing calls together. If we wrote this out, our target goal would be this:

    (hc-append (circle 10) 
        (hc-append (circle 10)
            (hc-append (circle 10)
                (hc-append (circle 10)
                    (hc-append (circle 10)
                        (hc-append (circle 10)
                            (hc-append (circle 10)
                                (hc-append (circle 10)
                                    (hc-append (circle 10))))))))))
    

    I am assuming all of our circles are going to be the same radius.

    Now, since we’re going to be writing a recursive method, we need to think of our base case. We want exactly nine circles drawn. Let’s call this maximum number of circles max. Our base case, when we break out of our “loop” will be when we reach max iterations, or when (= iterations max).

    Now for the recursion itself. We already know we need to pass in at least two variables, the current iteration iterations, and the maximum iteration max. If you look at the code above, you’ll notice that the repeating element in all of the “loops” is the (circle 10). Now there are a number of ways you could pass that along — some people would choose to just pass the radius for example — but I think the easiest way would be to pass in the pict of the circle.

    Finally, we also have to pass along the picture we’ve done so far. That is, as we append a circle to our chain, we need to pass this back into the recursive method so we can keep appending.

    Now that we’ve got that squared away, we can define the structure of our recursive method, which we shall call circle-chain-recursive:

    (define (circle-chain-recursive iteration max crcle output)
        ; body here
    )
    

    The “guts” of our method will be an if. If we’ve reached the max iteration, return the output. Otherwise append another circle, increment iteration, and call the method again.

    (define (circle-chain-recursive iteration max crcle output)
      (if (= iteration max) 
          output
          (circle-chain-recursive
            (+ 1 iteration) max crcle (hc-append crcle output))))
    

    I personally don’t like calling recursive looping methods like this directly, so I would write a helper method like this:

    (define (circle-chain num radius)
      (circle-chain-recursive 0 num (circle radius) (circle 0)))
    

    Now if I want a series of 9 circles with radius 10, all I have to do is call (circle-chain 9 10).

    You’ll notice that I passed (circle 0) as in as the parameter called output. This is because the hc-append method requires a pict parameter. Since we’re not starting out with any circles, I passed it the equivalent of a “blank” or nil pict. There may be some other way of passing a “blank” pict, but I’m not too familiar with the slideshow/pict libraries to know it.

    I hope that clears it up a bit.

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

Sidebar

Related Questions

I started learning Django recently, and can't find answer for a simple question. I
Just started learning c++ today and im pretty boggled. its an amazing language but
Started learning algorithms. I understand how to find theta-notation from a 'regular recurrence' like
Just started learning algorithms. So the exercise is to find if statement is always/sometimes
I just started learning ASP.NET MVC4 today. After reading tutorials, downloading VS 2012, and
I started learning vim today and installed it using sudo apt-get install vim Now,
Just started learning Rails (3). I am tearing my hair out trying to find
Just started learning Scheme. I'm using Dr. Racket as my compiler/interpreter. I need some
I started learning C# a week ago. Today I was trying to install the
I started learning Delphi two days ago but I got stuck. I broke down

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.