() steve tell <[email protected]>
() Wed, 9 Jun 2010 00:04:41 -0400 (EDT)

   But is there any way to copy the contents of bitvector a to another
   bitvector b of the same size, short of iterating over the elements?

You can use ‘bit-set*!’, something like:

(define (copy-bit-vector orig)
  (let ((copy (make-uniform-vector (uniform-vector-length orig) #t)))
    (bit-invert! copy)
    (bit-set*! copy orig #t)
    copy))

(write-line (copy-bit-vector #*111111111111111))
#*111111111111111

This uses Guile 1.4.x-isms for constructing the bit vector; YMMV.
Here is a more elegant variant that does not work under Guile 1.4.1.118,
even though it should (a bug):

(define (copy-bit-vector orig)
  (let ((copy (make-uniform-vector (uniform-vector-length orig) #t)))
    (bit-set*! copy orig #f)
    copy))

The first variant creates all-1s, "manually" inverts, then does a logical OR.
The second creates all-1s, then does a logical AND-NOT.

BTW, to answer the previous question (re shift), you can avoid shifting by
specifying a non-bitvec uniform vector as the second arg to ‘bit-set*!’.

thi

Reply via email to