Keeping it Clean with Syntax Parameters
Eli Barzilay, Ryan Culpepper, Matthew Flatt
1
Keeping it Clean with Syntax Parameters Eli Barzilay, Ryan - - PowerPoint PPT Presentation
Keeping it Clean with Syntax Parameters Eli Barzilay, Ryan Culpepper, Matthew Flatt 1 Macros Macros are great. 2 Macros Hygienic macros are great. 3 Macros Hygienic macros are great, but... 4 Macros Hygienic macros are great, but...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
(define-syntax (define-syntax-rules/capture stx0) (syntax-case stx0 () [(def name (capture ...) (keyword ...) [patt templ] ...) (with-syntax ([L (datum->syntax #'def 'L)]) #'(define-syntax (name stx) (syntax-case stx (keyword ...) [patt (with-syntax ([user-ctx stx]) #'(with-links L user-ctx (capture ...) templ))] ...)))])) (define-syntax with-links (syntax-rules () [(with-links L user-ctx (capture ...) template) (let-syntax ([L (lambda (stx) (syntax-case stx () [(L e (... ...)) (with-syntax ([(id (... ...)) (list (datum->syntax #'L 'capture) ...)] [(id* (... ...)) (list (syntax-local-introduce (datum->syntax #'user-ctx 'capture)) ...)]) #'(let-syntax ([id* (make-rename-transformer #'id)] (... ...)) e (... ...)))]))]) template)]))
24
25
26
27
28
29
30
31
(Even worse with core language constructs.)
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46