[plt-scheme] boolean operators on integers

From: Richard Cleis (rcleis at mac.com)
Date: Sat Jul 12 12:13:51 EDT 2008

On Jul 12, 2008, at 8:44 AM, Robby Findler wrote:

> On Sat, Jul 12, 2008 at 9:02 AM, Matthias Felleisen
> <matthias at ccs.neu.edu> wrote:
>> In centuries past, around
>> 1738, people thought that 0 stood for #f and that 1 stood for #t.  
>> But this
>> pun hasn't been useful to real programmer since then so I don't  
>> know where
>> one would fine this idea, except in history books.)
>
> Not to be too too contrarian, but the idea is actually being used all
> the time. It really starts with two voltages that we can interpret as
> booleans to implement boolean logical formulas and then, whaddayaknow,
> you can implement arithmetic using boolean formulas by treating the
> binary digits of a number as truth values....
>
> But of course, this is only something you think of when you peel back
> a layer of abstraction.
>
> THAT is the real sin, here. :)
>
> Robby

I occasionally have the need for functions that I never wrote.  They  
would work like string->list, but would instead convert bits of a  
hardware derived number to a list of booleans (rather than characters  
in a string to a list of characters.)  That way, a handler could  
cleanly be applied to the list of boolean values:

(apply handle-fridge-status (bits->list status-bits-from-fridge))

(define  (handle-fridge-status  pump-on cooler-on ...)
   (cond  ((pump-on ...)
           (cooler-on ...)
           (... ...))))

An equally useful function for abstraction would be list->bits (to  
turn the pump and/or cooler on or off, for example)

This is boring practical stuff, though; it's not as fun as using  
exponentiation for implementing logical negation. :)

rac

>
> _________________________________________________
>  For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme



Posted on the users mailing list.