PasteRack.org
Paste # 88615
2017-02-08 16:39:00

Fork as a new paste.

Paste viewed 1530 times.


Embed:

  1. #lang racket/base
  2.  
  3. (require
  4.   (for-syntax
  5.    racket/base
  6.    syntax/parse
  7.    ))
  8.  
  9. (define (test #:a a #:b b #:c c)
  10.   [list a b c])
  11.  
  12. (define-syntax (test-syntax stx)
  13.  
  14.   (define-splicing-syntax-class spec
  15.     #:datum-literals (:a :b :c)
  16.     (pattern (~seq :a n:number)
  17.              #:attr key #'#:a
  18.              #:attr value #'n)
  19.     (pattern (~seq :b n:number)
  20.              #:attr key #'#:b
  21.              #:attr value #'(* 2 n))
  22.     (pattern (~seq :c n:number)
  23.              #:attr key #'#:c
  24.              #:attr value #'(* 4 n))
  25.     )
  26.  
  27.   (syntax-parse stx
  28.     ([_ s:spec ...]
  29.      #'(keyword-apply
  30.         test
  31.         (s.key ...)
  32.         (s.value ...)
  33.         '()))))
  34.  
  35. (test-syntax :b 7 :a 3)

=>

program::-1: #%datum: keyword used as an expression

  in: #:b