(define-module (bit-vector-operations)
  #:export
  (binary-bit-vector-operation
   string->bit-vector))


(define (binary-bit-vector-operation bv1 bv2 proc)
  (define (iter bit-list1 bit-list2)
    (cond [(or (null? bit-list1) (null? bit-list2)) '()]
          [else (cons (proc (car bit-list1)
                            (car bit-list2))
                      (iter (cdr bit-list1)
                            (cdr bit-list2)))]))
  (list->bitvector
   (iter (bitvector->list bv1)
         (bitvector->list bv2))))


(define (string->bit-vector str)
  (list->bitvector
   (map (λ (char)
          (cond
           [(char=? char #\0) #f]
           [(char=? char #\1) #t]
           [else
            (throw 'value-error
                   "trying to convert the following character to boolean:"
                   char)]))
        (string->list str))))
