2011-02-01 54 views
1

Exercise 35.4.2 from HtDP中,我實現了GUI,並有一個名爲「Remove」的按鈕,它調用一個回調函數。這是它:如何使用`set!`忽略球拍中的副作用?

(define (cb-remove x) 
    ((lambda (name result) 
    (cond 
     [(number? result) (remove-name name address-book)] 
     [else (draw-message msg "Not found")])) 
    (string->symbol (text-contents label-name)) 
    (lookup (string->symbol (text-contents label-name)) address-book))) 

當我運行此,我收到以下消息:button-callback: result of type <Boolean> expected, your function produced #<set!-result>。問題是我必須撥打set!才能更改地址簿。但是,set!的結果是(void),它不能與布爾類型組合。我怎樣才能避免這個問題?感謝您的任何見解。

回答

2

簡單:

(begin (set! foo bar) #t) 
+0

輝煌!那正是我正在尋找的。謝謝! – Greenhorn 2011-02-01 04:01:54