Newsgroups: comp.lang.scheme
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!news2.near.net!news.mathworks.com!udel!gatech!howland.reston.ans.net!ix.netcom.com!netcom.com!hbaker
From: hbaker@netcom.com (Henry G. Baker)
Subject: Re: bit manipulation operators in scheme?
Message-ID: <hbakerCz8Lsp.9zs@netcom.com>
Organization: nil
References: <3a0s1q$ej1@tweedledumb.cygnus.com> <JAFFER.94Nov13123109@jacal.zurich.ai.mit.edu>
Date: Mon, 14 Nov 1994 03:02:49 GMT
Lines: 43

In article <JAFFER.94Nov13123109@jacal.zurich.ai.mit.edu> jaffer@zurich.ai.mit.edu (Aubrey Jaffer) writes:
>In article <3a0s1q$ej1@tweedledumb.cygnus.com> eichin@cygnus.com (Mark Eichin) writes:
>
>   I noticed that the FAQ and the R4RS don't mention bit manipulation
>   operators at all. Are there common extensions to do this, or do people
>   just not do that in scheme?
>
>   One could certainly use vectors of #t/#f, or even vectors of natural
>   numbers, unless one wanted space efficiency. There's also conversion
>   issue -- turning an integer into such a vector is going to cost a
>   division (hmm, or at least a subtraction) per bit. 

Ada uses vectors of boolean true/false as its only bitvectors.

>There are 2 types of "bit manipulation" in Common Lisp.  One is
>"Logical Operations on Number" and the other is bit vectors.  

Actually, there are _three_ different styles of bitvectors in Common
Lisp (when you can't decide among different features, include them
all!  -- i.e., 'how CL got so big').  There are logical operations on
bignums, logical operations on bit _arrays_, and the various sequence
operations on vectors of (integer 0 1) = BIT's.  Only the logical
operations on bignums are pure & functional, while the other metaphors
allow (read 'encourage') side-effects.  As is usual in Common Lisp,
there is no really organized way of converting from one kind of bit
vector into another, and no guarantee that _portable_ conversions are
efficient enough to actually use in an application.

My paper 'Efficient Implementation of Bit-vector Operations in Common
Lisp" discusses these issues, and ways to achieve efficiency.  This paper
is available in my ftp directory.

Bit-vectors are good for efficiently implementing sets and masks.  See
the papers 'The Nimble Type Inferencer', 'A Decision Procedure for
Common Lisp's SUBTYPEP Predicate', 'Speeding up the Puzzle Benchmark a
Bit', 'The Gabriel Triangle Benchmark at Warp Speed', all in my ftp
directory.  Bit-vectors are also used extensively in Pratt's 'Lingol'
parsing system.

      Henry Baker
      Read ftp.netcom.com:/pub/hbaker/README for info on ftp-able papers.
      Contact hoodr@netcom.com if you have trouble ftping

