* SRFI-60
@ 2014-02-18 6:53 Jamison Hope
2014-02-18 7:12 ` SRFI-60 Per Bothner
0 siblings, 1 reply; 10+ messages in thread
From: Jamison Hope @ 2014-02-18 6:53 UTC (permalink / raw)
To: kawa@sourceware.org list
[-- Attachment #1: Type: text/plain, Size: 1166 bytes --]
I saw that SRFI-60 was almost there, so I went ahead and implemented the rest of it. The functions all fall into one of these categories:
1. already provided as a builtin with the same name, so nothing to do
2. already provided as a builtin with a different name, so just add an alias
3. functionality is provided by a similar-name builtin but arguments are reordered or signature otherwise changes slightly, so define a wrapper function and then call the builtin
3.a. name/signature conflicts with a builtin (this happens exactly once, with logbit?)
4. new function, so implement it
Since there are argument order differences compared to existing numbers.scm procedures, I figure this one should probably require an explicit require/import, so it can go in the gnu.kawa.slib package next to srfi1.scm. Even so, I wonder whether it might be a good idea to remove the builtin logbit? (which is just an alias for bitwise-set-bit? anyway).
I can make the require.java/ImportFromLibrary.java changes, but since this is a new file I wanted to see if I was on the right track first.
--
Jamison Hope
The PTR Group
www.theptrgroup.com
[-- Attachment #2: srfi60.scm --]
[-- Type: application/octet-stream, Size: 3210 bytes --]
;; SRFI-60 implementation for Kawa (almost everything is already built
;; in, but some of the names differ slightly).
;; Copyright (C) 2014 by Jamison Hope. The implementations of
;; integer->list, list->integer, and booleans->integer were taken with
;; slight modifications from the reference implementation of SRFI-60,
;; which is copyright (C) 1991, 1993, 2001, 2003, 2005 Aubrey Jaffer
;
;Permission to copy this software, to modify it, to redistribute it,
;to distribute modified versions, and to use it for any purpose is
;granted, subject to the following restrictions and understandings.
;
;1. Any copy made of this software must include this copyright notice
;in full.
;
;2. I have made no warranty or representation that the operation of
;this software will be error-free, and I am under no obligation to
;provide any services, by way of maintenance, update, or otherwise.
;
;3. In conjunction with products arising from the use of this
;material, there shall be no use of my name in any advertising,
;promotional, or sales literature without prior written consent in
;each case.
(module-compile-options warn-unknown-member: #t)
;;; These procedures are already Kawa built-ins and do not need to be
;;; defined here: logand/bitwise-and, logior/bitwise-ior,
;;; logxor/bitwise-xor, lognot/bitwise-not, bitwise-if, logtest,
;;; logcount, integer-length, and ash/arithmetic-shift.
;;; These procedures alias functionality provided by built-ins with
;;; differing names:
(define bitwise-merge bitwise-if)
(define any-bits-set? logtest)
(define bit-count logcount)
(define log2-binary-factors bitwise-first-bit-set)
(define first-set-bit bitwise-first-bit-set)
(define bit-field bitwise-bit-field)
(define reverse-bit-field bitwise-reverse-bit-field)
;;; These procedures are similar to built-ins but with arguments
;;; reordered:
;; Note that this shadows the built-in logbit? procedure, which is an
;; alias for bitwise-bit-set?.
(define (logbit? index::int n::integer) ::boolean
(bitwise-bit-set? n index))
(define bit-set? logbit?)
(define (copy-bit-field to::integer from::integer start::int end::int)
::integer
(bitwise-copy-bit-field to start end from))
(define (rotate-bit-field n::integer count::int start::int end::int)
::integer
(bitwise-rotate-bit-field n start end count))
;;; This procedure has a slightly different signature compared to the
;;; built-in bitwise-copy-bit: the first two arguments are swapped and
;;; the last is a boolean instead of an int
(define (copy-bit index::int from::integer bit::boolean)
::integer
(bitwise-copy-bit from index (if bit 1 0)))
;;; These procedures are entirely new, with implementations derived
;;; from the SRFI-60 reference.
(define (integer->list k::integer #!optional (len ::int (integer-length k)))
::list
(do ((idx ::int (- len 1) (- idx 1))
(k ::integer k (ash k -1))
(lst ::list '() (cons (odd? k) lst)))
((< idx 0) lst)))
(define (list->integer bools::list) ::integer
(do ((bs bools (cdr bs))
(acc ::integer 0 (if (car bs) (+ acc acc 1) (+ acc acc))))
((null? bs) acc)))
(define (booleans->integer . bools)
(list->integer bools))
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: SRFI-60
2014-02-18 6:53 SRFI-60 Jamison Hope
@ 2014-02-18 7:12 ` Per Bothner
2014-02-18 16:30 ` SRFI-60 Jamison Hope
0 siblings, 1 reply; 10+ messages in thread
From: Per Bothner @ 2014-02-18 7:12 UTC (permalink / raw)
To: Jamison Hope, kawa@sourceware.org list
On 02/17/2014 10:53 PM, Jamison Hope wrote:
> I saw that SRFI-60 was almost there, so I went ahead and implemented the rest of it.
Thanks!
> Since there are argument order differences compared to existing numbers.scm procedures, I figure this one should probably require an explicit require/import, so it can go in the gnu.kawa.slib package next to srfi1.scm. Even so, I wonder whether it might be a good idea to remove the builtin logbit? (which is just an alias for bitwise-set-bit? anyway).
Yes, I think we should remove the old builtin logbit? I notice Common
Lisp's
logbitp uses the (logbitp index integer) order. I suspect the (logbit?
integer index)
order is just a bug - it doesn't match any other Scheme I've found.
--
--Per Bothner
per@bothner.com http://per.bothner.com/
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: SRFI-60
2014-02-18 7:12 ` SRFI-60 Per Bothner
@ 2014-02-18 16:30 ` Jamison Hope
2014-02-20 7:54 ` SRFI-60 Per Bothner
0 siblings, 1 reply; 10+ messages in thread
From: Jamison Hope @ 2014-02-18 16:30 UTC (permalink / raw)
To: kawa@sourceware.org list
[-- Attachment #1.1: Type: text/plain, Size: 1397 bytes --]
On Feb 18, 2014, at 2:11 AM, Per Bothner <per@bothner.com> wrote:
> On 02/17/2014 10:53 PM, Jamison Hope wrote:
>> I saw that SRFI-60 was almost there, so I went ahead and implemented the rest of it.
>
> Thanks!
As low hanging fruit go, this one was resting on the ground. :-)
>> Since there are argument order differences compared to existing numbers.scm procedures, I figure this one should probably require an explicit require/import, so it can go in the gnu.kawa.slib package next to srfi1.scm. Even so, I wonder whether it might be a good idea to remove the builtin logbit? (which is just an alias for bitwise-set-bit? anyway).
>
> Yes, I think we should remove the old builtin logbit? I notice Common Lisp's
> logbitp uses the (logbitp index integer) order. I suspect the (logbit? integer index)
> order is just a bug - it doesn't match any other Scheme I've found.
OK. That probably still argues for keeping the SRFI-60 version out of the builtins -- if anybody is using the old function by that name and not 'bitwise-bit-set?', it'll be better for them to see a compiler error than to have the semantics altered silently (I wouldn't want to be the one to track down that bug!).
Here's a patch which adds SRFI-60, updates require.java and ImportFromLibrary.java, and removes logbit? from Scheme.java.
--
Jamison Hope
The PTR Group
www.theptrgroup.com
[-- Attachment #1.2: srfi60.patch --]
[-- Type: application/octet-stream, Size: 7924 bytes --]
Index: ChangeLog
===================================================================
--- ChangeLog (revision 7818)
+++ ChangeLog (working copy)
@@ -1,3 +1,7 @@
+2014-02-18 Jamison Hope <jrh@theptrgroup.com>
+
+ * build.xml (slib-scm-classes): Add srfi60.scm.
+
2014-02-06 Per Bothner <per@bothner.com>
* build.xml (commonlisp-scm-classes): Make sure to compile
Index: build.xml
===================================================================
--- build.xml (revision 7818)
+++ build.xml (working copy)
@@ -586,6 +586,7 @@
<file name="srfi14.scm"/>
<file name="srfi34.scm"/>
<file name="srfi37.scm"/>
+ <file name="srfi60.scm"/>
<file name="srfi69.scm"/>
<file name="pregexp.scm"/>
<file name="Streams.scm"/>
Index: gnu/kawa/slib/ChangeLog
===================================================================
--- gnu/kawa/slib/ChangeLog (revision 7818)
+++ gnu/kawa/slib/ChangeLog (working copy)
@@ -1,3 +1,8 @@
+2014-02-18 Jamison Hope <jrh@theptrgroup.com>
+
+ * srfi60.scm: New implementation of SRFI-60.
+ * Makefile.am: Update accordingly.
+
2014-02-06 Seth Alves
* srfi13.scm (string-trim-right): Import bug-fix from reference
Index: gnu/kawa/slib/Makefile.am
===================================================================
--- gnu/kawa/slib/Makefile.am (revision 7818)
+++ gnu/kawa/slib/Makefile.am (working copy)
@@ -21,7 +21,7 @@
java_SCM = DefineRecordType.scm enums.scm readtable.scm \
srfi1.scm srfi2.scm \
conditions.scm srfi13.scm srfi14.scm srfi34.scm \
- srfi37.scm srfi69.scm pregexp.scm \
+ srfi37.scm srfi60.scm srfi69.scm pregexp.scm \
Streams.scm StreamsDerived.scm StreamsPrimitive.scm StreamsType.scm \
genwrite.scm pp.scm ppfile.scm printf.scm ralists.scm syntaxutils.scm \
cut.scm testing.scm $(XML_SCM) $(AWT_SCM) $(SWING_SCM)
Index: gnu/kawa/slib/srfi60.scm
===================================================================
--- gnu/kawa/slib/srfi60.scm (revision 0)
+++ gnu/kawa/slib/srfi60.scm (working copy)
@@ -0,0 +1,81 @@
+;; SRFI-60 implementation for Kawa (almost everything is already built
+;; in, but some of the names differ slightly).
+;; Copyright (C) 2014 by Jamison Hope. The implementations of
+;; integer->list, list->integer, and booleans->integer were taken with
+;; slight modifications from the reference implementation of SRFI-60,
+;; which is copyright (C) 1991, 1993, 2001, 2003, 2005 Aubrey Jaffer
+;
+;Permission to copy this software, to modify it, to redistribute it,
+;to distribute modified versions, and to use it for any purpose is
+;granted, subject to the following restrictions and understandings.
+;
+;1. Any copy made of this software must include this copyright notice
+;in full.
+;
+;2. I have made no warranty or representation that the operation of
+;this software will be error-free, and I am under no obligation to
+;provide any services, by way of maintenance, update, or otherwise.
+;
+;3. In conjunction with products arising from the use of this
+;material, there shall be no use of my name in any advertising,
+;promotional, or sales literature without prior written consent in
+;each case.
+
+(module-compile-options warn-unknown-member: #t)
+
+(provide 'srfi-60)
+
+;;; These procedures are already Kawa built-ins and do not need to be
+;;; defined here: logand/bitwise-and, logior/bitwise-ior,
+;;; logxor/bitwise-xor, lognot/bitwise-not, bitwise-if, logtest,
+;;; logcount, integer-length, and ash/arithmetic-shift.
+
+;;; These procedures alias functionality provided by built-ins with
+;;; differing names:
+
+(define bitwise-merge bitwise-if)
+(define any-bits-set? logtest)
+(define bit-count logcount)
+(define log2-binary-factors bitwise-first-bit-set)
+(define first-set-bit bitwise-first-bit-set)
+(define bit-field bitwise-bit-field)
+(define reverse-bit-field bitwise-reverse-bit-field)
+
+;;; These procedures are similar to built-ins but with arguments
+;;; reordered:
+
+(define (logbit? index::int n::integer) ::boolean
+ (bitwise-bit-set? n index))
+(define bit-set? logbit?)
+
+(define (copy-bit-field to::integer from::integer start::int end::int)
+ ::integer
+ (bitwise-copy-bit-field to start end from))
+
+(define (rotate-bit-field n::integer count::int start::int end::int)
+ ::integer
+ (bitwise-rotate-bit-field n start end count))
+
+;;; This procedure has a slightly different signature compared to the
+;;; built-in bitwise-copy-bit: the first two arguments are swapped and
+;;; the last is a boolean instead of an int
+(define (copy-bit index::int from::integer bit::boolean)
+ ::integer
+ (bitwise-copy-bit from index (if bit 1 0)))
+
+;;; These procedures are entirely new, with implementations derived
+;;; from the SRFI-60 reference.
+(define (integer->list k::integer #!optional (len ::int (integer-length k)))
+ ::list
+ (do ((idx ::int (- len 1) (- idx 1))
+ (k ::integer k (ash k -1))
+ (lst ::list '() (cons (odd? k) lst)))
+ ((< idx 0) lst)))
+
+(define (list->integer bools::list) ::integer
+ (do ((bs bools (cdr bs))
+ (acc ::integer 0 (if (car bs) (+ acc acc 1) (+ acc acc))))
+ ((null? bs) acc)))
+
+(define (booleans->integer . bools)
+ (list->integer bools))
Property changes on: gnu/kawa/slib/srfi60.scm
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+Rev Id
\ No newline at end of property
Index: kawa/ChangeLog
===================================================================
--- kawa/ChangeLog (revision 7818)
+++ kawa/ChangeLog (working copy)
@@ -1,3 +1,11 @@
+2014-02-18 Jamison Hope <jrh@theptrgroup.com>
+
+ * standard/Scheme.java (initScheme): Remove 'logbit?', since it
+ just an alias for 'bitwise-bit-set?' and happens to conflict with
+ the semantics of SRFI-60 'logbit?'.
+ * standard/ImportFromLibrary.java (SRFI97Map): Update for SRFI-60.
+ * standard/require.java (featureMap): Likewise.
+
2014-02-17 Per Bothner <per@bothner.com>
* standard/define.java: Implement 'define-early-constant'.
Index: kawa/standard/ImportFromLibrary.java
===================================================================
--- kawa/standard/ImportFromLibrary.java (revision 7818)
+++ kawa/standard/ImportFromLibrary.java (working copy)
@@ -63,7 +63,7 @@
{ "54", "cat", MISSING },
{ "57", "records", MISSING },
{ "59", "vicinities", MISSING },
- { "60", "integer-bits", MISSING },
+ { "60", "integer-bits", "gnu.kawa.slib.srfi60" },
{ "61", "cond", MISSING },
{ "63", "arrays", MISSING },
{ "64", "testing", "gnu.kawa.slib.testing" },
Index: kawa/standard/Scheme.java
===================================================================
--- kawa/standard/Scheme.java (revision 7818)
+++ kawa/standard/Scheme.java (working copy)
@@ -599,8 +599,6 @@
defProcStFld("lognot", "gnu.kawa.functions.BitwiseOp", "not");
defProcStFld("logop", "kawa.lib.numbers");
defProcStFld("bitwise-bit-set?", "kawa.lib.numbers");
- defProcStFld("logbit?", "kawa.lib.numbers",
- Language.mangleNameIfNeeded("bitwise-bit-set?"));
defProcStFld("logtest", "kawa.lib.numbers");
defProcStFld("bitwise-bit-count", "kawa.lib.numbers");
defProcStFld("logcount", "kawa.lib.numbers");
Index: kawa/standard/require.java
===================================================================
--- kawa/standard/require.java (revision 7818)
+++ kawa/standard/require.java (working copy)
@@ -97,6 +97,7 @@
map("srfi-41-streams-type", SLIB_PREFIX + "StreamsType");
map("srfi-41-streams-primitive", SLIB_PREFIX + "StreamsPrimitive");
map("srfi-41-streams-derived", SLIB_PREFIX + "StreamsDerived");
+ map("srfi-60", SLIB_PREFIX + "srfi60");
map("srfi-64", SLIB_PREFIX + "testing");
map("testing", SLIB_PREFIX + "testing");
map("srfi-69", SLIB_PREFIX + "srfi69");
[-- Attachment #1.3: Type: text/plain, Size: 1 bytes --]
[-- Attachment #2: Message signed with OpenPGP using GPGMail --]
[-- Type: application/pgp-signature, Size: 204 bytes --]
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: SRFI-60
2014-02-18 16:30 ` SRFI-60 Jamison Hope
@ 2014-02-20 7:54 ` Per Bothner
2014-02-20 13:47 ` SRFI-60 Jamison Hope
0 siblings, 1 reply; 10+ messages in thread
From: Per Bothner @ 2014-02-20 7:54 UTC (permalink / raw)
To: Jamison Hope, kawa@sourceware.org list
On 02/18/2014 08:30 AM, Jamison Hope wrote:
> Here's a patch which adds SRFI-60, updates require.java and ImportFromLibrary.java, and removes logbit? from Scheme.java.
Thanks - I checked this in.
Note I had to fix testsuite/num-tests.scm, since it used logbit?
--
--Per Bothner
per@bothner.com http://per.bothner.com/
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: SRFI-60
2014-02-20 7:54 ` SRFI-60 Per Bothner
@ 2014-02-20 13:47 ` Jamison Hope
2014-02-20 13:51 ` [PATCH] Was: SRFI-60 Jamison Hope
0 siblings, 1 reply; 10+ messages in thread
From: Jamison Hope @ 2014-02-20 13:47 UTC (permalink / raw)
To: kawa@sourceware.org list
On Feb 20, 2014, at 2:54 AM, Per Bothner <per@bothner.com> wrote:
> On 02/18/2014 08:30 AM, Jamison Hope wrote:
>> Here's a patch which adds SRFI-60, updates require.java and ImportFromLibrary.java, and removes logbit? from Scheme.java.
>
> Thanks - I checked this in.
>
> Note I had to fix testsuite/num-tests.scm, since it used logbit?
Oops, missed that one. I realized that I also forgot to update
kawa.texi to remove the "mostly implemented" language. When I
went to remedy that, I got sidetracked looking to see what other
SRFIs are almost completely supported, or are supported but just
aren't mentioned in that list, and I came up with this:
SRFI 10: Sharp-Comma External Form
It's there, other than the optional define-reader-ctor,
which is easy to write using ReadTable#putReaderCtor.
SRFI 34: Exception Handling for Programs
Seems to be supported, except that some aggressive compiler
return type checking is making the JVM crash on examples with
(+ 1 (raise 'an-error)).
SRFI 38: External Representation for Data With Shared Structure
Is only missing read-with-shared-structure (kawa.texi
already mentions this).
SRFI 66: Octet Vectors
Is only missing u8vector=?, u8vector-compare, u8vector-copy!,
and u8vector-copy.
SRFI 70: Numbers
I think this is the same as R6RS numbers, which Kawa does
support, but with a handful of extra functions:
exact-floor, exact-ceiling, exact-truncate, and exact-round.
(Any others? It's a really long document.)
SRFI 72: Simple hygienic macros
This is syntax-case plus make-capturing-identifier and
around-syntax, I think.
I also noticed a bug -- the angle of a negative real should be pi,
not 0. A patch is coming.
--
Jamison Hope
The PTR Group
www.theptrgroup.com
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH] Was: Re: SRFI-60
2014-02-20 13:47 ` SRFI-60 Jamison Hope
@ 2014-02-20 13:51 ` Jamison Hope
2014-02-21 17:54 ` Per Bothner
0 siblings, 1 reply; 10+ messages in thread
From: Jamison Hope @ 2014-02-20 13:51 UTC (permalink / raw)
To: kawa@sourceware.org list
[-- Attachment #1: Type: text/plain, Size: 332 bytes --]
On Feb 20, 2014, at 8:47 AM, Jamison Hope <jrh@theptrgroup.com> wrote:
> I realized that I also forgot to update
> kawa.texi to remove the "mostly implemented" language. When I
> went to remedy that, I got sidetracked
It just happened again. Here's the update for kawa.texi.
--
Jamison Hope
The PTR Group
www.theptrgroup.com
[-- Attachment #2: doc_srfi60.patch --]
[-- Type: application/octet-stream, Size: 848 bytes --]
Index: doc/ChangeLog
===================================================================
--- doc/ChangeLog (revision 7819)
+++ doc/ChangeLog (working copy)
@@ -1,3 +1,7 @@
+2014-02-20 Jamison Hope <jrh@theptrgroup.com>
+
+ * kawa.texi (Implemented SRFIs): SRFI-60 is now fully supported.
+
2014-02-17 Per Bothner <per@bothner.com>
* kawa.texi (Ideas and tasks): Update.
Index: doc/kawa.texi
===================================================================
--- doc/kawa.texi (revision 7819)
+++ doc/kawa.texi (working copy)
@@ -1667,8 +1667,6 @@
@item
@uref{http://srfi.schemers.org/srfi-60/srfi-60.html, SRFI 60}:
Integers as Bits.
-Mostly implemented. A few functions are missing,
-and a few are only available under other names.
@item
@uref{http://srfi.schemers.org/srfi-62/srfi-62.html, SRFI 62}: S-expression comments.
@item
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] Was: Re: SRFI-60
2014-02-20 13:51 ` [PATCH] Was: SRFI-60 Jamison Hope
@ 2014-02-21 17:54 ` Per Bothner
2014-02-22 0:41 ` Jamison Hope
2014-02-22 8:04 ` Jamison Hope
0 siblings, 2 replies; 10+ messages in thread
From: Per Bothner @ 2014-02-21 17:54 UTC (permalink / raw)
To: Jamison Hope, kawa@sourceware.org list
On 02/20/2014 05:51 AM, Jamison Hope wrote:
> It just happened again. Here's the update for kawa.texi.
We should also update the Logical-Number-Operations section.
I'm inclined to replace the subsection name
"Deprecated Logical Number Operations"
by something like "SRFI-60 Logical Number Operations", and
adding something about having to use import or require.
(Not quite true right now, but it might be a plausible thing to do.)
And of course fix the logbit? description, and add any missing
functions.
It's possible some of these "deprecated" functions aren't SRFI-60;
then we'll have to consider what to do.
Could you do this, since you just looked into it?
--
--Per Bothner
per@bothner.com http://per.bothner.com/
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] Was: Re: SRFI-60
2014-02-21 17:54 ` Per Bothner
@ 2014-02-22 0:41 ` Jamison Hope
2014-02-22 8:04 ` Jamison Hope
1 sibling, 0 replies; 10+ messages in thread
From: Jamison Hope @ 2014-02-22 0:41 UTC (permalink / raw)
To: kawa@sourceware.org list
On Feb 21, 2014, at 12:53 PM, Per Bothner <per@bothner.com> wrote:
> Could you do this, since you just looked into it?
I'll take a look, although I'm no texinfo expert.
--
Jamison Hope
The PTR Group
www.theptrgroup.com
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] Was: Re: SRFI-60
2014-02-21 17:54 ` Per Bothner
2014-02-22 0:41 ` Jamison Hope
@ 2014-02-22 8:04 ` Jamison Hope
2014-02-26 7:13 ` Per Bothner
1 sibling, 1 reply; 10+ messages in thread
From: Jamison Hope @ 2014-02-22 8:04 UTC (permalink / raw)
To: kawa@sourceware.org list
[-- Attachment #1: Type: text/plain, Size: 6474 bytes --]
On Feb 21, 2014, at 12:53 PM, Per Bothner <per@bothner.com> wrote:
> We should also update the Logical-Number-Operations section.
> I'm inclined to replace the subsection name
> "Deprecated Logical Number Operations"
> by something like "SRFI-60 Logical Number Operations", and
> adding something about having to use import or require.
> (Not quite true right now, but it might be a plausible thing to do.)
> And of course fix the logbit? description, and add any missing
> functions.
>
> It's possible some of these "deprecated" functions aren't SRFI-60;
> then we'll have to consider what to do.
See attached.
As it turns out, there's one "deprecated" function which is not a
SRFI-60 name: bit-extract. The SRFI-60 equivalent is called
bit-field. (Both are equivalent to R6RS bitwise-bit-field.)
Of the non-deprecated Kawa functions, all but logop and logtest are
mandated by R6RS (logtest is in SRFI-60 but has no equivalent in R6RS).
Of the R6RS functions, five of them also appear in SRFI-60 with the
same name: bitwise-not, bitwise-and, bitwise-ior, bitwise-xor, and
bitwise-if. They all also have alternate names in SRFI-60 (lognot,
logand, logior, logxor, bitwise-merge).
I put in a SRFI-60 section as you suggested. For now, I marked the
functions which are (old) builtins as such, with language saying that
the rest are available via (require 'srfi-60) or (import (srfi :60)).
I left the "deprecated" subsection there, but it only contains
bit-extract now. It probably makes sense to just get rid of that
function, but that feels like it should be a separate commit.
BTW here's an org-mode table I made while figuring all this stuff out.
|--------------------------------------------+------+------+---------|
| Function | R6RS | Kawa | SRFI-60 |
|--------------------------------------------+------+------+---------|
| bitwise-not n | Y | Y | Y |
| lognot n | | Dep | Y |
|--------------------------------------------+------+------+---------|
| bitwise-and n1 ... | Y | Y | Y |
| logand n1 ... | | Dep | Y |
|--------------------------------------------+------+------+---------|
| bitwise-ior n1 ... | Y | Y | Y |
| logior n1 ... | | Dep | Y |
|--------------------------------------------+------+------+---------|
| bitwise-xor n1 ... | Y | Y | Y |
| logxor n1 ... | | Dep | Y |
|--------------------------------------------+------+------+---------|
| bitwise-if mask n0 n1 | Y | Y | Y |
| bitwise-merge mask n0 n1 | | | Y |
|--------------------------------------------+------+------+---------|
| bitwise-bit-count n | Y | Y | |
| logcount n | | Dep | Y |
| bit-count n | | | Y |
|--------------------------------------------+------+------+---------|
| bitwise-length n | Y | Y | |
| integer-length n | | Dep | Y |
|--------------------------------------------+------+------+---------|
| bitwise-first-bit-set n | Y | Y | |
| log2-binary-factors n | | | Y |
| first-set-bit n | | | Y |
|--------------------------------------------+------+------+---------|
| bitwise-bit-set? n index | Y | Y | |
| logbit? index n | | Dep* | Y |
| bit-set? index n | | | Y |
|--------------------------------------------+------+------+---------|
| bitwise-copy-bit from index bit (int) | Y | Y | |
| copy-bit index from bit (boolean) | | | Y |
|--------------------------------------------+------+------+---------|
| bitwise-bit-field n start end | Y | Y | |
| bit-field n start end | | | Y |
| bit-extract n start end | | Dep | |
|--------------------------------------------+------+------+---------|
| bitwise-copy-bit-field to start end from | Y | Y | |
| copy-bit-field to from start end | | | Y |
|--------------------------------------------+------+------+---------|
| bitwise-arithmetic-shift n count | Y | Y | |
| arithmetic-shift n count | | Dep | Y |
| ash n count | | Dep | Y |
|--------------------------------------------+------+------+---------|
| bitwise-arithmetic-shift-left n count | Y | Y | |
| bitwise-arithmetic-shift-right n count | Y | Y | |
|--------------------------------------------+------+------+---------|
| bitwise-rotate-bit-field n start end count | Y | Y | |
| rotate-bit-field n count start end | | | Y |
|--------------------------------------------+------+------+---------|
| bitwise-reverse-bit-field n start end | Y | Y | |
| reverse-bit-field n start end | | | Y |
|--------------------------------------------+------+------+---------|
| logtest j k | | Y | Y |
| any-bits-set? j k | | | Y |
|--------------------------------------------+------+------+---------|
| integer->list k [len] | | | Y |
|--------------------------------------------+------+------+---------|
| list->integer list | | | Y |
|--------------------------------------------+------+------+---------|
| booleans->integer bool1 ... | | | Y |
|--------------------------------------------+------+------+---------|
| logop op x y | | Y | |
|--------------------------------------------+------+------+---------|
--
Jamison Hope
The PTR Group
www.theptrgroup.com
[-- Attachment #2: detailed_srfi60_documentation.patch --]
[-- Type: application/octet-stream, Size: 5178 bytes --]
Index: doc/ChangeLog
===================================================================
--- doc/ChangeLog (revision 7826)
+++ doc/ChangeLog (working copy)
@@ -1,3 +1,10 @@
+2014-02-22 Jamison Hope <jrh@theptrgroup.com>
+
+ * kawa.texi (Logical Number Operations): New subsection 'SRFI-60
+ Logical Number Operations' documenting the non-R6RS functions in
+ the SRFI. Many of the functions are moved here from the
+ subsection 'Deprecated Logical Number Operations'.
+
2014-02-21 Per Bothner <per@bothner.com>
* kawa.texi (Ideas and tasks): Various updates.
Index: doc/kawa.texi
===================================================================
--- doc/kawa.texi (revision 7826)
+++ doc/kawa.texi (working copy)
@@ -5672,49 +5672,113 @@
but is more efficient.
@end deffn
-@subsection Deprecated Logical Number Operations
+@subsection SRFI-60 Logical Number Operations
-These older functions are still available, but we
-recommand using the R6RS-compatible functions.
+Kawa supports SRFI-60 ``Integers as Bits'' as well, although we
+generally recommend using the R6RS-compatible functions instead when
+possible. Unless noted as being a builtin function, to use these you
+must first @code{(require 'srfi-60)} or @code{(import (srfi :60))}
+(or @code{(import (srfi :60 integer-bits))}).
-@deffn Procedure lognot i
-Equivalent to @code{(bitwise-not @var{i})}.
-@end deffn
-
@deffn Procedure logand i ...
-Equivalent to @code{(bitwise-and @var{i} ...)}.
+Equivalent to @code{(bitwise-and @var{i} ...)}. Builtin.
@end deffn
@deffn Procedure logior i ...
-Equivalent to @code{(bitwise-ior @var{i} ...)}.
+Equivalent to @code{(bitwise-ior @var{i} ...)}. Builtin.
@end deffn
@deffn Procedure logxor i ...
-Equivalent to @code{(bitwise-xor @var{i} ...)}.
+Equivalent to @code{(bitwise-xor @var{i} ...)}. Builtin.
@end deffn
+@deffn Procedure lognot i
+Equivalent to @code{(bitwise-not @var{i})}. Builtin.
+@end deffn
+
+@deffn Procedure bitwise-merge mask i j
+Equivalent to @code{(bitwise-if @var{mask} @var{i} @var{j})}.
+@end deffn
+
+@deffn Procedure any-bits-set? i j
+Equivalent to @code{(logtest @var{i} @var{j})}.
+@end deffn
+
@deffn Procedure logcount i
+@deffnx Procedure bit-count i
Count the number of 1-bits in @var{i}, if it is non-negative.
If @var{i} is negative, count number of 0-bits.
Same as @code{(bitwise-bit-count @var{i})} if @var{i} is non-negative.
+Builtin as @func{logcount}.
@end deffn
@deffn Procedure integer-length i
-Equivalent to @code{(bitwise-length @var{i})}.
+Equivalent to @code{(bitwise-length @var{i})}. Builtin.
@end deffn
-@deffn Procedure logbit? i pos
-Equivalent to @code{bitwise-bit-set? @var{i} @var{pos})}.
+@deffn Procedure log2-binary-factors i
+@deffnx Procedure first-set-bit i
+Equivalent to @code{(bitwise-first-bit-set @var{i})}.
@end deffn
+@deffn Procedure logbit? pos i
+@deffnx Procedure bit-set? pos i
+Equivalent to @code{(bitwise-bit-set? @var{i} @var{pos})}.
+@end deffn
+
+@deffn Procedure copy-bit bitno i bool
+Equivalent to @code{(bitwise-copy-bit @var{i} @var{bitno} (if @var{bool} 1 0))}.
+@end deffn
+
+@deffn Procedure bit-field n start end
+Equivalent to @code{(bitwise-bit-field @var{n} @var{start} @var{end})}.
+@end deffn
+
+@deffn Procedure copy-bit-field to from start end
+Equivalent to @code{(bitwise-copy-bit-field @var{to} @var{start} @var{end} @var{from})}.
+@end deffn
+
@deffn Procedure arithmetic-shift i j
-Equivalent to @code{bitwise-arithmetic-shift @var{i} @var{j})}.
+Equivalent to @code{(bitwise-arithmetic-shift @var{i} @var{j})}. Builtin.
@end deffn
@deffn Procedure ash i j
-Alias for @code{arithmetic-shift}.
+Alias for @code{arithmetic-shift}. Builtin.
@end deffn
+@deffn Procedure rotate-bit-field n count start end
+Equivalent to @code{(bitwise-rotate-bit-field @var{n} @var{start} @var{end} @var{count})}.
+@end deffn
+
+@deffn Procedure reverse-bit-field i start end
+Equivalent to @code{(bitwise-reverse-bit-field @var{i} @var{start} @var{end})}.
+@end deffn
+
+@deffn Procedure integer->list @var{k} [@var{length}]
+@deffnx Procedure list->integer @var{list}
+The @func{integer->list} procedure returns a list of @var{length}
+booleans corresponding to the bits of the non-negative integer @var{k},
+with @code{#t} for @code{1} and @code{#f} for @code{0}. @var{length}
+defaults to @code{(bitwise-length @var{k})}. The list will be in order
+from MSB to LSB, with the value of @code{(odd? @var{k})} in the last
+car.
+
+The @func{list->integer} procedure returns the integer corresponding to
+the booleans in the list @var{list}.
+The @func{integer->list} and @func{list->integer} procedures are
+inverses so far as @func{equal?} is concerned.
+@end deffn
+
+@deffn Procedure booleans->integer bool1 ...
+Returns the integer coded by the @var{bool1} ... arguments.
+Equivalent to @code{(list->integer (list @var{bool1} ...))}.
+@end deffn
+
+@subsection Deprecated Logical Number Operations
+
+This older function is still available, but we
+recommend using the R6RS-compatible function.
+
@deffn Procedure bit-extract n start end
Equivalent to @code{(bitwise-bit-field @var{n} @var{start} @var{end})}.
@end deffn
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] Was: Re: SRFI-60
2014-02-22 8:04 ` Jamison Hope
@ 2014-02-26 7:13 ` Per Bothner
0 siblings, 0 replies; 10+ messages in thread
From: Per Bothner @ 2014-02-26 7:13 UTC (permalink / raw)
To: Jamison Hope, kawa@sourceware.org list
On 02/22/2014 12:04 AM, Jamison Hope wrote:
> On Feb 21, 2014, at 12:53 PM, Per Bothner <per@bothner.com> wrote:
>
>> We should also update the Logical-Number-Operations section.
> ...
> See attached.
Thanks - I checked this in.
--
--Per Bothner
per@bothner.com http://per.bothner.com/
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2014-02-26 7:13 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-02-18 6:53 SRFI-60 Jamison Hope
2014-02-18 7:12 ` SRFI-60 Per Bothner
2014-02-18 16:30 ` SRFI-60 Jamison Hope
2014-02-20 7:54 ` SRFI-60 Per Bothner
2014-02-20 13:47 ` SRFI-60 Jamison Hope
2014-02-20 13:51 ` [PATCH] Was: SRFI-60 Jamison Hope
2014-02-21 17:54 ` Per Bothner
2014-02-22 0:41 ` Jamison Hope
2014-02-22 8:04 ` Jamison Hope
2014-02-26 7:13 ` Per Bothner
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).