1. Your program does NOT change a string. It changes the state of the traffic 
light (or it tells drracket to keep track of a different state). The string 
"rood" remains the same in eternity. 

2. You're missing test cases, and if you had tested the program you would have 
discovered it before evaluating (main "rood"). 

3. You can understand your program in terms of interactions after it signals an 
error: 

> (tock "rood")  ;; what is the state after one clock tick 
"groen"
> (tock (tock "rood"))  ;; what is the state after two clock ticks 
"oranje"
> (light (tock (tock "rood"))) ;; how will DrRacket render the state after two 
> clock ticks 
. ;; <-- some yellow circle 
> ;; <-- now try three clock ticks. 



On Mar 19, 2012, at 3:10 PM, Roelof Wobben wrote:

> Hello,
> 
> I have to make a traffic-light which changes color after each tick of the 
> computer.
> So I thought this would work :
> 
> 
> ;; String -> Image
> ;; given a state of a trafic-light display a circle of the given color if 
> it's a color of the traffic-light otherwise error
> (define (light color)
>  (cond
>    [(string=? color "oranje") (circle 10 "solid"  "yellow")]
>    [(string=? color "rood") (circle 10 "solid" "red" )]
>    [(string=? color "groen") (circle 10 "solid" "green" )]
>    [else (error  "Error : geen kleur van een verkeerslicht ingevoerd in de 
> functie" " light")]
>    ))
> 
> ;; World -> World
> ;; Given a World and set the traffic-light to the next color
> (define (tock color)
>  ( cond
>     [ (string=? color "oranje") "red"]
>     [ (string=? color "rood") "groen"]
>     [ (string=? color "groen") "oranje"]
>     ))
> 
> (define (main color)
>  ( big-bang color (on-tick tock) (to-draw light)))
> 
> (main "rood")
> 
> But the contents of color does not change so I get a error message.
> What is the racket way to change the value of a string.
> 
> Roelof
> 
> ____________________
> Racket Users list:
> http://lists.racket-lang.org/users


____________________
  Racket Users list:
  http://lists.racket-lang.org/users

Reply via email to