-
Notifications
You must be signed in to change notification settings - Fork 0
/
mylet.rkt
39 lines (26 loc) · 929 Bytes
/
mylet.rkt
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
;; (module mylet racket
(define-for-syntax (mylet-param param-stx)
(syntax-case param-stx ()
[((a ...) b) #'((a ...) b)]
[(a b) #'((a) (values b))]))
(define-for-syntax (mylet-params params-stx)
(datum->syntax params-stx (map mylet-param (syntax->list params-stx))))
(define-syntax (mylet_ stx)
(syntax-case stx ()
[(_ n () body ...) #'(begin body ...)]
[(_ n (a ...) body ...)
#`(n #,(mylet-params #'(a ...)) body ...)]))
(define-syntax mylet
(syntax-rules ()
[(_ a ...) (mylet_ let-values a ...)]))
(define-syntax mylet*
(syntax-rules ()
[(_ a ...) (mylet_ let*-values a ...)]))
(define-syntax myletrec
(syntax-rules ()
[(_ a ...) (mylet_ letrec-values a ...)]))
;; (provide mylet mylet* myletrec))
(mylet ([a 5]
[(b c) (values 7 8)])
(display (list a b c)))
;; (mylet () 1)