You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
16 lines
556 B
Racket
16 lines
556 B
Racket
8 years ago
|
#lang racket/base
|
||
|
(require racket/list)
|
||
|
(provide (all-defined-out))
|
||
|
|
||
|
(define (syntax-flatten stx)
|
||
8 years ago
|
(let* ([stx-unwrapped (syntax-e stx)]
|
||
|
[maybe-pair (and (pair? stx-unwrapped) (flatten stx-unwrapped))])
|
||
|
(if maybe-pair
|
||
|
(append-map syntax-flatten maybe-pair)
|
||
|
(list stx))))
|
||
|
|
||
|
(module+ test
|
||
|
(require rackunit)
|
||
|
(check-equal? (map syntax->datum (syntax-flatten #'(let ([x 42])
|
||
|
(* x y)))) '(let x 42 * x y))
|
||
|
(check-equal? (map syntax->datum (syntax-flatten #'let)) '(let)))
|