Skip to content

Instantly share code, notes, and snippets.

@takikawa
Created May 24, 2012 22:41
Show Gist options
  • Save takikawa/2784657 to your computer and use it in GitHub Desktop.
Save takikawa/2784657 to your computer and use it in GitHub Desktop.
Inits are weird
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]
@sstrickl
Copy link

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 :(

@samth
Copy link

samth commented May 30, 2012

@sstrickl, when you do that, Racket should reach out and slap you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment