-
Notifications
You must be signed in to change notification settings - Fork 4
/
match.ss
43 lines (35 loc) · 1.03 KB
/
match.ss
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
#lang scheme/base
(require "base.ss")
(require (for-syntax scheme/base
(cce-scheme-in syntax))
scheme/match
srfi/26
"debug.ss")
; Match expanders --------------------------------
; (_ expr pattern ...)
(define-match-expander match:eq?
(lambda (stx)
(syntax-case stx ()
[(_ expr pattern ...)
#'(? (cut eq? <> expr) pattern ...)]))
(redirect-transformer #'eq?))
; (_ expr pattern ...)
(define-match-expander match:equal?
(lambda (stx)
(syntax-case stx ()
[(_ expr pattern ...)
#'(? (cut equal? <> expr) pattern ...)]))
(redirect-transformer #'equal?))
; (_ proc pattern ...)
(define-match-expander app*
(syntax-rules ()
[(_ expr pattern)
(app expr pattern)]
[(_ expr pattern ...)
(app (lambda (val)
(call-with-values (cut expr val) list))
(list pattern ...))]))
; Provide statements -----------------------------
(provide (rename-out [match:eq? eq?]
[match:equal? equal?])
app*)