Next: A Scheme API for test suites, Previous: Requiring extensions, Up: Library modules - SRFIs [Contents][Index]
srfi-60 - Integers as bitsThis srfi provides bit operations on integers, regarding them
as 2’s complement representation. It is compatible to SLIB’s logical
module.
The newer srfi-151 (see R7RS bitwise operations) provides the same functionality and more, with more consistent naming. We recommend new code to use srfi-151, while we keep srfi-60 for the backward compatibility.
The following procedures are Gauche built-in. See Basic bitwise operations, for the description.
lognot logand logior logxor logtest logcount integer-length logbit? copy-bit bit-field copy-bit-field ash
The following procedures are defined in srfi-151. See R7RS bitwise operations, for the description.
bitwise-not bitwise-and bitwise-ior bitwise-xor arithmetic-shift bit-count bitwise-if bit-set? copy-bit first-set-bit
We describe procedures that are unique in srfi-60 below.
[SRFI-60]
{srfi-60}
Same as bitwise-if (see R7RS bitwise operations).
[SRFI-60]
{srfi-60}
Same as builtin logtest (see Basic bitwise operations).
It is also called any-bit-set? in srfi-151 (see R7RS bitwise operations).
[SRFI-60]
{srfi-60}
It is also called as first-set-bit in this srfi, which is also
in srfi-151 (see R7RS bitwise operations).
This is equivalent to Gauche’s built-in twos-exponent-factor
(see Basic bitwise operations).
[SRFI-60]
{srfi-60}
This is equivalent to bit-field-rotate in srfi-151
(see R7RS bitwise operations).
[SRFI-60]
{srfi-60}
This is equivalent to bit-field-reverse in srfi-151
(see R7RS bitwise operations).
[SRFI-60]
{srfi-60}
Breaks n to each bits, representing 1 as #t and
0 as #f, LSB last, and returns a list of them.
If a nonnegative integer len is given, it specifies the length
of the result. If it is omitted, (integer-length n) is used.
(integer->list 10) ⇒ (#t #f #t #f) (integer->list 10 6) ⇒ (#f #f #t #f #t #f)
Srfi-151 has similar procedure bits->list, with a reversed bit
order (LSB first) (see R7RS bitwise operations).
[SRFI-60]
{srfi-60}
Takes a list of boolean values, replaces the true value for 1
and the false value for 0, and compose an integer regarding
each value as a binary digit. If n is nonnegative integer,
(eqv? (list->integer (integer->list n)) n) is true.
(list->integer '(#f #t #f #t #f)) ⇒ 10
Srfi-151 has similar procedure list->bits, with a reversed bit
order (LSB first) (see R7RS bitwise operations).
[SRFI-60]
{srfi-60}
≡ (list->integer (list bool …))
Srfi-151 has similar procedure bits, with a reversed bit
order (LSB first) (see R7RS bitwise operations).
Next: A Scheme API for test suites, Previous: Requiring extensions, Up: Library modules - SRFIs [Contents][Index]