Marginal bootstrap memory improvements
[bpt/guile.git] / module / rnrs / lists.scm
1 ;;; lists.scm --- The R6RS list utilities library
2
3 ;; Copyright (C) 2010 Free Software Foundation, Inc.
4 ;;
5 ;; This library is free software; you can redistribute it and/or
6 ;; modify it under the terms of the GNU Lesser General Public
7 ;; License as published by the Free Software Foundation; either
8 ;; version 3 of the License, or (at your option) any later version.
9 ;;
10 ;; This library is distributed in the hope that it will be useful,
11 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 ;; Lesser General Public License for more details.
14 ;;
15 ;; You should have received a copy of the GNU Lesser General Public
16 ;; License along with this library; if not, write to the Free Software
17 ;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 \f
19
20 (library (rnrs lists (6))
21 (export find for-all exists filter partition fold-left fold-right remp remove
22 remv remq memp member memv memq assp assoc assv assq cons*)
23 (import (rnrs base (6))
24 (only (guile) filter member memv memq assoc assv assq cons*)
25 (rename (only (srfi srfi-1) any
26 every
27 remove
28 member
29 assoc
30 find
31 partition
32 fold-right
33 filter-map)
34 (any exists)
35 (every for-all)
36 (remove remp)
37
38 (member memp-internal)
39 (assoc assp-internal)))
40
41 (define (fold-left combine nil list . lists)
42 (define (fold nil lists)
43 (if (exists null? lists)
44 nil
45 (fold (apply combine nil (map car lists))
46 (map cdr lists))))
47 (fold nil (cons list lists)))
48
49 (define (remove obj list) (remp (lambda (elt) (equal? obj elt)) list))
50 (define (remv obj list) (remp (lambda (elt) (eqv? obj elt)) list))
51 (define (remq obj list) (remp (lambda (elt) (eq? obj elt)) list))
52
53 (define (memp pred list) (memp-internal #f list (lambda (x y) (pred y))))
54 (define (assp pred list) (assp-internal #f list (lambda (x y) (pred y))))
55 )