我来自Java和Python,对于Racket中的面向对象代码理解有些困难。
Given
(define food% (class object% (super-new) (init-field name) (field (edible? #t)) (init-field healthy?) (init-field tasty?) ) )
define a superclass fruit% of food% which always has the healthy? value of #t, and which doesn't require one to set the healthy? field when defining a new fruit.
In racket/gui, define a super-class of button% called text-input-button% which has two new fields, output (ideally of type text-field%) and text (ideally a string), and whose callback field has as its value a function which appends the value of the text field to the current contents of the value of the output field. Practically, the buttons would input characters into the text-field specified.
我认为如果我能看到这两个例子,我的困惑会得到很大的解决。也就是说,我正在寻找“适当”或教科书上的方法来做到这一点,而不是使用set!这样一些兜圈子的技巧,除非这是所有适当方法的实质。