lists.scm 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. ;;; lists.scm --- The R6RS list utilities library
  2. ;; Copyright (C) 2010 Free Software Foundation, Inc.
  3. ;;
  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.
  8. ;;
  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.
  13. ;;
  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
  17. (library (rnrs lists (6))
  18. (export find for-all exists filter partition fold-left fold-right remp remove
  19. remv remq memp member memv memq assp assoc assv assq cons*)
  20. (import (rnrs base (6))
  21. (only (guile) filter member memv memq assoc assv assq cons*)
  22. (rename (only (srfi srfi-1) any
  23. every
  24. remove
  25. member
  26. assoc
  27. find
  28. partition
  29. fold-right
  30. filter-map)
  31. (any exists)
  32. (every for-all)
  33. (remove remp)
  34. (member memp-internal)
  35. (assoc assp-internal)))
  36. (define (fold-left combine nil list . lists)
  37. (define (fold nil lists)
  38. (if (exists null? lists)
  39. nil
  40. (fold (apply combine nil (map car lists))
  41. (map cdr lists))))
  42. (fold nil (cons list lists)))
  43. (define (remove obj list) (remp (lambda (elt) (equal? obj elt)) list))
  44. (define (remv obj list) (remp (lambda (elt) (eqv? obj elt)) list))
  45. (define (remq obj list) (remp (lambda (elt) (eq? obj elt)) list))
  46. (define (memp pred list) (memp-internal #f list (lambda (x y) (pred y))))
  47. (define (assp pred list) (assp-internal #f list (lambda (x y) (pred y))))
  48. )