htdp
htdp copied to clipboard
add check-big-bang
This adds check-big-bang
and check-big-bang*
to 2htdp/universe
. A usage of check-big-bang
looks like:
(check-big-bang (main (make-posn 0 0))
[(make-tick) (make-posn 1 1)]
[(make-key "right") (make-posn 6 1)]
[(make-tick) (make-posn 7 2)]
[(make-key "left") (make-posn 2 2)]
[(make-key "down") (make-posn 2 7)]
[(make-tick) (make-posn 3 8)]
[(make-mouse 100 50 "button-down") (make-posn 100 50)]
[(make-tick) (make-posn 101 51)])
The check-big-bang*
version of this would look like:
(check-big-bang* (main (make-posn 0 0))
(list
(make-event-expect (make-tick) (make-posn 1 1))
(make-event-expect (make-key "right") (make-posn 6 1))
(make-event-expect (make-tick) (make-posn 7 2))
(make-event-expect (make-key "left") (make-posn 2 2))
(make-event-expect (make-key "down") (make-posn 2 7))
(make-event-expect (make-tick) (make-posn 3 8))
(make-event-expect (make-mouse 100 50 "button-down") (make-posn 100 50))
(make-event-expect (make-tick) (make-posn 101 51))))
The documentation still isn't finished, and it also doesn't handle sent messages properly yet.
That's neat! I like it. Looks possibly tricky to teach, though.
(Edit: I now use make-tick
, make-key
, etc. instead)
What should I do about name conflicts? The way to give it events to test with is with things like (tick)
, (key "a")
, and (receive "message")
, but what if someone defines an on-tick
handler named tick
? What if someone defines an on-receive
handler named receive
?
This is done in at least one place, here: https://github.com/racket/htdp/blob/master/htdp-lib/2htdp/uchat/chatter.rkt#L483
Should I name the event constructors differently? Or should I rename this handler function and force every future handler function to have names different from those? Also how will I know whether this might break any examples in the textbook or in other class materials? How should I deal with other possible name conflicts?
I name basically all my mouse handlers mouse
, so breaking those programs would be bad.
What about using the names on-tick
etc? Those names are already taken.
(Edit: I now use make-tick
, make-key
, etc. instead)
For check-big-bang*
, I need (tick)
, (key "a")
, (mouse 100 50 "button-down")
etc. to be values. If I were to overload on-tick
, then on-tick
would be a function of zero arguments at the same time as being a big-bang clause literal, and that would be really confusing.
That seems like a point against the current design of check-big-bang*
.
Tick isn't the best example, so how about using on-mouse
to show:
(check-big-bang (main 0)
[(on-mouse 123 50 "button-down") 123])
It would be weird to have on-mouse
be both the method for adding a mouse handler and the way to construct mouse events in check-big-bang
. We do need a different name if we want to avoid that.
I think that makes a lot of sense, actually. I would find using on-mouse
the easiest way to teach this.
@AlexKnauth do you have plans to pursue this further, or should it be closed?
It can be closed. check-big-bang
is not on my priorities at this point