bit-vector-operations.scm 857 B

123456789101112131415161718192021222324252627282930
  1. (define-module (bit-vector-operations)
  2. #:export
  3. (binary-bit-vector-operation
  4. string->bit-vector))
  5. (define (binary-bit-vector-operation bv1 bv2 proc)
  6. (define (iter bit-list1 bit-list2)
  7. (cond [(or (null? bit-list1) (null? bit-list2)) '()]
  8. [else (cons (proc (car bit-list1)
  9. (car bit-list2))
  10. (iter (cdr bit-list1)
  11. (cdr bit-list2)))]))
  12. (list->bitvector
  13. (iter (bitvector->list bv1)
  14. (bitvector->list bv2))))
  15. (define (string->bit-vector str)
  16. (list->bitvector
  17. (map (λ (char)
  18. (cond
  19. [(char=? char #\0) #f]
  20. [(char=? char #\1) #t]
  21. [else
  22. (throw 'value-error
  23. "trying to convert the following character to boolean:"
  24. char)]))
  25. (string->list str))))