forked from guenchi/Core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
syntax.sc
46 lines (40 loc) · 1.49 KB
/
syntax.sc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
(library (core syntax)
(export define-syntax-rule ~> ~>> and-let*
assoc/free-identifier=? member/free-identifier=?)
(import (chezscheme))
(define-syntax define-syntax-rule
(syntax-rules ()
[(_ (macro-name . patterns) form)
(define-syntax macro-name
(syntax-rules ()
[(_ . patterns) form]))]))
;;threading macros
(define-syntax ~>
(syntax-rules ()
[(_ init) init]
[(_ init (f args ...) r ...) (~> (f init args ...) r ...)]))
(define-syntax ~>>
(syntax-rules ()
[(_ init) init]
[(_ init (f args ...) r ...) (~>> (f args ... init) r ...)]))
(define-syntax and-let*
(syntax-rules ()
[(_ () body ...)
(let () body ...)]
[(_ ([name value] rest ...) body ...)
(let ([name value])
(if name (and-let* (rest ...) body ...)
#f))]))
(define (assoc/free-identifier=? x lst)
(if (null? lst)
#f
(if (free-identifier=? x (caar lst))
(car lst)
(assoc/free-identifier=? x (cdr lst)))))
(define (member/free-identifier=? x lst)
(if (null? lst)
#f
(or (free-identifier=? x (car lst))
(member/free-identifier=? x (cdr lst)))
))
)