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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:46:07+00:00 2026-05-28T00:46:07+00:00

So I’m going through the first chapter of How To Design Programs 2nd Edition.

  • 0

So I’m going through the first chapter of How To Design Programs 2nd Edition. I believe I made pretty good progress. But there’s a “suggestion” to add another graphic to the grid. Every time I try I get an error. At this point, I’m stuck. Below is the code and the error.

Note: the ROCKET image is in the Chapter 1. I just copy and pasted it into the IDE.

Note: The “suggestion” is: How would change the program so that the rocket lands on a flat rock bed that is 10 pixels higher than the bottom of the scene? Don’t forget to change the scenery, too.

HTDP Chapter 1

Here’s code that works.

(define BOARDWIDTH 200)
(define BOARDHEIGHT 200)
(define STARTPOSITION 50)
(define BOARDBKGR "blue")
(define GAMEBOARD (empty-scene BOARDWIDTH BOARDHEIGHT BOARDBKGR))

(define ROCKET .)
(define UFO (overlay (circle 10 "solid" "red")
                     (rectangle 40 4 "solid" "green")))
(define FLATBED (rectangle 60 10 "outline" "black"))
(define (SPACESHIP option)
  (cond
    [(= option 1) ROCKET]
    [(= option 2) UFO]))
(define SHOWNSHIP (SPACESHIP 1))

(define V 20) ;Velocity
(define A 1)  ;Acceleration

(define (distance t)  ;t = Time
  (- (* V t) (* 1/2 A (sqr t))))

(define SPACESHIP-BOTTOM (- BOARDHEIGHT (/ (image-height SHOWNSHIP) 2)))

(define (render-shownship x y)
  (place-image SHOWNSHIP x y GAMEBOARD))

(define (create-rocket-scene.v7 t)
  (cond 
    [(<= (distance t) SPACESHIP-BOTTOM)
     (render-shownship STARTPOSITION (distance t))]
    [(> (distance t) SPACESHIP-BOTTOM)
     (render-shownship STARTPOSITION SPACESHIP-BOTTOM)]))

Here’s the code that doesn’t work:

(define BOARDWIDTH 200)
(define BOARDHEIGHT 200)
(define STARTPOSITION 50)
(define BOARDBKGR "blue")
(define GAMEBOARD (empty-scene BOARDWIDTH BOARDHEIGHT BOARDBKGR))

(define ROCKET .)
(define UFO (overlay (circle 10 "solid" "red")
                     (rectangle 40 4 "solid" "green")))
(define FLATBED (rectangle 60 10 "outline" "black"))
(define (SPACESHIP option)
  (cond
    [(= option 1) ROCKET]
    [(= option 2) UFO]))
(define SHOWNSHIP (SPACESHIP 1))

(define V 20) ;Velocity
(define A 1)  ;Acceleration

(define (distance t)  ;t = Time
  (- (* V t) (* 1/2 A (sqr t))))

(define SPACESHIP-BOTTOM (- BOARDHEIGHT (/ (image-height SHOWNSHIP) 2)))

(define (render-shownship x y)
  (place-image SHOWNSHIP x y GAMEBOARD)
  (place-image FLATBED STARTPOSITION 195 GAMEBOARD))  ;offender

(define (create-rocket-scene.v7 t)
  (cond 
    [(<= (distance t) SPACESHIP-BOTTOM)
     (render-shownship STARTPOSITION (distance t))]
    [(> (distance t) SPACESHIP-BOTTOM)
     (render-shownship STARTPOSITION SPACESHIP-BOTTOM)]))

And the error I get is:

define: expected only one expression for the function body, but found
1 extra part

  • 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-05-28T00:46:07+00:00Added an answer on May 28, 2026 at 12:46 am

    place-image always takes 4 arguments – the image to be placed, x and y coordinates, and the scene (background) on which to place the image. The problem in your code is that the expression (place-image FLATBED STARTPOSITION 195) is providing only 3 inputs to place-image.

    So, back up a little and consider: what does the first expression produce? (place-image SHOWNSHIP x y GAMEBOARD) produces a game board scene with a ship on it, correct? Now on top of that scene you further want to place the FLATBED. So instead of sequencing the place-image function calls, instead consider composing them – i.e. what do you think the missing piece is in (place-image FLATBED STARTPOSITION 195 ____)? upon what scene do you want to place the FLATBED? (Hint: we just answered that above). What expression produces that scene? (hint: you already have that expression).

    If you understand the idea, you see that to place multiple images on a scene, you compose or nest the function calls (instead of sequencing them as you are attempting):

    (place-image img1 x1 y1 (place-image img2 x2 y2 ...))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
I want to construct a data frame in an Rcpp function, but when I
I am trying to loop through a bunch of documents I have to put

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.