Created
August 10, 2018 19:23
-
-
Save shhyou/4e0090b8f9c33f2c02cf3b1a2290cd93 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
(require (for-syntax syntax/parse | |
racket/syntax)) | |
(define-type-alias Unit Symbol) ;; Temp | |
(struct Parameter ([p-id : String] | |
[p-desc : String] | |
;[p-val : Measure] | |
[p-num : Number] | |
[p-unit : Unit]) | |
#:transparent) | |
(define-syntax (def-par stx) | |
(syntax-parse stx | |
[(_ [~seq name:id descr:string val:number punit:expr] ...) | |
#:fail-when (check-duplicate-identifier (syntax->list #'(name ...))) "duplicate identifier" | |
#:with [name-str ...] (map (λ (name) #`#,(symbol->string (syntax-e name))) (syntax->list #'[name ...])) | |
#:with [ids ...] (map | |
(λ (s) (format-id s "par-~a" s)) | |
(syntax->list #'[name ...])) | |
#'(begin (define ids (Parameter name-str descr val punit)) ...)])) | |
(define kilogram 'kilogram) | |
(def-par | |
h "handling time" 123 kilogram | |
a "attack rate" 321 kilogram) | |
par-h |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment