Skip to content

Commit 1eb1066

Browse files
lassikarthurgleckler
authored andcommitted
Add two library name commands
1 parent 9eccad2 commit 1eb1066

File tree

1 file changed

+44
-15
lines changed

1 file changed

+44
-15
lines changed

srfi-tools/library.sld

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
(define-library (srfi-tools library)
2-
(export srfi-library-names-sxml
2+
(export srfi-map-library-names
3+
srfi-library-names
4+
srfi-r6rs-imports
5+
srfi-library-names-sxml
36
srfi-generate-library-names)
47
(import (scheme base)
58

@@ -14,6 +17,38 @@
1417
(srfi-tools url))
1518
(begin
1619

20+
(define (srfi-map-library-names proc)
21+
(filter-map (lambda (srfi)
22+
(let ((name (srfi-library-name srfi)))
23+
(and name (proc (srfi-number srfi) name))))
24+
(srfi-list)))
25+
26+
(define (srfi-library-names)
27+
(srfi-map-library-names cons))
28+
29+
(define-command (library-names)
30+
"List library names (SRFI 97 and beyond)."
31+
(display-two-column-table (srfi-library-names)))
32+
33+
(define (r6rs-import num name)
34+
;; Return a string instead of an S-expression because symbols
35+
;; starting with a colon are handled inconsistently by Scheme
36+
;; implementations. Some of them escape such symbols to avoid
37+
;; confusing them with keywords. R6RS standard syntax does not
38+
;; support those escapes.
39+
(format "(import (srfi :~a ~a))" num name))
40+
41+
(define (r7rs-import num name)
42+
;; R7RS may add the names at some point.
43+
(format "(import (srfi ~a))" num))
44+
45+
(define (srfi-r6rs-imports)
46+
(srfi-map-library-names r6rs-import))
47+
48+
(define-command (r6rs-imports)
49+
"List R6RS (import ...) for each SRFI (SRFI 97 and beyond)."
50+
(for-each write-line (srfi-r6rs-imports)))
51+
1752
(define (srfi-library-names-sxml)
1853
(let ((title "SRFI library names"))
1954
`(html
@@ -31,19 +66,13 @@
3166
(tr (th "")
3267
(th "R6RS")
3368
(th "R7RS"))
34-
,@(filter-map
35-
(lambda (srfi)
36-
(let ((num (srfi-number srfi))
37-
(name (srfi-library-name srfi)))
38-
(and name
39-
`(tr (td (a (@ (href ,(srfi-landing-url num))
40-
(title ,(srfi-title srfi)))
41-
"SRFI " ,(number->string num)))
42-
(td (code ,(format "(import (srfi :~a ~a))"
43-
num name)))
44-
(td (code ,(format "(import (srfi ~a))"
45-
num)))))))
46-
(srfi-list)))))))
69+
,@(srfi-map-library-names
70+
(lambda (num name)
71+
`(tr (td (a (@ (href ,(srfi-landing-url num))
72+
(title ,(srfi-title num)))
73+
"SRFI " ,(number->string num)))
74+
(td (code ,(r6rs-import num name)))
75+
(td (code ,(r7rs-import num name)))))))))))
4776

4877
(define (srfi-generate-library-names)
4978
(let ((file (path-append (srfi-common-dir) "library-names.html"))
@@ -52,5 +81,5 @@
5281
(write-html-file file sxml)))
5382

5483
(define-command (generate-library-names)
55-
"Display the SRFI 97 library names."
84+
"Write web page of library names (SRFI 97 and beyond)."
5685
(srfi-generate-library-names))))

0 commit comments

Comments
 (0)