[plt-scheme] boolean operators on integers

From: Richard Cleis (rcleis at mac.com)
Date: Sat Jul 12 21:09:01 EDT 2008

That's slick.  Back when I wanted to do this, I didn't think of  
supplying a base to the number conversions so I ended up abandoning  
the list idea and instead equated numbers to bit patterns.  Resorting  
to such C'ish code was the first thing that came to mind, but it is  
not at all generally usable.

rac


On Jul 12, 2008, at 6:42 PM, Eli Barzilay wrote:

> On Jul 12, Richard Cleis wrote:
>>
>> 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:
>
> Here's a quick hack that works as long as you don't mind the temporary
> junk that is generated:
>
>  (map (lambda (x) (eq? x #\1))
>       (string->list (number->string 1234 2)))
>
>  (string->number (apply string (map (lambda (x) (if x #\1 #\0))
>                                     '(#t #f #f #t #t #f #t #f #f #t  
> #f)))
>
> -- 
>          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli  
> Barzilay:
>                  http://www.barzilay.org/                 Maze is  
> Life!
> _________________________________________________
>  For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme



Posted on the users mailing list.