lists.scm 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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) fold
  23. any
  24. every
  25. remove
  26. member
  27. assoc
  28. find
  29. partition
  30. fold-right
  31. filter-map)
  32. (fold fold-left)
  33. (any exists)
  34. (every for-all)
  35. (remove remp)
  36. (member memp-internal)
  37. (assoc assp-internal)))
  38. (define (remove obj list) (remp (lambda (elt) (equal? obj elt)) list))
  39. (define (remv obj list) (remp (lambda (elt) (eqv? obj elt)) list))
  40. (define (remq obj list) (remp (lambda (elt) (eq? obj elt)) list))
  41. (define (memp pred list) (memp-internal #f list (lambda (x y) (pred y))))
  42. (define (assp pred list) (assp-internal #f list (lambda (x y) (pred y))))
  43. )