srfi-238-string/codesets.sld

35 lines
1.1 KiB
Scheme

(define-library (codesets)
(export codeset-alist)
(cond-expand
(chibi
(import (scheme base))
(include-shared "codesets.chibi"))
(gambit
(import (gambit))
(include "codesets.gambit.scm")))
(begin
(define (split string)
(let loop ((list '()) (a 0) (b 0))
(cond ((= a (string-length string))
(reverse list))
((char=? #\newline (string-ref string b))
(loop (cons (string-copy string a b) list)
(+ b 1)
(+ b 1)))
(else
(loop list a (+ b 1))))))
(define (grovel-codeset codeset)
(define (append-map f a b c) (apply append (map f a b c)))
(cons (string->symbol codeset)
(list->vector
(append-map
list
(map string->number (split (%codeset-numbers codeset)))
(map string->symbol (split (%codeset-symbols codeset)))
(split (%codeset-messages codeset))))))
(define codeset-alist
(map grovel-codeset (split (%codeset-list))))))