Skip to content

Instantly share code, notes, and snippets.

@danking
Created May 19, 2012 00:42
Show Gist options
  • Select an option

  • Save danking/2728373 to your computer and use it in GitHub Desktop.

Select an option

Save danking/2728373 to your computer and use it in GitHub Desktop.
#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