Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as Scheme by neilv ( 15 years ago )
#lang racket/base

(require syntax/parse)

(define (foo stx)
  (syntax-parse stx
    (((~datum myform) NAME:id SUB ...)
     (quasisyntax/loc stx
       (newform NAME:id
                #,@(map (lambda (sub-stx)
                          (syntax-parse sub-stx
                            (((~or (~once (~seq #:alpha   ALPHA)   #:name "#:alpha option")
                                   (~once (~seq #:bravo   BRAVO)   #:name "#:bravo option"))
                              ...
                              BODYn ...)
                             #`(yo ALPHA BRAVO charlie))))
                        (syntax->list (syntax (SUB ...)))))))))

(syntax->datum (foo #'(myform John (#:alpha 42 #:bravo 43) (#:bravo 45 #:alpha 44))))
;;==> (newform NAME:id (yo 42 43 charlie) (yo 44 45 charlie))

 

Revise this Paste

Your Name: Code Language: