Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!elroy.jpl.nasa.gov!decwrl!argosy!freeman From: freeman@argosy.UUCP (Jay R. Freeman) Newsgroups: comp.lang.scheme Subject: Re: Logical operations on integers. Message-ID: <1212@argosy.UUCP> Date: 6 Apr 91 19:46:52 GMT References: Sender: news@argosy.UUCP Reply-To: freeman@cleo.UUCP (Jay R. Freeman) Distribution: comp Organization: MasPar Computer Corporation, Sunnyvale, CA Lines: 82 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. [...] > I'd like to use the same name as any existing >extensions. So, if these sorts of operations are in some Scheme >implementations (e.g. T, CScheme, Chez, Mac ... etc.), what are they >called? Pixie Scheme (shareware for the Macintosh) has these; I call them e::bit-and e::bit-not e::bit-or e::bit-shift-left e::bit-shift-right-arithmetic ; sign-extends e::bit-shift-right-logical ; shifts in zeros e::bit-xor The "e::" business is *not* part of a package system, it is just my convention for how I name extensions. I selected the "bit-" prefix rather than Common Lisp's "logic..." prefix, because strictly, the existing operations "and" and "or" *are* logic operations, hence the Common Lisp names might confuse someone. Each operation takes arguments that are integers, and requires that they be small enough to fit into the machine representation for a fixnum (garden-variety 32-bit). The operation returns a new fixnum obtained by performing the indicated bit operation. For the shifts, the number to be shifted is the first argument, and the number of bits by which to shift is the second. "E::bit-and", "e::bit-or" and possibly "e::bit-xor" might reasonably be defined to take more than two arguments; I happened to set them up to take exactly two. (There are different definitions of what the "xor" of three or more arguments ought to be, hence the qualifier.) I put these in mostly for my own use in developing a compiler: Pixie Scheme is a tagged-object Lisp, and built-in bitwise operations are invaluable for dealing quickly with tags. There are lots of other extensions that I found useful to implement. Many of them are system-dependent, and cannot be part of the standard simply because their existence and utility depends on what computer and what operating system the implementation runs on. Some of more general value might be: e::bound-instance? ; Takes a symbol, answers whether it has a ; value in any environment in scope. e::closed-port? ; Takes a port, answers whether it is closed. e::cons-with-continuation ; One flavor of "eval". e::exit ; Back to the operating system. e::full-gc ; Force a complete garbage collection. e::inf? ; Is the object an IEEE infinity? e::nan? ; Is the object an IEEE not-a-number? e::promise? ; Is the object a promise? e::reset ; Abort calculation, restart top-level loop. Other useful classes of operations might be ones to deal with the existence and non-existence of files, location and motion within the directory hierarchy, amount of main store used and remaining (before a garbage collection), storage class of certain objects (typically numbers), obtaining and changing the maximum length and depth to print lists and vectors, saving and restoring "worlds", inspecting and altering low-level data structures not normally seen by the user (this last for the curious, the demented, and the developer), and perhaps creating and using macros. Another handy class of entity -- not quite an operation -- is top-level loop variables, like Common Lisp's, which contain recent values of forms evaluated and values returned, for use by the hapless user who forgot to bind the value of an hour-long calculation to some place from which it could be recovered. Pixie Scheme has facilities for all of these, but I have no great claim to wisdom in the names I have chosen. -- Jay Freeman