guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: logical shift operators in guile?


From: Thien-Thi Nguyen
Subject: Re: logical shift operators in guile?
Date: Thu, 10 Jun 2010 14:32:15 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.91 (gnu/linux)

() steve tell <address@hidden>
() 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

[Prev in Thread] Current Thread [Next in Thread]