Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!ucbvax!bloom-beacon!dont-send-mail-to-path-lines From: gyro@cymbal.reasoning.COM (Scott Layson Burson) Newsgroups: comp.lang.scheme Subject: Logical operations on integers. Message-ID: <9104090602.AA06996@cymbal.reasoning.com.> Date: 9 Apr 91 06:02:43 GMT References: Sender: daemon@athena.mit.edu (Mr Background) Reply-To: Gyro@reasoning.com Organization: The Internet Lines: 39 Date: 9 Apr 91 00:18:36 GMT From: david carlton Organization: Citizens for Boysenberry Jam In article bevan@cs.man.ac.uk (Stephen J Bevan) writes: To provide a reasonably portable implementation of Icon like character sets in Scheme I need the equivalent of CommonLisp's logical operations on integers i.e. logand, logior ... etc. Shouldn't logical operations of this sort be included in a standard? Not necessarily in the base language, but perhaps something along the lines of ``if logical operations are provided they should be called X, Y, Z and they should do P, Q, R when applied to integers'' Do these really make sense when operating on bignums? And and or I can buy, at least when operating on non-negative bignums, but not not. Of course, at least one of the standards mentions fixnums - maybe it could encourage implementors to stick them in if the implementation supports fixnums. I think that it would be a bit ugly, though. Of course they make sense on bignums. One way to think about it is that the sign bit of an integer, whether fixnum or bignum, is repeated infinitely to the left. Another way is simply to define (assuming two's complement) (lognot x) = (- -1 x) In one's complement, of course, LOGNOT and unary negation are the same operation. Here's a related puzzle: suppose one were to implement a language which was like C except that it supported infinite-precision integers. (In C, unsigned integers are integers mod 2^n where n is the word length.) What would be the sensible semantics for unsigned integers given that they can be of arbitrary precision? (It turns out that there is a surprisingly reasonable answer.) -- Scott