Quoting Kevin Cozens <[EMAIL PROTECTED]>:
> Giovanni Rizzardi wrote:
>> I'm trying to update an old script (stegano.scm) that uses the functions
>> bit-or and bit-and. Both these function should be
>> ported from SIOD to TinyScheme but the interpreter raises an exception
>> complaining about an "unbound variable".
> Those two functions are unique to SIOD. TinyScheme tends to follow the R4RS
> and R5RS Scheme standards which do not currently define bit wise operations.
> The bitwise operation could be written in standard Scheme but they would be
> rather slow.
> Bit operations were proposed in SRFI-33 (http://srfi.schemers.org/srfi-33/)
> but that is currently in a withdrawn state awaiting revival. You could check
> to see if they have a reference implementation which you could use.
I don't know if they are reference implementations, but the following
two functions should work for reasonably-sized positive integers.
(define (bit-or x y)
((= x y) x)
((zero? x) y)
((zero? y) x)
(+ (* (bit-or (quotient (trunc x) 2) (quotient (trunc y) 2)) 2)
(if (and (even? x) (even? y)) 0 1)))))
(define (bit-and x y)
((= x y) x)
((zero? x) 0)
((zero? y) 0)
(+ (* (bit-and (quotient (trunc x) 2) (quotient (trunc y) 2)) 2)
(if (or (even? x) (even? y)) 0 1)))))
Gimp-developer mailing list