htdp icon indicating copy to clipboard operation
htdp copied to clipboard

add check-big-bang

Open AlexKnauth opened this issue 8 years ago • 7 comments

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.

AlexKnauth avatar Oct 01 '16 03:10 AlexKnauth

That's neat! I like it. Looks possibly tricky to teach, though.

stamourv avatar Oct 01 '16 14:10 stamourv

(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?

AlexKnauth avatar Oct 01 '16 22:10 AlexKnauth

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.

samth avatar Oct 02 '16 00:10 samth

(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.

AlexKnauth avatar Oct 02 '16 00:10 AlexKnauth

That seems like a point against the current design of check-big-bang*.

samth avatar Oct 03 '16 13:10 samth

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.

AlexKnauth avatar Oct 03 '16 14:10 AlexKnauth

I think that makes a lot of sense, actually. I would find using on-mouse the easiest way to teach this.

samth avatar Oct 03 '16 15:10 samth

@AlexKnauth do you have plans to pursue this further, or should it be closed?

samth avatar Oct 11 '22 14:10 samth

It can be closed. check-big-bang is not on my priorities at this point

AlexKnauth avatar Oct 11 '22 14:10 AlexKnauth