Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to retrieve a button's label in Racket/PLT-Scheme?
    primarykey
    data
    text
    <p>I'm attempting <a href="http://htdp.org/2003-09-26/Book/curriculum-Z-H-28.html#node_chap_22" rel="nofollow">Exercise 22.3.3 from HtDP</a> but do not know how to retrieve the label of the button that was clicked. I get this message <code>draw-message: expected &lt;string&gt; as second argument, given: (instantiate (class ...) ...)</code> 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?</p> <hr> <p>This is what I have so far:</p> <pre><code>(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-&gt;gui p) (cond [(empty? p) empty] [else (cons (button-maker (first p)) (pad-&gt;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-&gt;string (first a-list)) call-back) (button-maker (rest a-list)))] [(symbol? (first a-list))(cons (make-button (symbol-&gt;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-&gt;gui pad1))) </code></pre> <p>If I understand things correctly, each button will call <code>call-back</code> when it is pressed. This in turn should call <code>display</code> 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 <code>call-back</code>. But how do I retrieve the value "9"? This is what I'm unsure about.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload