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

*To*: Pavel@parc.xerox.com*Subject*: R5RS Proposal proposal (bitvectors)*From*: "Aubrey Jaffer" <jaffer@martigny.ai.mit.edu>*Date*: Wed, 27 May 92 13:04:07 -0400*Cc*: ziggy@martigny.ai.mit.edu, rrrs-authors@ai.mit.edu*In-Reply-To*: Pavel Curtis's message of Tue, 26 May 1992 14:34:33 PDT <92May26.143443pdt.58371@lambda.parc.xerox.com>

From: Pavel Curtis <Pavel@parc.xerox.com> Date: Tue, 26 May 1992 14:34:33 PDT Date: Tue, 26 May 1992 14:13:57 -0700 From: "Michael R. Blair" <ziggy@martigny.ai.mit.edu> I just want to be able to have bitvectors and bitwise logical AND and OR and NOT and so on. This is partly because I simulate digital chips and partly because I am envious of other languages that claim high efficiency algorithms by using bitvectors to scoreboard things like set operations (union/intersection/etc as OR/AND etc). I would prefer not adding a new data-type but rather just specifying the various bitwise operations on (exact) integers in much the same way Common Lisp does, with integers treated as if they were half-infinite two's complement bit sequences. I'd like to see LOGAND, LOGIOR, LOGXOR, and LOGNOT, with the first three being binary operators (or perhaps n-ary) and the last being unary, all mapping exact integers to exact integers. Common Lisp provides both these operations on integers and logical operations on (mutable) bit-vectors. I find the integer variety to be much simpler to understand (mainly due to their immutability, I think), but I can see the usefulness, in certain contexts, of a mutable variety too. I guess what I'm saying is that I certainly want the integer ops and wouldn't squawk too loudly if bit-vectors were added too. SLIB has most of the Common Lisp logical operations implemented in portable Scheme code. I find them very useful. They are used for modular arithmatic computations and random number generation in SLIB. I am including the documentation for logical.scm at the end of this message. Bitvectors could be implemented in portable scheme code using vectors or strings for the actual storage. SLIB would certainly welcome such code. ---------------------------------------------------------------------- (logand n1 n2) procedure Returns the integer which is the bit-wise AND of the two integer arguments. (logor n1 n2) procedure Returns the integer which is the bit-wise OR of the two integer arguments. (logxor n1 n2) procedure Returns the integer which is the bit-wise XOR of the two integer arguments. (lognot n) procedure Returns the integer which is the 2s-complement of the integer argument. (ash int count) procedure Returns an integer equivalent to (inexact->exact (floor (* int (expt 2 count)))) (logcount n) procedure Returns the number of bits in integer n. If integer is positive, the 1-bits in its binary representation are counted. If negative, the 0-bits in its two's-complement binary representation are counted. If 0, 0 is returned. (integer-length n) procedure Returns the number of bits neccessary to represent n. (integer-expt n k) procedure Returns n raised to the non-negative integer exponent k. (bit-extract n <start> <end>) procedure Returns the integer composed of the <start> (inclusive) through <end> (exclusive) bits of n. The <start>th bit becomes the 0-th bit in the result. Common Lispers will notice that I have not supported the multiple (more than 2) argument forms of logand, logor, and logxor. I don't care if you include them.

**References**:**Re: R5RS Proposal proposal (bitvectors)***From:*Pavel Curtis <Pavel@parc.xerox.com>

- Prev by Date:
**Re: ports as real types...** - Next by Date:
**Re: A few random I/O proposals** - Prev by thread:
**Re: R5RS Proposal proposal (bitvectors)** - Next by thread:
**rationale** - Index(es):