Created
May 19, 2012 00:42
-
-
Save danking/2728373 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #lang racket | |
| (require (for-syntax racket racket/syntax)) | |
| (provide (all-defined-out)) | |
| (define-syntax (struct* stx) | |
| (syntax-case stx () | |
| ((_ name (args ...) (defaults ...) others ...) | |
| (with-syntax ((arg-list (datum->syntax #'(args ...) | |
| (for/list ((arg (syntax->list #'(args ...))) | |
| (default (syntax->datum #'(defaults ...)))) | |
| (if (not (eq? '_ default)) | |
| (list arg default) | |
| arg)))) | |
| (real-constructor (format-id #'name "make-~a" #'name))) | |
| (displayln #'real-constructor) | |
| #'(begin (struct name (args ...) #:constructor-name constructor others ...) | |
| (define (real-constructor . arg-list) | |
| (constructor args ...))))))) | |
| (struct* posn (x y z) (_ 0 1) #:transparent) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment