Hi Patrick, The problem you’re up against is that in the code you’ve attached, we don’t have a clear picture of what the signatures for your functions are, nor of the “world” upon which big-bang operates. Standard practice in HtDP-based courses dictates that every big-bang program should have a data definition for the world in comments, and every function should have a signature and brief description of its purpose in comments (as well as one or more examples/tests to illustrate its use).
Because you write (big-bang (ufo 70 60) ...), you clearly intend for your “world” to be a ufo struct. So in order for your readers to not have to guess at what you mean, you need a comment to accompany your struct definition: ;; A World is a (ufo Number Number): (struct ufo (xpos ypos)) ;; where xpos is ... ;; and ypos is ... And say what xpos and ypos represent. Thereafter, when you write function signatures, you can use World to describe the kind of data that’s passing in or out, e.g., ;; SIGNATURE: render-ufo : World -> Image ;; PURPOSE: draws the UFO at the given location If you look at the Help Desk docs for 2htdp/universe, one fine thing it gives you in the description of big-bang is the signature required for every one of the handler functions. For example: big-bang’s first parameter must be a World, and in [to-draw f] the signature of f must be ;; f : World -> Image Once you’ve worked out what the signatures should be for all of your handler functions, take a look at your code and start writing signatures for the functions you’ve written. This will lead you to figure out what’s going wrong. Cheers, jmj On Jun 26, 2015, at 4:42 PM, Patrick Ester <patrick.es...@gmail.com> wrote: > > Dear All, > > I am not sure if this is the right place since I am working from the Realm of > Racket book. If not, please let me know where I can take my question. I > finished up chapter five, and wanted to modify the UFO example to move in > relation to the arrow keys. Here is the code that I wrote: > > #lang racket > (require 2htdp/universe 2htdp/image) > > (define WIDTH 600) > (define HEIGHT 600) > ;;The image won't copy and paste, but you get the idea. > (define IMAGE-of-ufo .) > > (struct ufo (xpos ypos)) > > (define (move-up w) > (add1 (ufo-xpos w))) > > (define (move-down w) > (sub1 (ufo-xpos w))) > > (define (move-right w) > (add1 (ufo-ypos w))) > > (define (move-left w) > (sub1 (ufo-ypos w))) > > (define (render-ufo w) > (place-image > (scale 0.25 IMAGE-of-ufo) (ufo-xpos w) (ufo-ypos w) > (empty-scene WIDTH HEIGHT))) > > (define (move-UFO w key) > (cond [(key=? key "up") (move-up w)] > [(key=? key "down") (move-down w)] > [(key=? key "left") (move-left w)] > [(key=? key "right") (move-right w)] > [else w])) > > (big-bang (ufo 70 60) > (on-key move-UFO) > (to-draw render-ufo)) > > When I click the Run button, the output initially looks good. However, when I > press an arrow key, I get an error. Attached is a screenshot with what I see > in the definitions pane. > > The error message in the interactions pane is: > > "ufo-xpos: contract violation > expected: ufo? > given: 61" > > I do not get why the contract is broken. The function place-image takes an > image, number, number, and a scene. What mistake am I making? Thanks in > advance. > > Patrick > > -- > You received this message because you are subscribed to the Google Groups > "Racket Users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to racket-users+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > <Screen Shot 2015-06-26 at 6.26.21 PM.png> -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.