Skip to content

Instantly share code, notes, and snippets.

@shhyou
Created August 10, 2018 19:23
Show Gist options
  • Save shhyou/4e0090b8f9c33f2c02cf3b1a2290cd93 to your computer and use it in GitHub Desktop.
Save shhyou/4e0090b8f9c33f2c02cf3b1a2290cd93 to your computer and use it in GitHub Desktop.
(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