I'm attempting Exercise 22.3.3 from HtDP but do not know how to retrieve the label of the button that was clicked. I get this message draw-message: expected <string> as second argument, given: (instantiate (class ...) ...)
which seems to suggest that I need a string but I'm getting an instance of a class. Is the answer in the callback? If so, how do I de-structure it?
This is what I have so far:
(define pad1
'((1 2 3)
(4 5 6)
(7 8 9)
(\# 0 *)))
(define pad2
'((1 2 3 +)
(4 5 6 -)
(7 8 9 *)
(0 = \. /)))
(define (title t)
(make-message t))
(define display
(make-message ""))
(define (pad->gui p)
(cond
[(empty? p) empty]
[else (cons (button-maker (first p))
(pad->gui (rest p)))]))
;; make buttons out of a list
(define (button-maker a-list)
(cond
[(empty? a-list) empty]
[(number? (first a-list))(cons (make-button (number->string (first a-list)) call-back)
(button-maker (rest a-list)))]
[(symbol? (first a-list))(cons (make-button (symbol->string (first a-list)) call-back)
(button-maker (rest a-list)))]))
(define (call-back b)
(draw-message display ...))
(create-window
(append (list (list (title "Virtual Phone")))
(list (list display))
(pad->gui pad1)))
If I understand things correctly, each button will call call-back
when it is pressed. This in turn should call display
which will update the text. However, I do not understand how to retrieve the caller's label. e.g. if the button "9" is pressed, it will call call-back
. But how do I retrieve the value "9"? This is what I'm unsure about.