Info: Signature Story

Why do handlers have specific signatures?

Racket requires functions with specific signatures for the handlers in a big bang animation. This page motivates that with a story.

Story

Once upon a time, every teacher in my school required students in their class to make “name tents”. This was a great idea, but every teacher had different requirements.

  • First period wanted your preferred first name, written large on the name tent.
  • Second period wanted a preferred name and a last initial.
  • Third period wanted a preferred name (large), and also your grade written in the lower right.
  • Fourth period wanted a preferred name (large), and a stripe made of your favorite color drawn along the left side.

Some students found themselves carrying around four different name tents, each one different, to satisfy each class’s requirements.

Other students thought this was ridiculous and they made one name tent - preferred name written large, followed by last initial, grade in the lower right corner, with a stripe of their favorite color drawn along the left side. They used this one name tent to satisfy the requirements of each class they attended.

Racket Connection

You could imagine a similar situation in the Big Bang:

  • Mouse handler A wants no additional information, just the image being currently shown. All it does is (rotate 5 img).
  • Mouse handler B wants the image being currently shown and the x-coordinate of the mouse. It does (place-image img x 100 bg).
  • Mouse handler C wants the image being currently shown and the y-coordinate of the mouse.
  • Mouse handler D wants the current image and the event (like "button-down").
  • Mouse handler E wants only the x and y coordinates of the mouse, and no information about the past image. It does (place-image pic:stick-figure x y bg).

This would be possible, you could indicate in big-bang which kinds of information you wanted:

    (on-mouse:old A)
    (on-mouse:old+x B)
    (on-mouse:old+y C)
    (on-mouse:old+event D)
    (on-mouse:x+y E)

The developers of Racket decided that this was a ridiculous level of detail, and instead they decided to make a rule to make their own lives easier: your mouse handler function must take in all of the available information: old image, x-coordinate of the mouse, y-coordinate of the mouse, and the “mouse-event”. You don’t have to use any of the information, but for consistency you have to have enough parameters to your function so there is a place to put each piece of information.

Last modified August 18, 2023: 2022-2023 End State (7352e87)