PasteRack.org
Paste # 61697
2014-11-26 13:16:01

Forked from paste # 78794.

Fork as a new paste.

Paste viewed 11 times.


Embed:

macro with define

  1. #lang racket
  2.  
  3.  
  4. (define-syntax (kin-plot stx)
  5.   (syntax-case stx ()
  6.     [(_ lst (Kx ...))
  7.      (begin
  8.        (define base-color 45)
  9.        (with-syntax ([(Kx ...) (for/list ([s (in-syntax #'(Kx ...))])
  10.                                  (syntax->datum s))]
  11.                      [(Kxs ...) (generate-temporaries #'(Kx ...))]
  12.                      [(label ...) (for/list ([s (in-syntax #'(Kx ...))])
  13.                                     (symbol->string (syntax-e s)))]
  14.                      [(color ...) (for/list ([s (in-syntax #'(Kx ...))])
  15.                                     (set! base-color (add1 base-color))
  16.                                     base-color)])
  17.          #'(let ()
  18.              (define-values (Kxs ...)
  19.                (for/fold ([Kxs '()] ...)
  20.                          ([v (in-list lst)])
  21.                  (match-define (vector x state) v)
  22.                  (match-define (vector K1 K1P K1PP K2 K2P K2PP K3 K3P K3PP K4P) state)
  23.                  (values
  24.                   (cons (vector x Kx) Kxs)
  25.                   ...)))
  26.              (list
  27.               (lines Kxs  #:color color #:style color #:label label #:width 2)
  28.               ...))))]))

=>