Re: [Chicken-hackers] Proposal / patch for fixing #1385 (swapped bit-set? argument order)

2017-08-19 Thread Kooda
Sounds like the best thing to do.

Applied. :)

___
Chicken-hackers mailing list
Chicken-hackers@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-hackers


Re: [Chicken-hackers] Proposal / patch for fixing #1385 (swapped bit-set? argument order)

2017-08-08 Thread John Cowan
On Tue, Aug 8, 2017 at 2:11 PM, Peter Bex  wrote:

Renaming it to a completely nonstandard name should make it easy to port,
>

I think this is the Right Thing.


> and later on (CHICKEN 5.1 or even 5.2) we can re-introduce the bit-set?
> procedure with the correct argument order, and deprecate the new procedure.
>

I would say: don't even bother bringing bit-set? back in a Chicken package.
  If you want or need it, import it from srfi-33, srfi-60, or (latest and
greatest) srfi-151, all of which use (bit-set? index i).


> The name of the nonstandard procedure is not very relevant since it is
> going to disappear anyway, but I think bit->boolean is a relatively clean
> name.


I agree.

-- 
John Cowan  http://vrici.lojban.org/~cowanco...@ccil.org
C'est la` pourtant que se livre le sens du dire, de ce que, s'y conjuguant
le nyania qui bruit des sexes en compagnie, il supplee a ce qu'entre eux,
de rapport nyait pas.   --Jacques Lacan, "L'Etourdit"
___
Chicken-hackers mailing list
Chicken-hackers@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-hackers


[Chicken-hackers] Proposal / patch for fixing #1385 (swapped bit-set? argument order)

2017-08-08 Thread Peter Bex
Hi all,

I've discussed #1385 with Felix, and after some consideration we agreed
the lesser of three evils is to rename the procedure to something
completely nonstandard.  Swapping the argument order in CHICKEN 5 will
almost certainly introduce insidious bugs when porting existing programs
from CHICKEN 4 or from other Schemes.  And keeping the argument order is
bad too, because we will pay the price for having a nonstandard argument
order for the rest of all time.

Keeping the old procedure and adding a new one just moves the problem of
how to rectify this into the future, so that's not an option either.
Renaming it to a completely nonstandard name should make it easy to port,
and later on (CHICKEN 5.1 or even 5.2) we can re-introduce the bit-set?
procedure with the correct argument order, and deprecate the new procedure.

The name of the nonstandard procedure is not very relevant since it is
going to disappear anyway, but I think bit->boolean is a relatively clean
name.  Luckily, core itself doesn't use bit-set? anywhere, so we can
just rename it with impunity, no need to keep the OBSOLETE name around.

If nobody disagrees, let's get this over with!

Cheers,
Peter
From 32b45a6ac3b0297762c1d5bb85847535d85abedb Mon Sep 17 00:00:00 2001
From: Peter Bex 
Date: Tue, 8 Aug 2017 19:48:07 +0200
Subject: [PATCH] Rename bit-set? to bit->boolean to avoid confusion (fixes
 #1385)

The problem with bit-set? is that our definition has the argument
order swapped when compared to SRFI-33 and SRFI-60.  Given that all
our other procedures follow the definitions given in these SRFIs, it
is extra confusing that this one procedure has a different argument
order.  This may result in very subtle bugs.

To make matters worse, swapping the argument to match the SRFIs would
be downright evil, because it would make porting bugs harder to
find: (bit-set? 1 2) for example will return different values
depending on which argument indicates the number and which the bit
position, but the result is still a boolean and in other cases it
might "accidentally" return the expected result, making it very very
difficult to figure out why a program is failing.

So this is why we rename it: When porting any program from CHICKEN 4
to CHICKEN 5 (or from another Scheme), it will immediately error out,
and after a quick search one will be able to find the CHICKEN 5
procedure bit->boolean (and curse us for deviating from the SRFI, not
knowing our alternatives were even worse).

The new bit->boolean procedure immediately has a sort of deprecated
status.  Later on, after enough time has passed to have ported all
CHICKEN 4 code, bit-set? may be re-introduced with the
correct (SRFI-compliant) argument order, and we can then officially
deprecate bit->boolean.  Even later still we can finally get rid of
this ugly temporary procedure.
---
 NEWS  |  3 +++
 c-platform.scm|  6 +++---
 chicken.h | 10 ++
 library.scm   |  4 +++-
 runtime.c |  9 +
 tests/numbers-test-ashinn.scm |  4 ++--
 tests/numbers-test.scm| 26 +-
 types.db  |  8 
 8 files changed, 39 insertions(+), 31 deletions(-)

diff --git a/NEWS b/NEWS
index a7622b9b..6c0b6487 100644
--- a/NEWS
+++ b/NEWS
@@ -50,6 +50,9 @@
   - Added the `glob->sre` procedure to the irregex library.
   - Removed the `get-host-name' and `system-information' procedures.
 These are available in the "system-information" egg.
+  - Renamed bit-set? to bit->boolean because of swapped argument order
+with respect to SRFI-33 and SRFI-60, which was confusing (fixes
+#1385, thanks to Lemonboy).
 
 - Module system
   - The compiler has been modularised, for improved namespacing.  This
diff --git a/c-platform.scm b/c-platform.scm
index 100cccb9..f94dcfd4 100644
--- a/c-platform.scm
+++ b/c-platform.scm
@@ -157,7 +157,7 @@
 chicken.bitwise#integer-length
 chicken.bitwise#bitwise-and chicken.bitwise#bitwise-not
 chicken.bitwise#bitwise-ior chicken.bitwise#bitwise-xor
-chicken.bitwise#arithmetic-shift chicken.bitwise#bit-set?
+chicken.bitwise#arithmetic-shift chicken.bitwise#bit->boolean
 add1 sub1 exact-integer? nan? finite? infinite?
 void flush-output print print* error call/cc chicken.blob#blob-size
 identity chicken.blob#blob=? equal=? make-polar make-rectangular
@@ -1013,7 +1013,7 @@
 		  (list arg)) ) ) ) ) ) ) )
 
 (rewrite
- 'chicken.bitwise#bit-set? 8
+ 'chicken.bitwise#bit->boolean 8
  (lambda (db classargs cont callargs)
(and (= 2 (length callargs))
 	(make-node
@@ -1021,7 +1021,7 @@
 	 (list cont
 	   (make-node
 		'##core#inline 
-		(list (if (eq? number-type 'fixnum) "C_u_i_bit_setp" "C_i_bit_setp"))
+		(list (if (eq? number-type 'fixnum) "C_u_i_bit_to_bool" "C_i_bit_to_bool"))
 		callargs) ) ) ) ) )
 
 (rewrite
diff --git a/chicken.h b/chicken.h
index 443565d3..6d72fcea 100644