Re: script-fu error.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Quoting Kevin Cozens <kevin@xxxxxxxxx>:

> 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)
   (cond
     ((= x y) x)
     ((zero? x) y)
     ((zero? y) x)
   (else
     (+ (* (bit-or (quotient (trunc x) 2) (quotient (trunc y) 2)) 2)
        (if (and (even? x) (even? y)) 0 1)))))

(define (bit-and x y)
   (cond
     ((= x y) x)
     ((zero? x) 0)
     ((zero? y) 0)
   (else
     (+ (* (bit-and (quotient (trunc x) 2) (quotient (trunc y) 2)) 2)
        (if (or (even? x) (even? y)) 0 1)))))


_______________________________________________
Gimp-developer mailing list
Gimp-developer@xxxxxxxxxxxxxxxxxxxxxx
https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer

[Index of Archives]     [Video For Linux]     [Photo]     [Yosemite News]     [gtk]     [GIMP for Windows]     [KDE]     [GEGL]     [Gimp's Home]     [Gimp on GUI]     [Gimp on Windows]     [Steve's Art]

  Powered by Linux