Skip to content

Instantly share code, notes, and snippets.

@philnguyen
Created December 9, 2014 16:34
Show Gist options
  • Save philnguyen/04ef4e8ff239f3a3d533 to your computer and use it in GitHub Desktop.
Save philnguyen/04ef4e8ff239f3a3d533 to your computer and use it in GitHub Desktop.
Fully expanded `(struct x (a b) #:transparent)`
#lang racket/base
(begin
(define-syntaxes (struct:x x1 x? x-a x-b) (#%app values))
(define-syntaxes
(x)
(#%app
make-self-ctor-checked-struct-info
(lambda ()
(#%app
list
(quote-syntax struct:x)
(quote-syntax x)
(quote-syntax x?)
(#%app list (quote-syntax x-b) (quote-syntax x-a))
(#%app list '#f '#f)
'#t))
(#%app list (#%app list) (#%app list))
(lambda () (quote-syntax x1))))
(define-values
(struct:x x1 x? x-a x-b)
(let-values (((struct: make- ? -ref -set!)
(letrec-syntaxes+values (((struct-field-index12)
(convert-renamer
(lambda (stx)
(syntax-case stx (a b)
((_ a) #'0)
((_ b) #'1)
((_ name)
(raise-syntax-error
#f
"no such field"
stx
#'name)))))))
()
(letrec-syntaxes+values (((struct-field-index1)
(values
(make-rename-transformer
(quote-syntax
struct-field-index12)))))
()
(#%app
make-struct-type
'x
'#f
'2
'0
'#f
null
(#%app current-inspector)
'#f
'(0 1)
'#f
'x)))))
(#%app
values
struct:
make-
?
(#%app make-struct-field-accessor -ref '0 'a)
(#%app make-struct-field-accessor -ref '1 'b)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment