1 ;;;; hash-table.scm --- Additional hash table procedures
2 ;;;; Copyright (C) 2013 Free Software Foundation, Inc.
4 ;;;; This library is free software; you can redistribute it and/or
5 ;;;; modify it under the terms of the GNU Lesser General Public
6 ;;;; License as published by the Free Software Foundation; either
7 ;;;; version 3 of the License, or (at your option) any later version.
9 ;;;; This library is distributed in the hope that it will be useful,
10 ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 ;;;; Lesser General Public License for more details.
14 ;;;; You should have received a copy of the GNU Lesser General Public
15 ;;;; License along with this library; if not, write to the Free Software
16 ;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 (define-module (ice-9 hash-table)
20 #:export (alist->hash-table
25 (define-syntax-rule (define-alist-converter name hash-set-proc)
27 "Convert ALIST into a hash table."
28 (let ((table (make-hash-table)))
29 (for-each (lambda (pair)
30 (hash-set-proc table (car pair) (cdr pair)))
34 (define-alist-converter alist->hash-table hash-set!)
35 (define-alist-converter alist->hashq-table hashq-set!)
36 (define-alist-converter alist->hashv-table hashv-set!)
38 (define (alist->hashx-table hash assoc alist)
39 "Convert ALIST into a hash table with custom HASH and ASSOC
41 (let ((table (make-hash-table)))
42 (for-each (lambda (pair)
43 (hashx-set! hash assoc table (car pair) (cdr pair)))