Debian Codegraph @

%3a146/gleckler/hamt-misc.sls

raw
1 ;;;; Utilities used by HAMT
2
3 ;;; Copyright MMIV-MMXVII Arthur A. Gleckler. All rights reserved.
4
5 ;; Permission is hereby granted, free of charge, to any person
6 ;; obtaining a copy of this software and associated documentation
7 ;; files (the "Software"), to deal in the Software without
8 ;; restriction, including without limitation the rights to use, copy,
9 ;; modify, merge, publish, distribute, sublicense, and/or sell copies
10 ;; of the Software, and to permit persons to whom the Software is
11 ;; furnished to do so, subject to the following conditions:
12
13 ;; The above copyright notice and this permission notice shall be
14 ;; included in all copies or substantial portions of the Software.
15
16 ;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 ;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 ;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 ;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 ;; HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 ;; WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 ;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 ;; DEALINGS IN THE SOFTWARE.
24 (library (srfi :146 gleckler hamt-misc)
25 (export assert do-list
26 make-string-hash-table
27 with-output-to-string)
28 (import (except (rnrs) string-hash assert)
29 (srfi :6)
30 (srfi :39)
31 (only (srfi :43) vector-copy!)
32 (only (srfi :69) string-hash)
33 (only (srfi :125) make-hash-table)
34 (only (srfi :128) make-comparator))
35
36 (define-syntax assert
37 (syntax-rules ()
38 ((_ (operator argument ...))
39 (unless (operator argument ...)
40 (error "Assertion failed:"
41 '(operator argument ...)
42 (list 'operator argument ...))))
43 ((_ expression)
44 (unless expression
45 (error "Assertion failed:" 'expression)))))
46
47 (define-syntax do-list
48 (syntax-rules ()
49 ((_ (variable list) body ...)
50 (do ((remaining list (cdr remaining)))
51 ((null? remaining))
52 (let ((variable (car remaining)))
53 body ...)))
54 ((_ (element-variable index-variable list) body ...)
55 (do ((remaining list (cdr remaining))
56 (index-variable 0 (+ index-variable 1)))
57 ((null? remaining))
58 (let ((element-variable (car remaining)))
59 body ...)))))
60
61 (define string-comparator
62 (make-comparator string? string=? #f string-hash))
63
64 (define (make-string-hash-table)
65 (make-hash-table string-comparator))
66
67 (define (with-output-to-string thunk)
68 (parameterize ((current-output-port (open-output-string)))
69 (thunk)
70 (get-output-string (current-output-port)))))