1;;;; chicken implementation of SRFI 1512(module srfi-151 ()3 (import scheme)4 (cond-expand5 (chicken-56 (import (only (chicken base) include case-lambda when)))7 (chicken-68 (import (only (scheme base) include when)9 (scheme case-lambda))))10 (import (only (chicken module) export))1112 ;; Provides bitwise-not, bitwise-and, butwise-ior, bitwise-xor,13 ;; arithmetic-shift, integer-length. The remaining14 ;; core function, bit-count, is provided in this file.15 (import (chicken bitwise))1617 (export bitwise-not bitwise-and bitwise-ior bitwise-xor bitwise-eqv18 bitwise-nand bitwise-nor bitwise-andc1 bitwise-andc219 bitwise-orc1 bitwise-orc2)20 (export arithmetic-shift bit-count integer-length bitwise-if21 bit-set? copy-bit bit-swap any-bit-set? every-bit-set? first-set-bit)22 (export bit-field bit-field-any? bit-field-every? bit-field-clear bit-field-set23 bit-field-replace bit-field-replace-same24 bit-field-rotate bit-field-reverse)25 (export bits->list list->bits bits->vector vector->bits bits26 bitwise-fold bitwise-for-each bitwise-unfold make-bitwise-generator)2728 (define bit-count29 (letrec ((logcnt (lambda (n tot)30 (if (zero? n)31 tot32 (logcnt (quotient n 16)33 (+ (vector-ref34 '#(0 1 1 2 1 2 2 3 1 2 2 3 2 3 3 4)35 (modulo n 16))36 tot))))))37 (lambda (n)38 (cond ((negative? n) (logcnt (bitwise-not n) 0))39 ((positive? n) (logcnt n 0))40 (else 0)))))4142 (include "srfi-151/bitwise-33.scm")43 (include "srfi-151/bitwise-60.scm")44 (include "srfi-151/bitwise-other.scm")45)