On Wed, Dec 19, 2012 at 5:07 PM, Chen Xiao <chenxiao770...@gmail.com> wrote: > Why racket's class not like Java have a constructor method?
The body of the class can do things that a constructor method can typically do, including calling the instantiation for the super class. Example: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; #lang racket (define thing% (class object% (init-field name) (super-new) (printf "making up ~a\n" name))) (define food% (class thing% (init-field calories) (inherit-field name) (printf "bubble, bubble...\n") (super-new) (printf "Cooking ~a (~a cals)\n" name calories))) (define t (new thing% [name "rainbow"])) (define f (new food% [name "ramen"] [calories 56000])) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; The calls to 'super-new' there are calls to the parent class's initializer code. Does this do what you want? ____________________ Racket Users list: http://lists.racket-lang.org/users