Hello.
I want to switch two images, according to the flag defined in a WorldState of big-bang in 2htdp/universe.
Let's say, the experimental code I wrote was like this:
#lang racket
(require 2htdp/image 2htdp/universe)
(struct world (flag))
(define (place0 w)
(place-image
(text "foo" 15 "black")
300
200
(empty-scene 640 400)))
(define (place1 w)
(place-image
(text "bar" 15 "black")
300
200
(empty-scene 640 400)))
(big-bang (world #f)
(to-draw (if (world-flag world) place0 place1))) ; this does not work
I want to change the image shown, according to the flag of the WorldState; however, because the name of the world struct constructed in big-bang is implicitly determined, I do not know how to refer to the "name" of it.
Of course, we can name the WorldState outside of big-bang, as shown below.
#lang racket
(require 2htdp/image 2htdp/universe)
(struct world (flag))
(define world_0 (world #f)) ; name the world struct outside of "big-bang"
(define (place0 w)
(place-image
(text "foo" 15 "black")
300
200
(empty-scene 640 400)))
(define (place1 w)
(place-image
(text "bar" 15 "black")
300
200
(empty-scene 640 400)))
(big-bang world_0
(to-draw (if (world-flag world_0) place0 place1))) ;; It works!
However, I prefer a smarter way, or the way directly to refer to the implicit name, defined by big-bang.
Thanks.