-
Notifications
You must be signed in to change notification settings - Fork 0
/
symbols.rkt
executable file
·60 lines (53 loc) · 1.82 KB
/
symbols.rkt
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
57
58
59
60
#! /usr/bin/env racket
#lang racket
;; raco pkg install css-expr sxml
(require css-expr sxml)
(define (read-all)
(let loop ((forms '()))
(let ((form (read)))
(if (eof-object? form) (reverse forms) (loop (cons form forms))))))
(define (string->file string file)
(call-with-atomic-output-file
file (λ (out . _) (write-string string out))))
(define (assoc1 key alist)
(let ((pair (assoc key alist)))
(cond ((not pair)
(error "Not found:" key alist))
((not (and (list? pair) (= 2 (length pair))))
(error "Bad pair:" key))
(else
(cadr pair)))))
(define (assoc* key alist)
(filter (lambda (pair)
(and (list? pair) (equal? key (car pair))))
alist))
(string->file
(srl:sxml->html
`(html
(head
(title "Lisp")
(style ,(css-expr->css
(css-expr
(html #:background-color white #:font-family sans-serif)
(table #:border-collapse collapse)
(table (td th
#:border (1px solid black)
#:padding 3px))))))
(body
(h1 "Symbols")
,@(append-map
(lambda (form)
(cond ((and (list? form) (equal? 'enumeration (car form)))
`((h2 ,(assoc1 'title (cdr form)))
(table
(tr (th "Symbol")
(th "Title"))
,@(map (lambda (value)
`(tr (td (code
,(symbol->string
(assoc1 'symbol (cdr value)))))
(td ,(assoc1 'title (cdr value)))))
(assoc* 'value (cdr form))))))
(else '())))
(with-input-from-file "symbols.lisp" read-all)))))
"symbols.html")