Line | |
---|
1 | (use syntax-case) |
---|
2 | |
---|
3 | (define-syntax mu |
---|
4 | (syntax-rules () |
---|
5 | ((mu argument ...) (lambda (f) (f argument ...))))) |
---|
6 | |
---|
7 | (define m (mu 1 2 3)) |
---|
8 | (define v (lambda () (values 1 2 3))) |
---|
9 | (define mm (lambda (x) |
---|
10 | (if (< x 0) |
---|
11 | (mu 1 2 3) |
---|
12 | (if (= x 0) |
---|
13 | (mu 4 5 6) |
---|
14 | (mu 7 8 9))))) |
---|
15 | (define vv (lambda (x) |
---|
16 | (if (< x 0) |
---|
17 | (values 1 2 3) |
---|
18 | (if (= x 0) |
---|
19 | (values 4 5 6) |
---|
20 | (values 7 8 9))))) |
---|
21 | |
---|
22 | (define-syntax dotimes |
---|
23 | (syntax-rules () |
---|
24 | ((dotimes (i count) body0 body1 ...) |
---|
25 | (let ((%COUNT count)) |
---|
26 | (do ((i 0 (+ i 1))) |
---|
27 | ((= i %COUNT)) |
---|
28 | body0 |
---|
29 | body1 |
---|
30 | ...))))) |
---|
31 | |
---|
32 | (define (test-m) |
---|
33 | (dotimes (i 10000000) |
---|
34 | (m (lambda (x y z) |
---|
35 | (+ i x y z))))) |
---|
36 | (define (test-v) |
---|
37 | (dotimes (i 10000000) |
---|
38 | (receive (x y z) (v) |
---|
39 | (+ i x y z)))) |
---|
40 | (define (test-mm) |
---|
41 | (dotimes (i 10000000) |
---|
42 | ((mm i) (lambda (x y z) |
---|
43 | (+ i x y z))))) |
---|
44 | (define (test-vv) |
---|
45 | (dotimes (i 10000000) |
---|
46 | (receive (x y z) (vv i) |
---|
47 | (+ i x y z)))) |
---|
48 | |
---|
49 | |
---|
50 | (time (test-m)) |
---|
51 | (time (test-v)) |
---|
52 | (time (test-mm)) |
---|
53 | (time (test-vv)) |
---|
Note: See
TracBrowser
for help on using the repository browser.