Created
May 24, 2012 22:41
-
-
Save takikawa/2784657 to your computer and use it in GitHub Desktop.
Inits are weird
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Welcome to Racket v5.3.0.8. | |
-> (define c (class object% (init [x 0]) (super-new))) | |
-> (define d (class c (init [x 0] [y 0]) (super-instantiate () [x x]))) | |
-> (make-object d 1) | |
(object:d ...) | |
-> (make-object d 1 2) | |
(object:d ...) | |
-> (make-object d 1 2 4) | |
; instantiate: unused initialization arguments: (x 4) for instantiated class: d | |
; [,bt for context] | |
-> (make-object d 1 2 4 5) | |
; instantiate: too many initialization arguments: 1 2 4 5 for class: d [,bt for | |
; context] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Oh yeah? Try this:
-> (define c% (class object% (init c d) (super-new)))
-> (define d% (class c% (init a b e) (if (zero? e) (super-new [c a] [d b]) (super-new [c a]))))
-> (new d% [a 1] [b 2] [e 0])
(object:d% ...)
-> (new d% [a 1] [b 2] [e 3])
instantiate: no argument for required init variable: d in class: c%
And we were all sad pandas :(