-
Notifications
You must be signed in to change notification settings - Fork 0
/
README
56 lines (47 loc) · 1.6 KB
/
README
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
47
48
49
50
51
52
53
54
55
56
This repository contains an implementation of Oleg Kiselyov's CK-macros.
Cloning
-------
This repository includes submodules. If you use the following clone command,
it will automatically initialize and update each submodule in the repository.
$ git clone --recursive https://github.com/mnieper/rapid-macros.git
Run Tests
---------
Assuming you have Chibi Scheme installed, you can run the tests by issuing
the command
chibi-scheme -Irapid-lib tests.scm
in the main directory. The test suite should work as well with any other
R7RS-compliant implementation of the Scheme programming language although
the exact command-line syntax may differ.
Example
-------
$ chibi-scheme -mscheme.base -mrapid.macros -msrfi.2
> (define-macro simple-match ()
((simple-match expr (pattern template) ...)
(m-expression
`(call-with-current-continuation
(lambda (return)
(let ((e expr))
(or (and-let* ,(%compile-pattern 'pattern 'e) (return template))
...
(error "does not match" expr))))))))
> (define-macro %compile-pattern ()
((%compile-pattern '() 'e)
'(((null? e))))
((%compile-pattern '(pattern1 pattern2 ...) 'e)
`(((not (null? e)))
(e1 (car e))
(e2 (cdr e))
,@(%compile-pattern 'pattern1 'e1)
,@(%compile-pattern '(pattern2 ...) 'e2)))
((%compile-pattern 'x 'e)
(m-if (m-symbol? 'x)
'((x e))
'(((equal? x e))))))
> (define (f e)
(simple-match e
(10 'ten)
((11 x) x)))
> (f 10)
ten
> (f '(11 eleven))
eleven