srfi-151.sld 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. ;; Copyright (C) John Cowan (2016). All Rights Reserved.
  2. ;; Permission is hereby granted, free of charge, to any person obtaining
  3. ;; a copy of this software and associated documentation files (the
  4. ;; "Software"), to deal in the Software without restriction, including
  5. ;; without limitation the rights to use, copy, modify, merge, publish,
  6. ;; distribute, sublicense, and/or sell copies of the Software, and to
  7. ;; permit persons to whom the Software is furnished to do so, subject to
  8. ;; the following conditions:
  9. ;; The above copyright notice and this permission notice shall be
  10. ;; included in all copies or substantial portions of the Software.
  11. ;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  12. ;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  13. ;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  14. ;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  15. ;; BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  16. ;; ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  17. ;; CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  18. ;; SOFTWARE.
  19. (define-library (srfi srfi-151)
  20. (import (scheme base))
  21. (import (scheme case-lambda))
  22. (export bitwise-not bitwise-and bitwise-ior bitwise-xor bitwise-eqv
  23. bitwise-nand bitwise-nor bitwise-andc1 bitwise-andc2
  24. bitwise-orc1 bitwise-orc2)
  25. (export arithmetic-shift bit-count integer-length bitwise-if
  26. bit-set? copy-bit bit-swap any-bit-set? every-bit-set? first-set-bit)
  27. (export bit-field bit-field-any? bit-field-every? bit-field-clear bit-field-set
  28. bit-field-replace bit-field-replace-same
  29. bit-field-rotate bit-field-reverse)
  30. (export bits->list list->bits bits->vector vector->bits bits
  31. bitwise-fold bitwise-for-each bitwise-unfold make-bitwise-generator)
  32. ;; Provide core functions
  33. (import (only (rnrs arithmetic bitwise)
  34. bitwise-not bitwise-and bitwise-ior bitwise-xor
  35. bitwise-bit-count))
  36. (import (rename (only (rnrs arithmetic bitwise)
  37. bitwise-arithmetic-shift bitwise-length)
  38. (bitwise-arithmetic-shift arithmetic-shift)
  39. (bitwise-length integer-length)))
  40. (begin
  41. (define (bit-count i) ; Negative case different to R6RS bitwise-bit-count
  42. (if (>= i 0)
  43. (bitwise-bit-count i)
  44. (bitwise-bit-count (bitwise-not i)))))
  45. ;; Stable part of the implementation
  46. (include "srfi-151/bitwise-33.scm")
  47. (include "srfi-151/bitwise-60.scm")
  48. (include "srfi-151/bitwise-other.scm"))