[racket] do I understand the concept World ?

 From: Matthias Felleisen (matthias at ccs.neu.edu) Date: Sun Mar 18 19:50:38 EDT 2012 Previous message: [racket] do I understand the concept World ? Next message: [racket] Racket style question Messages sorted by: [date] [thread] [subject] [author]

```This is all wrong even though 'it works' :-)  [[see my homepage]]

1. You need to agree on one set of possible worlds? What states can the world be in? What kind of data describes these states?

Call this set of data WORLD.

2. Then you need to design three functions with the following signatures:

gauge : WORLD -> IMAGE  :: renders the world state as an image
tock:     WORLD -> WORLD :: handles a clock event, receives world and produces new world depending on what clock ticks mean
toets:    WORLD KeyEvent -> WORLD :: handles a keyevent, received world plus key event and produced new world depending on what key strokes mean

On Mar 18, 2012, at 4:12 PM, ROELOF WOBBEN wrote:

> Hello,
>
> I have this programm :
>
> ; WorldState -> WorldState
> ; the clock ticked; decrease the gauge with 0.1
> ; example:
> ; given: 20, expected 19.9
> ; given: 78, expected 77.9
> (define (tock ws)
>   (if (> ws 0) (- ws 0.1)0 ))
>
> ; GaugeState -> Gaugestate.
> ; display the gauge.
> (define (gauge ws)
>   (overlay/xy (rectangle  100 20 "outline" "black") 0 0 (rectangle ws 20 "solid" "red")))
>
>
> ; World -> World
> ; adjust the gauge when the user uses the up or down key.
> ; given 20 and the down-key expected 20.5
> ; given 78 and the up-key expected 78,3
> (define (toets ws input)
>   (cond
>     [ (key=? input "down") (+ ws 0.3)]
>     [ (key=? input "up") (+ ws 0.5)]
>     [ else ws]
>     ))
>
> (define (main ws)
>    (big-bang ws (on-tick tock) (to-draw gauge) (on-key toets)))
>
>
>
> It runs perfectly but do I understand it right that the variable ws is the same as world.
>
> Roelof
>
> ____________________
>  Racket Users list:
>  http://lists.racket-lang.org/users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20120318/54a4a632/attachment.html>
```

 Posted on the users mailing list. Previous message: [racket] do I understand the concept World ? Next message: [racket] Racket style question Messages sorted by: [date] [thread] [subject] [author]