Quiz App
Decks
Folders
Back
Summary
{deck: {name: "3a How to Design Worlds"}, score: [{question_type: "multiple_choice", label: "Multiple choice", graded: true, count: 0, total: 0}, {question_type: "short_answer", label: "Short answer", graded: false, count: 8, total: 8}], answers: [{question_prompt: "A world program represents a ball moving horizontally across the screen. The only changing information is the ball's x-coordinate. Define a data definition named BallWorld for the world state, include an interpretation, and write the basic template for a function that consumes a BallWorld.", question_type: "short_answer", choices: [], selected_choice: nil, response: "; HorizontalBall\n; interp represents the horizontal x position of the ball\n(define (fn-for-ball hb) (... hb))", correct: nil}, {question_prompt: "Write a big-bang expression for a world program that starts at 0 and uses tick as its on-tick handler, draw as its to-draw handler, and handle-key as its on-key handler.", question_type: "short_answer", choices: [], selected_choice: nil, response: "```racket\n(define (main 0)\n (on-tick tick)\n (to-draw draw)\n (on-key handle-key)))\n```", correct: nil}, {question_prompt: "Write the signatures and stubs for three handlers: tick updates a WorldState every clock tick, draw renders a WorldState as an Image, and handle-key consumes a WorldState and KeyEvent and produces a WorldState.", question_type: "short_answer", choices: [], selected_choice: nil, response: "; WorldState -> WorldState\n; interp. update the world state data every tick\n(define (tick ws) (... ws))\n\n; WorldState -> Image\n; interp. returns an image representation of the world state\n(define (draw ws) (empty))\n\n; WorldState, KeyEvent -> WorldState\n; interp. takes a world state and key event and returns an updated world state\n(define (handle-key ws ke)\n (cond [q a]\n [q a]))", correct: nil}, {question_prompt: "A key handler should reset the world to 0 when the space key is pressed and otherwise leave the world unchanged. Write the handler and two check-expect tests: one for the space key and one representative unrelated key.", question_type: "short_answer", choices: [], selected_choice: nil, response: "```racket\n(define (handle-key ws ke)\n (cond [(key=? \" \") 0]\n [(else ws)]))\n\n(check-expect (handle-key 42 \" \") 0)\n(check-expect (handle-key 10 \"a\") 10)f\n```", correct: nil}, {question_prompt: "Explain the flow of information in a simple big-bang program after an on-tick event occurs. Describe what the tick handler receives and produces, what happens to that result, and how to-draw is involved.", question_type: "short_answer", choices: [], selected_choice: nil, response: "the on tick receives the world state and should return a world state (usually the tick function will update the world state in some way). Then the world program will pass this world state to the to-draw function which should produce an image to draw on the screen.", correct: nil}, {question_prompt: "Write the signatures for these three world handlers: (1) tick consumes a WorldState and produces the next WorldState; (2) draw consumes a WorldState and produces an Image; (3) handle-key consumes a WorldState and a KeyEvent and produces a WorldState. Pay attention to the parameter order for the key handler.", question_type: "short_answer", choices: [], selected_choice: nil, response: "; WorldState -> WorldState\n(define (tick ws) ws)\n\n; WorldState -> Image\n(define (draw ws) (text (to-string ws) 20 \"blackf'))\n\n; WorldState, KeyEvent -> WorldState\n(define (handle-key ws ke) ws)", correct: nil}, {question_prompt: "You are designing a world program but have not implemented its handlers yet. Write callable stubs for tick, draw, and handle-key with the signatures WorldState -> WorldState, WorldState -> Image, and WorldState KeyEvent -> WorldState. Do not implement the real behavior yet.", question_type: "short_answer", choices: [], selected_choice: nil, response: "(define (tick ws) ws)\n(define (draw ws) (text (to-string ws) 20 \"black\"))\n(define (handle-key ws ke) ws)", correct: nil}, {question_prompt: "Write a complete key handler named handle-key that resets a numeric WorldState to 0 when the space key is pressed and otherwise returns the world unchanged. Then write two check-expect tests: starting from 20 with the space key should produce 0, and starting from 20 with the key \"a\" should produce 20.", question_type: "short_answer", choices: [], selected_choice: nil, response: "(define (handle-key ws ke)\n (cond [(key=? \" \") 0]\n [(else ws)]))\n\n(check-expect (handle-key 20 \" \") 0)\n(check-expect (handle-key 20 \"r\") 20)", correct: nil}]}
Copy JSON