diff options
-rwxr-xr-x | ruse.scm | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/ruse.scm b/ruse.scm new file mode 100755 index 0000000..1fff10a --- /dev/null +++ b/ruse.scm | |||
@@ -0,0 +1,50 @@ | |||
1 | #!/bin/sh | ||
2 | #| -*- mode: scheme; geiser-scheme-implementation: chicken -*- | ||
3 | exec csi -R r7rs -ss "$0" "$@" | ||
4 | RUSE --- by case duckworth | ||
5 | Make r7rs library files out of source scheme files | ||
6 | |# | ||
7 | |||
8 | #+chicken (import (r7rs)) | ||
9 | (import (scheme base) | ||
10 | (scheme file)) | ||
11 | |||
12 | (define (filter pred xs) | ||
13 | (let loop ((pred pred) | ||
14 | (xs xs) | ||
15 | (acc '())) | ||
16 | (cond | ||
17 | ((null? xs) | ||
18 | (reverse acc)) | ||
19 | ((pred (car xs)) | ||
20 | (loop pred (cdr xs) (cons (car xs) acc))) | ||
21 | (else | ||
22 | (loop pred (cdr xs) acc))))) | ||
23 | |||
24 | (define (top-level-defines tree) | ||
25 | (filter (lambda (x) | ||
26 | (memq (car x) | ||
27 | '( define | ||
28 | define-syntax | ||
29 | define-record-type | ||
30 | define-values | ||
31 | ;; others ? | ||
32 | ))) | ||
33 | tree)) | ||
34 | |||
35 | (define (top-level-names tree) | ||
36 | (map (lambda (d) | ||
37 | (if (pair? (cadr d)) | ||
38 | (caadr d) | ||
39 | (cadr d))) | ||
40 | (top-level-defines tree))) | ||
41 | |||
42 | (define (slurp-file file) | ||
43 | (with-input-from-file file | ||
44 | (lambda () | ||
45 | (let loop ((next (read)) | ||
46 | (it '())) | ||
47 | (if (eof-object? next) | ||
48 | (reverse it) | ||
49 | (loop (read) (cons next it))))))) | ||
50 | |||