[racket] Help With a Macro (tricky?)
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 13-01-12 11:37, Marijn wrote:
> (define-syntax fast-class (lambda (stx) (syntax-case stx () ((_
> _field_ ...) (with-syntax (((_getter_ ...) (datum->syntax #f (map
> (lambda (f) (string->symbol (string-append "get-" (symbol->string
> f)))) (syntax->datum #'(_field_ ...)) )) )) #'(class object%
> (super-new) (init-field _field_ ...) (define/public (_getter_)
> _field_) ...) )))))
>
> (define fast-class1% (fast-class size weight))
>
> (define fast1 (new fast-class1% (size 2) (weight 200))) (send fast1
> get-size) (send fast1 get-weight)
I forgot to point out that you now basically have a struct with clunky
method access; so only use this for educational purposes, for real
code use a real struct.
Marijn
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.18 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAk8QJpwACgkQp/VmCx0OL2xy6gCeKKLjNxaBeOfNHiEV/6lY3tdV
no0Anj1pVvx0Ez3mu6A1sMsZLFK0Npe+
=d68J
-----END PGP SIGNATURE-----