[racket] string problem question

From: Roelof Wobben (r.wobben at home.nl)
Date: Mon Mar 19 15:10:47 EDT 2012

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


Posted on the users mailing list.