Back Edit Delete

Write a complete key handler named handle-key that resets a numeric WorldState to 0 when the space key is pressed and otherwise returns the world unchanged. Then write two check-expect tests: starting from 20 with the space key should produce 0, and starting from 20 with the key "a" should produce 20.

Short answer

Accepted answer

(define (handle-key ws ke)
(cond [(key=? ke " ") 0]
[else ws]))

(check-expect (handle-key 20 " ") 0)
(check-expect (handle-key 20 "a") 20)