Created
August 23, 2011 14:07
-
-
Save danking/1165217 to your computer and use it in GitHub Desktop.
This file contains 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
(define-syntax symbol-append | |
(syntax-rules () | |
[(_ sym ...) | |
(string->symbol (string-append (symbol->string sym) ...))])) | |
(define-syntax (define-ustruct stx) | |
(define (make-updater-name struct-name field-name) | |
;; How do I get symbol-append to be defined here? | |
(symbol-append struct-name '-update- field-name)) | |
(define (make-updater-proc name-stx field-stx) | |
(let* ((field-name (syntax->datum field-stx)) | |
(struct-name (syntax->datum name-stx)) | |
(update-proc (datum->syntax name-stx | |
(make-updater-name struct-name | |
field-name)))) | |
#`(define (#,update-proc val s) | |
(struct-copy #,name-stx s [#,field-stx val])))) | |
(syntax-case stx () | |
((_ name fields kws ...) | |
#`(begin (define-struct name fields kws ...) | |
#,@(syntax-map (lambda (f) | |
(make-updater-proc #'name f)) | |
#'fields))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment