问题
I am wanting to do two different things at each tick. Is it possible to have multiple on-tick event handlers in a big-bang environment?
This is what I would like to do:
(big-bang world
(on-draw show-world)
(on-tick event1 event2 1))
or
(big-bang world
(on-draw show-world)
(on-tick event1 1)
(on-tick event2 1))
Neither of these methods is allowed. Is there a way to do this?
Thank you.
回答1:
What would it mean?
For example, suppose that
;; A World is a Nat (a natural number).
and here are the two tick handlers:
;; advance-by-one : World -> World
(define (advance-by-one w)
(add1 w))
;; reset-at-ten : World -> World
(define (reset-at-ten w)
(if (< w 10) w 0))
If the current World is 9
, then what would you expect the next World to be? (I can think of two plausible answers; you have to pick one.)
Can you define another function that has the meaning you want and just use that (single) function as the tick handler? (Hint: you should use the two existing handler functions rather than trying to merge their definitions into one big function.)
(If you've made it to ISL:) What if you had three handlers, or four, or ten, that you wanted to compose together? Can you design a function that takes a list of handlers and produces a single handler function?
来源:https://stackoverflow.com/questions/53663171/in-racket-is-it-possible-to-have-multiple-event-handlers-in-big-bang