GNU bug report logs - #32252
[PATCH] %o and %x now format signed numbers

Previous Next

Package: emacs;

Reported by: Paul Eggert <eggert <at> cs.ucla.edu>

Date: Mon, 23 Jul 2018 19:14:02 UTC

Severity: normal

Tags: patch

Done: Paul Eggert <eggert <at> cs.ucla.edu>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 32252 in the body.
You can then email your comments to 32252 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#32252; Package emacs. (Mon, 23 Jul 2018 19:14:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Paul Eggert <eggert <at> cs.ucla.edu>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Mon, 23 Jul 2018 19:14:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: bug-gnu-emacs <at> gnu.org
Cc: Paul Eggert <eggert <at> cs.ucla.edu>
Subject: [PATCH] %o and %x now format signed numbers
Date: Mon, 23 Jul 2018 12:12:50 -0700
Treat integers as signed numbers when using the %o
and %x format specifiers, instead of treating them as
a machine-dependent two’s complement representation.
This should make Emacs more machine-independent, and
better-insulated for future changes involving bignums.
The new compatibility variable ‘binary-as-unsigned’
enables the old machine-dependent behavior.
This is a simplified version of the change proposed in:
https://lists.gnu.org/r/emacs-devel/2018-07/msg00763.html
I simplified that proposal by omitting bitwidth modifiers, as
I could not find an any example uses in the Emacs source code
that needed them and doing them correctly would have been
quite a bit more work for apparently little benefit.
* doc/lispref/strings.texi (Formatting Strings):
* etc/NEWS: Document change.
* src/editfns.c (styled_format): Treat integers as signed
numbers even with %o and %x.  Support the + and space
flags with %o and %x, since they’re about signs.
(syms_of_editfns): New compatibility variable binary-as-signed.
* test/src/editfns-tests.el (read-large-integer):
Test that maximal integers can be read after printing
with all integer formats.
(format-%o-invalid-float): Adjust test to match new
behavior, which allows negative octal.
---
 doc/lispref/strings.texi  |  6 +++---
 etc/NEWS                  |  8 ++++++++
 src/editfns.c             | 42 ++++++++++++++++++++++++++++++++++-----
 test/src/editfns-tests.el | 11 +++++-----
 4 files changed, 54 insertions(+), 13 deletions(-)

diff --git a/doc/lispref/strings.texi b/doc/lispref/strings.texi
index 2fff3c7c75..582561fe42 100644
--- a/doc/lispref/strings.texi
+++ b/doc/lispref/strings.texi
@@ -922,7 +922,7 @@ Formatting Strings
 @item %o
 @cindex integer to octal
 Replace the specification with the base-eight representation of an
-unsigned integer.  The object can also be a nonnegative floating-point
+integer.  The object can also be a floating-point
 number that is formatted as an integer, dropping any fraction, if the
 integer does not exceed machine limits.
 
@@ -935,8 +935,8 @@ Formatting Strings
 @itemx %X
 @cindex integer to hexadecimal
 Replace the specification with the base-sixteen representation of an
-unsigned integer.  @samp{%x} uses lower case and @samp{%X} uses upper
-case.  The object can also be a nonnegative floating-point number that
+integer.  @samp{%x} uses lower case and @samp{%X} uses upper
+case.  The object can also be a floating-point number that
 is formatted as an integer, dropping any fraction, if the integer does
 not exceed machine limits.
 
diff --git a/etc/NEWS b/etc/NEWS
index fc2a5d4c03..b735cf49b3 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -697,6 +697,14 @@ To get the old behavior, set the new, experimental variable
 read-integer-overflow-as-float to t and please email
 30408 <at> debbugs.gnu.org if you need that.  (Bug#30408).
 
++++
+** Numbers formatted via %o or %x are now formatted as signed integers.
+Formerly they were formatted using machine-dependent two's complement
+representations.  To get the old behavior, set the new, experimental
+variable binary-as-unsigned to t and please email emacs-devel <at> gnu.org
+if you need that.  Because %o and %x now format signed integers, they
+now support the + and space flags.
+
 ---
 ** Some functions and variables obsolete since Emacs 22 have been removed:
 archive-mouse-extract, assoc-ignore-case, assoc-ignore-representation,
diff --git a/src/editfns.c b/src/editfns.c
index 09f836c3eb..a8fc499d63 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -4196,8 +4196,8 @@ contain either numbered or unnumbered %-sequences but not both, except
 that %% can be mixed with numbered %-sequences.
 
 The + flag character inserts a + before any nonnegative number, while a
-space inserts a space before any nonnegative number; these flags only
-affect %d, %e, %f, and %g sequences, and the + flag takes precedence.
+space inserts a space before any nonnegative number; these flags
+affect only numeric %-sequences, and the + flag takes precedence.
 The - and 0 flags affect the width specifier, as described below.
 
 The # flag means to use an alternate display form for %o, %x, %X, %e,
@@ -4736,19 +4736,42 @@ styled_format (ptrdiff_t nargs, Lisp_Object *args, bool message)
 		}
 	      else
 		{
-		  /* Don't sign-extend for octal or hex printing.  */
 		  uprintmax_t x;
+		  bool negative;
 		  if (INTEGERP (arg))
-		    x = XUINT (arg);
+		    {
+		      EMACS_INT i;
+		      if (binary_as_unsigned)
+			{
+			  i = XUINT (arg);
+			  negative = false;
+			}
+		      else
+			{
+			  i = XINT (arg);
+			  negative = i < 0;
+			  if (negative)
+			    i = -i;
+			}
+		      x = i;
+		    }
 		  else
 		    {
 		      double d = XFLOAT_DATA (arg);
 		      double uprintmax = TYPE_MAXIMUM (uprintmax_t);
+		      negative = d < 0;
+		      if (negative)
+			d = -d;
 		      if (! (0 <= d && d < uprintmax + 1))
 			xsignal1 (Qoverflow_error, arg);
 		      x = d;
+		      negative &= x != 0;
 		    }
-		  sprintf_bytes = sprintf (sprintf_buf, convspec, prec, x);
+		  sprintf_buf[0] = negative ? '-' : plus_flag ? '+' : ' ';
+		  bool signedp = negative | plus_flag | space_flag;
+		  sprintf_bytes = sprintf (sprintf_buf + signedp,
+					   convspec, prec, x);
+		  sprintf_bytes += signedp;
 		}
 
 	      /* Now the length of the formatted item is known, except it omits
@@ -5558,6 +5581,15 @@ functions if all the text being accessed has this property.  */);
   DEFVAR_LISP ("operating-system-release", Voperating_system_release,
 	       doc: /* The release of the operating system Emacs is running on.  */);
 
+  DEFVAR_BOOL ("binary-as-unsigned",
+	       binary_as_unsigned,
+	       doc: /* Non-nil means `format' %x and %o treat numbers as unsigned.
+Nil (the default) means to treat them as signed.
+Treating them as unsigned has machine-dependent results.
+
+This variable is experimental; email emacs-devel <at> gnu.org if you need it.  */);
+  binary_as_unsigned = false;
+
   defsubr (&Spropertize);
   defsubr (&Schar_equal);
   defsubr (&Sgoto_char);
diff --git a/test/src/editfns-tests.el b/test/src/editfns-tests.el
index c828000bb4..57a2081fc5 100644
--- a/test/src/editfns-tests.el
+++ b/test/src/editfns-tests.el
@@ -165,15 +165,16 @@ transpose-test-get-byte-positions
                 :type 'overflow-error)
   (should-error (read (substring (format "%d" most-negative-fixnum) 1))
                 :type 'overflow-error)
-  (should-error (read (format "#x%x" most-negative-fixnum))
-                :type 'overflow-error)
-  (should-error (read (format "#o%o" most-negative-fixnum))
-                :type 'overflow-error)
+  (dolist (fmt '("%d" "%s" "#o%o" "#x%x"))
+    (dolist (val (list most-negative-fixnum (1+ most-negative-fixnum)
+                       -1 0 1
+                       (1- most-positive-fixnum) most-positive-fixnum))
+      (should (eq val (read (format fmt val))))))
   (should-error (read (format "#32rG%x" most-positive-fixnum))
                 :type 'overflow-error))
 
 (ert-deftest format-%o-invalid-float ()
-  (should-error (format "%o" -1e-37)
+  (should-error (format "%o" -1e+INF)
                 :type 'overflow-error))
 
 ;; Bug#31938
-- 
2.17.1





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#32252; Package emacs. (Mon, 23 Jul 2018 19:49:04 GMT) Full text and rfc822 format available.

Message #8 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Helmut Eller <eller.helmut <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: Re: bug#32252: [PATCH] %o and %x now format signed numbers
Date: Mon, 23 Jul 2018 21:48:06 +0200
>  Replace the specification with the base-eight representation of an
> -unsigned integer.  The object can also be a nonnegative floating-point
> +integer.  The object can also be a floating-point
>  number that is formatted as an integer, dropping any fraction, if the
>  integer does not exceed machine limits.

Why breaking longstanding behavior instead of introducing this with a
different format specifier.  Like %a.

> +  DEFVAR_BOOL ("binary-as-unsigned",
> +	       binary_as_unsigned,
> +	       doc: /* Non-nil means `format' %x and %o treat numbers as unsigned.
 
This is the same crap as text-quoting-style.  Nil should mean treat
numbers in the tradtional way.

Helmut





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#32252; Package emacs. (Mon, 23 Jul 2018 19:50:02 GMT) Full text and rfc822 format available.

Message #11 received at 32252 <at> debbugs.gnu.org (full text, mbox):

From: Drew Adams <drew.adams <at> oracle.com>
To: Paul Eggert <eggert <at> cs.ucla.edu>, 32252 <at> debbugs.gnu.org
Subject: RE: bug#32252: [PATCH] %o and %x now format signed numbers
Date: Mon, 23 Jul 2018 12:49:10 -0700 (PDT)
1. I don't see where the doc now mentions variable `binary-as-signed'.  And I don't see where the doc mentions what the output is for %o and %x - for a negative number or a positive number.

2. Should `binary-as-signed' perhaps be a user option?

3. Why the change in the default behavior?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#32252; Package emacs. (Mon, 23 Jul 2018 23:31:01 GMT) Full text and rfc822 format available.

Message #14 received at 32252 <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Drew Adams <drew.adams <at> oracle.com>, 32252 <at> debbugs.gnu.org
Subject: Re: bug#32252: [PATCH] %o and %x now format signed numbers
Date: Mon, 23 Jul 2018 16:30:34 -0700
On 07/23/2018 12:49 PM, Drew Adams wrote:
> 1. I don't see where the doc now mentions variable `binary-as-signed'.

binary-as-signed is intentionally documented only in its doc string. The 
intent is that it be like the variable read-integer-overflow-as-float. 
That is, although it's present if someone actually needs it, we're 
hoping actual use cases are so rare that we can obsolete the variable 
soon. This is also why it's not a user option.

> I don't see where the doc mentions what the output is for %o and %x - for a negative number or a positive number.

For %o the Elisp manual says "Replace the specification with the 
base-eight representation of an
integer", and there is similar wording for %x and %X. It might be 
helpful to nail down negative-integer handling with wording like "Format 
a negative integer with a leading @samp{-} followed by the absolute value."

> 3. Why the change in the default behavior?

The primary motivation is that the old behavior can't reasonably be 
extended to bignums. Also, it's long been an annoyance that the old 
behavior was machine dependent: (format "%x" -1) yields different 
answers depending on what machine you're running on. The proposed change 
would make this usage portable, and would make it obvious what bignums 
should do.





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#32252; Package emacs. (Mon, 23 Jul 2018 23:40:02 GMT) Full text and rfc822 format available.

Message #17 received at 32252 <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Helmut Eller <eller.helmut <at> gmail.com>
Cc: 32252 <at> debbugs.gnu.org
Subject: Re: bug#32252: [PATCH] %o and %x now format signed numbers
Date: Mon, 23 Jul 2018 16:39:08 -0700
> Why breaking longstanding behavior instead of introducing this with a
> different format specifier.  Like %a.

Although it is indeed an incompatible change, I surveyed the existing 
Emacs source code and couldn't find anything that the change would 
break. Almost all uses of %x, %X, and %o were with nonnegative integers 
where the behavior would not change. In the few places I found where the 
integers could be negative, the resulting strings were things like 
nonces where the change didn't break anything. Of course I could have 
missed some uses, and there are uses outside of Emacs source code; 
still, it seems that this change would break very little user code (and 
the rare users who might run into a problem have a simple workaround).

%a has quite a different meaning in C11, so we'd need to use some other 
letter (or set of letters, if we want something for %x, %X, %o) if we 
went that route. This seems like overkill for such a small change to 
functionality that hardly ever matters; plus, %x, %X and %o would 
continue to have problematic machine-dependent semantics and would not 
be sensibly extensible to bignums.





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#32252; Package emacs. (Tue, 24 Jul 2018 01:18:02 GMT) Full text and rfc822 format available.

Message #20 received at 32252 <at> debbugs.gnu.org (full text, mbox):

From: Drew Adams <drew.adams <at> oracle.com>
To: Paul Eggert <eggert <at> cs.ucla.edu>, Helmut Eller <eller.helmut <at> gmail.com>
Cc: 32252 <at> debbugs.gnu.org
Subject: RE: bug#32252: [PATCH] %o and %x now format signed numbers
Date: Mon, 23 Jul 2018 18:16:52 -0700 (PDT)
> Although it is indeed an incompatible change, I surveyed the existing
> Emacs source code and couldn't find anything that the change would
> break.

Inadequate.  Never wholly irrelevant, but certainly not
sufficient.  You surveyed something mostly irrelevant.

Emacs is about users.  Users use Elisp.  Lisp code delivered
with Emacs is not the same as the set of existing Emacs Lisp
code. Far, far from it.  This is a classic mistake.

> Almost all uses ... would not change.

What should be done, usually (not always):

1. Keep the default behavior - at least for a while
   (typically quite a while).

2. Ask users.  Take a poll - beyond this list.

What should not be done, usually:

* Just do what you feel like - make the default behavior
  whatever you like.

(Note: I don't have a horse in this race.  I don't care
what the default behavior is in this case, other than,
other things being equal it should be kept as is, as
that usually perturbs users least.)




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#32252; Package emacs. (Tue, 24 Jul 2018 01:21:03 GMT) Full text and rfc822 format available.

Message #23 received at 32252 <at> debbugs.gnu.org (full text, mbox):

From: Drew Adams <drew.adams <at> oracle.com>
To: Paul Eggert <eggert <at> cs.ucla.edu>, 32252 <at> debbugs.gnu.org
Subject: RE: bug#32252: [PATCH] %o and %x now format signed numbers
Date: Mon, 23 Jul 2018 18:20:32 -0700 (PDT)
> > 3. Why the change in the default behavior?
> 
> The primary motivation is that the old behavior can't reasonably be
> extended to bignums. Also, it's long been an annoyance that the old
> behavior was machine dependent: (format "%x" -1) yields different
> answers depending on what machine you're running on. The proposed change
> would make this usage portable, and would make it obvious what bignums
> should do.

Put that motivation in NEWS.  Users deserve to be told why
things change incompatibly.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#32252; Package emacs. (Tue, 24 Jul 2018 02:06:02 GMT) Full text and rfc822 format available.

Message #26 received at 32252 <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Drew Adams <drew.adams <at> oracle.com>, 32252 <at> debbugs.gnu.org
Subject: Re: bug#32252: [PATCH] %o and %x now format signed numbers
Date: Mon, 23 Jul 2018 19:04:48 -0700
Drew Adams wrote:
> Put that motivation in NEWS.  Users deserve to be told why
> things change incompatibly.

OK, here's a revised NEWS entry. It also mentions avoiding read/print 
misbehavior, a more-immediate prompt for this change that I forgot to mention 
previously.

** Numbers formatted via %o or %x are now formatted as signed integers.
Formerly they were formatted using machine-dependent two's complement
representations.  The new behavior is machine-independent, avoids
misbehavior in calls like (read (format "#x%x" -1)), and is more
compatible with bignums, a planned feature.  To get the old behavior,
set the new, experimental variable binary-as-unsigned to t and please
email 32252 <at> debbugs.gnu.org if you need that.  Because %o and %x now
format signed integers, they now support the + and space flags.
(Bug#32252).




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#32252; Package emacs. (Tue, 24 Jul 2018 02:39:01 GMT) Full text and rfc822 format available.

Message #29 received at 32252 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Paul Eggert <eggert <at> cs.ucla.edu>
Cc: 32252 <at> debbugs.gnu.org, drew.adams <at> oracle.com
Subject: Re: bug#32252: [PATCH] %o and %x now format signed numbers
Date: Tue, 24 Jul 2018 05:38:09 +0300
> From: Paul Eggert <eggert <at> cs.ucla.edu>
> Date: Mon, 23 Jul 2018 19:04:48 -0700
> 
> ** Numbers formatted via %o or %x are now formatted as signed integers.
> Formerly they were formatted using machine-dependent two's complement
> representations.  The new behavior is machine-independent, avoids
> misbehavior in calls like (read (format "#x%x" -1)), and is more
> compatible with bignums, a planned feature.  To get the old behavior,
> set the new, experimental variable binary-as-unsigned to t and please
> email 32252 <at> debbugs.gnu.org if you need that.  Because %o and %x now
> format signed integers, they now support the + and space flags.
> (Bug#32252).

Please don't put bug numbers in NEWS.  If some bug is important for
NEWS (I doubt that it ever could be), describe it instead.

NEWS is for people who want to grasp changes at a glance, we shouldn't
bother them with looking up bugs.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#32252; Package emacs. (Tue, 24 Jul 2018 02:45:02 GMT) Full text and rfc822 format available.

Message #32 received at 32252 <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 32252 <at> debbugs.gnu.org, drew.adams <at> oracle.com
Subject: Re: bug#32252: [PATCH] %o and %x now format signed numbers
Date: Mon, 23 Jul 2018 19:44:33 -0700
Eli Zaretskii wrote:
> Please don't put bug numbers in NEWS.  If some bug is important for
> NEWS (I doubt that it ever could be), describe it instead.

Sorry, I didn't know that. Should I remove the existing bug numbers in NEWS? 
There are a half-dozen that could easily be removed. (One would need to stay 
since it's part of a quotation.)




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#32252; Package emacs. (Tue, 24 Jul 2018 04:17:01 GMT) Full text and rfc822 format available.

Message #35 received at 32252 <at> debbugs.gnu.org (full text, mbox):

From: Drew Adams <drew.adams <at> oracle.com>
To: Paul Eggert <eggert <at> cs.ucla.edu>, 32252 <at> debbugs.gnu.org
Subject: RE: bug#32252: [PATCH] %o and %x now format signed numbers
Date: Mon, 23 Jul 2018 21:15:56 -0700 (PDT)
> > Put that motivation in NEWS.  Users deserve to be told why
> > things change incompatibly.
> 
> OK, here's a revised NEWS entry. It also mentions avoiding read/print
> misbehavior, a more-immediate prompt for this change that I forgot to
> mention
> previously.
> 
> ** Numbers formatted via %o or %x are now formatted as signed integers.
> Formerly they were formatted using machine-dependent two's complement
> representations.  The new behavior is machine-independent, avoids
> misbehavior in calls like (read (format "#x%x" -1)), and is more
> compatible with bignums, a planned feature.  To get the old behavior,
> set the new, experimental variable binary-as-unsigned to t and please
> email 32252 <at> debbugs.gnu.org if you need that.  Because %o and %x now
> format signed integers, they now support the + and space flags.
> (Bug#32252).

Thank you for providing the rationale.  A minor suggestion would
be to drop "new, experimental".  There's no way of knowing now
whether the variable will be only temporary/experimental, and
no reason to broadcast that supposition.  I'd also suggest that
you remove the part about emailing that bug thread.  Also, maybe
"space" should be `SPC' (dunno).

IMO it's good to let us know why the change was made.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#32252; Package emacs. (Tue, 24 Jul 2018 04:50:02 GMT) Full text and rfc822 format available.

Message #38 received at 32252 <at> debbugs.gnu.org (full text, mbox):

From: Helmut Eller <eller.helmut <at> gmail.com>
To: Paul Eggert <eggert <at> cs.ucla.edu>
Cc: 32252 <at> debbugs.gnu.org
Subject: Re: bug#32252: [PATCH] %o and %x now format signed numbers
Date: Tue, 24 Jul 2018 06:49:34 +0200
On Mon, Jul 23 2018, Paul Eggert wrote:

> %a has quite a different meaning in C11, so we'd need to use some

With your change %x will also have quite a different meaning in C11.

> other letter (or set of letters, if we want something for %x, %X, %o)
> if we went that route. This seems like overkill for such a small
> change to functionality that hardly ever matters; plus, %x, %X and %o
> would continue to have problematic machine-dependent semantics and
> would not be sensibly extensible to bignums.

If it doesn't matter to you then why make the change/break at all?  You
could just create a function bignum-to-hex-string.

Helmut




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#32252; Package emacs. (Tue, 24 Jul 2018 14:24:02 GMT) Full text and rfc822 format available.

Message #41 received at 32252 <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Helmut Eller <eller.helmut <at> gmail.com>
Cc: 32252 <at> debbugs.gnu.org
Subject: Re: bug#32252: [PATCH] %o and %x now format signed numbers
Date: Tue, 24 Jul 2018 07:22:52 -0700
Helmut Eller wrote:
> With your change %x will also have quite a different meaning in C11.

Not really, as Emacs (format "%x" N) agrees with C11 printf ("%x", N) in all 
values of N that are valid in both languages. In C11, negative values are not 
valid, as printf ("%x", N) has undefined behavior when N is negative. So we are 
discussing an area where Emacs Lisp can define behavior without introducing 
incompatibilities with C11.

If we changed (format "%x" -1) to signal an error instead, that would also be 
upward-compatible with C11. However, it's more useful for something like (format 
"#x%x" -1) to output a string that can 'read' can scan to get -1, something 
that's not true of Emacs now.

>> This seems like overkill for such a small
>> change to functionality that hardly ever matters; plus, %x, %X and %o
>> would continue to have problematic machine-dependent semantics and
>> would not be sensibly extensible to bignums.
> 
> If it doesn't matter to you then why make the change/break at all?

It does matter to me, actually. I think Emacs should have sensible behavior even 
in corner cases that hardly ever arise in real programs.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#32252; Package emacs. (Tue, 24 Jul 2018 14:30:02 GMT) Full text and rfc822 format available.

Message #44 received at 32252 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Paul Eggert <eggert <at> cs.ucla.edu>
Cc: 32252 <at> debbugs.gnu.org, drew.adams <at> oracle.com
Subject: Re: bug#32252: [PATCH] %o and %x now format signed numbers
Date: Tue, 24 Jul 2018 17:29:33 +0300
> Cc: drew.adams <at> oracle.com, 32252 <at> debbugs.gnu.org
> From: Paul Eggert <eggert <at> cs.ucla.edu>
> Date: Mon, 23 Jul 2018 19:44:33 -0700
> 
> Eli Zaretskii wrote:
> > Please don't put bug numbers in NEWS.  If some bug is important for
> > NEWS (I doubt that it ever could be), describe it instead.
> 
> Sorry, I didn't know that. Should I remove the existing bug numbers in NEWS? 

Yes, please, but if the details were left off the rest of the text
because the bug reference was supposed to serve instead, please now
add some minimal details to make the entry speak for itself.  (I can
do this myself, if you prefer that.)

Thanks.

P.S. I never said anything to this effect until now because I didn't
realize bug numbers are being added to NEWS in the absence of any
guidance to the contrary.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#32252; Package emacs. (Tue, 24 Jul 2018 14:36:01 GMT) Full text and rfc822 format available.

Message #47 received at 32252 <at> debbugs.gnu.org (full text, mbox):

From: Andreas Schwab <schwab <at> suse.de>
To: Paul Eggert <eggert <at> cs.ucla.edu>
Cc: 32252 <at> debbugs.gnu.org, Helmut Eller <eller.helmut <at> gmail.com>
Subject: Re: bug#32252: [PATCH] %o and %x now format signed numbers
Date: Tue, 24 Jul 2018 16:35:13 +0200
On Jul 24 2018, Paul Eggert <eggert <at> cs.ucla.edu> wrote:

> If we changed (format "%x" -1) to signal an error instead, that would also
> be upward-compatible with C11.

Unlike printf, format can convert arguments as needed, so an error is
wrong here.

Andreas.

-- 
Andreas Schwab, SUSE Labs, schwab <at> suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#32252; Package emacs. (Tue, 24 Jul 2018 16:28:02 GMT) Full text and rfc822 format available.

Message #50 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Andy Moreton <andrewjmoreton <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: Re: bug#32252: [PATCH] %o and %x now format signed numbers
Date: Tue, 24 Jul 2018 17:26:57 +0100
On Tue 24 Jul 2018, Paul Eggert wrote:

> Helmut Eller wrote:
>> With your change %x will also have quite a different meaning in C11.
>
> Not really, as Emacs (format "%x" N) agrees with C11 printf ("%x", N) in all
> values of N that are valid in both languages. In C11, negative values are not
> valid, as printf ("%x", N) has undefined behavior when N is negative. So we
> are discussing an area where Emacs Lisp can define behavior without
> introducing incompatibilities with C11.

As emacs fixnums are signed, and the C printf conversion specifier "%x"
takes an unsigned int argument, there are expected to be differences in
behaviour.

However what matters in C (and in elisp) is not what the spec says, but
what the codebase of existing users does, and what existing library
implementations do.

When printing values with base!=10, it is always the underlying
representation (i.e. bit pattern) that is of interest, not the value
interpreted as a signed number. Long standing practice in many languages
shows values printed in hex, octal and binary as unsigned.

> If we changed (format "%x" -1) to signal an error instead, that would also be
> upward-compatible with C11. However, it's more useful for something like
> (format "#x%x" -1) to output a string that can 'read' can scan to get -1,
> something that's not true of Emacs now.

I agree that there is a problem, but not with your solution.

I think it would be better to change the reader to treat non-base10
values as if they were unsigned representations, so that `format' is
unchanged, and (read (format "#x%x" -1)) evaluates to -1.

That is consistent wth other languages and user expectation.

> It does matter to me, actually. I think Emacs should have sensible behavior
> even in corner cases that hardly ever arise in real programs.

I agree: a consistent model of behaviour is important, even if it may
take a while to fix buggy behaviour that disagrees with the model.

    AndyM





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#32252; Package emacs. (Tue, 24 Jul 2018 18:17:01 GMT) Full text and rfc822 format available.

Message #53 received at 32252 <at> debbugs.gnu.org (full text, mbox):

From: Helmut Eller <eller.helmut <at> gmail.com>
To: Paul Eggert <eggert <at> cs.ucla.edu>
Cc: 32252 <at> debbugs.gnu.org
Subject: Re: bug#32252: [PATCH] %o and %x now format signed numbers
Date: Tue, 24 Jul 2018 20:15:57 +0200
On Tue, Jul 24 2018, Paul Eggert wrote:

>> With your change %x will also have quite a different meaning in C11.
>
> Not really, as Emacs (format "%x" N) agrees with C11 printf ("%x", N)
> in all values of N that are valid in both languages. In C11, negative
> values are not valid, as printf ("%x", N) has undefined behavior when
> N is negative. So we are discussing an area where Emacs Lisp can
> define behavior without introducing incompatibilities with C11.

In practice, printf ("%x", (int)N) prints the bits in N as unsigned
integer not as signed integer.

> If we changed (format "%x" -1) to signal an error instead, that would
> also be upward-compatible with C11. However, it's more useful for
> something like (format "#x%x" -1) to output a string that can 'read'
> can scan to get -1, something that's not true of Emacs now.

#x-1 maybe interesting to the read function but it's not interesting to
humans.  Humans want to see #x3fffffffffffffff.

>>> This seems like overkill for such a small
>>> change to functionality that hardly ever matters; plus, %x, %X and %o
>>> would continue to have problematic machine-dependent semantics and
>>> would not be sensibly extensible to bignums.
>>
>> If it doesn't matter to you then why make the change/break at all?
>
> It does matter to me, actually.

If it matters to you then you should have no problem with introducing an
new specifier for this.

> I think Emacs should have sensible behavior even in corner cases that
> hardly ever arise in real programs.

That %x prints the two's complement representation for negative fixnums
is fairly sensible behavior.  Emacs should not change such basic things
or for that matter start to print ’ instead of '.  Such changes would be
the opposite of sensible.

Helmut




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#32252; Package emacs. (Tue, 24 Jul 2018 18:28:01 GMT) Full text and rfc822 format available.

Message #56 received at 32252 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Helmut Eller <eller.helmut <at> gmail.com>
Cc: 32252 <at> debbugs.gnu.org, eggert <at> cs.ucla.edu
Subject: Re: bug#32252: [PATCH] %o and %x now format signed numbers
Date: Tue, 24 Jul 2018 21:27:45 +0300
> From: Helmut Eller <eller.helmut <at> gmail.com>
> Date: Tue, 24 Jul 2018 06:49:34 +0200
> Cc: 32252 <at> debbugs.gnu.org
> 
> On Mon, Jul 23 2018, Paul Eggert wrote:
> 
> > %a has quite a different meaning in C11, so we'd need to use some
> 
> With your change %x will also have quite a different meaning in C11.
> 
> > other letter (or set of letters, if we want something for %x, %X, %o)
> > if we went that route. This seems like overkill for such a small
> > change to functionality that hardly ever matters; plus, %x, %X and %o
> > would continue to have problematic machine-dependent semantics and
> > would not be sensibly extensible to bignums.
> 
> If it doesn't matter to you then why make the change/break at all?  You
> could just create a function bignum-to-hex-string.

Do we really need to have identical or consistent behavior for fixnums
and bignums?  They are different beasts, so the behavior could be
different, provided that it makes sense for each of the varieties.

More generally, given the controversy, maybe we should collect some
real-life experience before we start making incompatible behavior
changes?  I mean, the bignum branch is not even merged yet, and we are
already changing the behavior with fixnums in incompatible ways.
Maybe we should merge the branch first, let the dust settle and let
people use the new functionality, then revisit this stuff with more
experience on our hands.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#32252; Package emacs. (Wed, 25 Jul 2018 00:51:02 GMT) Full text and rfc822 format available.

Message #59 received at 32252 <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Helmut Eller <eller.helmut <at> gmail.com>
Cc: 32252 <at> debbugs.gnu.org
Subject: Re: bug#32252: [PATCH] %o and %x now format signed numbers
Date: Tue, 24 Jul 2018 17:50:46 -0700
Helmut Eller wrote:

> In practice, printf ("%x", (int)N) prints the bits in N as unsigned
> integer not as signed integer.

That's two operations not one, and even there the results disagree with what 
(format "%x" N) does. On every Emacs platform I've ever used the C output begins 
with a different hex digit than the Emacs Lisp output. Emacs has never done %x 
just like that unportable C code, and likely will never do so.

> #x-1 maybe interesting to the read function but it's not interesting to
> humans.  Humans want to see #x3fffffffffffffff.

I doubt very much that most humans really want to see an error-prone notation 
like that (can you easily spot the difference between it and 
#x3ffffffffffffffff? I can't). And even if some humans did want it, they won't 
get it on 32-bit Emacs. This whole idea is a bad approach for Emacs.

What I expect most users would prefer is an approach where 'read' and 'format' 
are inverses, e.g., (read (printf "#x%x" N)) returns N for every integer N. 
Emacs doesn't do that now, and the proposed patch fixes things so that it does. 
No other approach has been proposed that would make much sense (that is, be 
portable, be easily extendible to bignums, that sort of thing).

> you should have no problem with introducing an
> new specifier for this.

I'd rather not, as the hex stuff has never worked right in Emacs and we 
shouldn't be codifying old bugs.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#32252; Package emacs. (Wed, 25 Jul 2018 00:56:01 GMT) Full text and rfc822 format available.

Message #62 received at 32252 <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Eli Zaretskii <eliz <at> gnu.org>, Helmut Eller <eller.helmut <at> gmail.com>
Cc: 32252 <at> debbugs.gnu.org
Subject: Re: bug#32252: [PATCH] %o and %x now format signed numbers
Date: Tue, 24 Jul 2018 17:54:57 -0700
Eli Zaretskii wrote:

> Do we really need to have identical or consistent behavior for fixnums
> and bignums?  They are different beasts, so the behavior could be
> different, provided that it makes sense for each of the varieties.

I don't know what inconsistent behavior would make sense here. There's a 
longstanding tradition in Lisp that integer arithmetic just works, and I don't 
see why Emacs would want to fight against that tradition here. Although there 
may be some low-level functions that distinguish between fixnums and bignums for 
efficiency reasons, the vast majority of Lisp functions should not distinguish 
them, and 'format' should be one of those functions.
> Maybe we should merge the branch first, let the dust settle and let
> people use the new functionality, then revisit this stuff with more
> experience on our hands.

This particular patch is not primarily about bignums. It's more about (read 
(printf "#x%x" N)) returning N, which is basic functionality that should work 
even if we never add bignums. The fact that the patch also will make bignums 
easier is just icing on the cake.

Although I understand the concern about the patch, the concern doesn't seem to 
be warranted, and any compatibility issues can easily be addressed by setting 
binary-as-signed.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#32252; Package emacs. (Wed, 25 Jul 2018 03:54:01 GMT) Full text and rfc822 format available.

Message #65 received at 32252 <at> debbugs.gnu.org (full text, mbox):

From: Richard Stallman <rms <at> gnu.org>
To: Drew Adams <drew.adams <at> oracle.com>
Cc: 32252 <at> debbugs.gnu.org, eggert <at> cs.ucla.edu, eller.helmut <at> gmail.com
Subject: Re: bug#32252: [PATCH] %o and %x now format signed numbers
Date: Tue, 24 Jul 2018 23:53:26 -0400
[[[ To any NSA and FBI agents reading my email: please consider    ]]]
[[[ whether defending the US Constitution against all enemies,     ]]]
[[[ foreign or domestic, requires you to follow Snowden's example. ]]]

  > > Although it is indeed an incompatible change, I surveyed the existing
  > > Emacs source code and couldn't find anything that the change would
  > > break.

  > Inadequate.  Never wholly irrelevant, but certainly not
  > sufficient.  You surveyed something mostly irrelevant.

How about saying "incomplete"?  It states the valid point
but is far less harsh.

-- 
Dr Richard Stallman
President, Free Software Foundation (https://gnu.org, https://fsf.org)
Internet Hall-of-Famer (https://internethalloffame.org)






Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#32252; Package emacs. (Wed, 25 Jul 2018 04:37:02 GMT) Full text and rfc822 format available.

Message #68 received at 32252 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Paul Eggert <eggert <at> cs.ucla.edu>
Cc: 32252 <at> debbugs.gnu.org, eller.helmut <at> gmail.com
Subject: Re: bug#32252: [PATCH] %o and %x now format signed numbers
Date: Wed, 25 Jul 2018 05:41:38 +0300
> From: Paul Eggert <eggert <at> cs.ucla.edu>
> Date: Tue, 24 Jul 2018 17:50:46 -0700
> Cc: 32252 <at> debbugs.gnu.org
> 
> > #x-1 maybe interesting to the read function but it's not interesting to
> > humans.  Humans want to see #x3fffffffffffffff.
> 
> I doubt very much that most humans really want to see an error-prone notation 
> like that (can you easily spot the difference between it and 
> #x3ffffffffffffffff? I can't).

I don't know if "most" is accurate, but I'm definitely in that camp.

As for counting the number of 'f's, how is that different from
counting leading zeros?

> And even if some humans did want it, they won't get it on 32-bit
> Emacs.

I don't see any problem: the user always knows in what Emacs she is
running.

> This whole idea is a bad approach for Emacs.

This bad approach was with us since about forever.  It is a de-facto
correct behavior by now




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#32252; Package emacs. (Wed, 25 Jul 2018 06:59:02 GMT) Full text and rfc822 format available.

Message #71 received at 32252 <at> debbugs.gnu.org (full text, mbox):

From: Helmut Eller <eller.helmut <at> gmail.com>
To: Paul Eggert <eggert <at> cs.ucla.edu>
Cc: 32252 <at> debbugs.gnu.org
Subject: Re: bug#32252: [PATCH] %o and %x now format signed numbers
Date: Wed, 25 Jul 2018 08:58:25 +0200
On Tue, Jul 24 2018, Paul Eggert wrote:

> Helmut Eller wrote:
>
>> In practice, printf ("%x", (int)N) prints the bits in N as unsigned
>> integer not as signed integer.
>
> That's two operations not one, and even there the results disagree
> with what (format "%x" N) does. On every Emacs platform I've ever used
> the C output begins with a different hex digit than the Emacs Lisp
> output. Emacs has never done %x just like that unportable C code, and
> likely will never do so.

Nobody is arguing for printing the tag-bits.  And what Emacs has done is
fairly obvious to everybody.

>> #x-1 maybe interesting to the read function but it's not interesting to
>> humans.  Humans want to see #x3fffffffffffffff.
>
> I doubt very much that most humans really want to see an error-prone
> notation like that (can you easily spot the difference between it and
> #x3ffffffffffffffff? I can't). And even if some humans did want it,
> they won't get it on 32-bit Emacs. This whole idea is a bad approach
> for Emacs.

What's more interesting:
(format "%x" (lognot 8)) => "-9"
or
(format "%x" (lognot 8)) => "3ffffffffffffff7"

For me, the first version is totally useless.

> What I expect most users would prefer is an approach where 'read' and
> 'format' are inverses, e.g., (read (printf "#x%x" N)) returns N for
> every integer N. Emacs doesn't do that now, and the proposed patch
> fixes things so that it does.

The inverse of read is print, not format or printf. 

> No other approach has been proposed that
> would make much sense (that is, be portable, be easily extendible to
> bignums, that sort of thing).

Of course there have been proposals: Do your bignum stuff with a
different format specifier.

Here is another proposal: Add a read syntax for unsigned fixnums like
#x3fffffffffffffffu or alternatively #xu3fffffffffffffff.

>> you should have no problem with introducing an
>> new specifier for this.
>
> I'd rather not, as the hex stuff has never worked right in Emacs and
> we shouldn't be codifying old bugs.

It was already codified in the documentation, even the much more dubios
flonum case.  It's really annoying when documented behavior changes.

Helmut




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#32252; Package emacs. (Wed, 25 Jul 2018 08:10:02 GMT) Full text and rfc822 format available.

Message #74 received at 32252 <at> debbugs.gnu.org (full text, mbox):

From: Andreas Schwab <schwab <at> suse.de>
To: Paul Eggert <eggert <at> cs.ucla.edu>
Cc: 32252 <at> debbugs.gnu.org, Eli Zaretskii <eliz <at> gnu.org>,
 Helmut Eller <eller.helmut <at> gmail.com>
Subject: Re: bug#32252: [PATCH] %o and %x now format signed numbers
Date: Wed, 25 Jul 2018 10:09:14 +0200
On Jul 24 2018, Paul Eggert <eggert <at> cs.ucla.edu> wrote:

> It's more about (read (printf "#x%x" N)) returning N, which is basic
> functionality that should work

Where is that documented?

Andreas.

-- 
Andreas Schwab, SUSE Labs, schwab <at> suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#32252; Package emacs. (Wed, 25 Jul 2018 10:09:02 GMT) Full text and rfc822 format available.

Message #77 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Andy Moreton <andrewjmoreton <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: Re: bug#32252: [PATCH] %o and %x now format signed numbers
Date: Wed, 25 Jul 2018 11:08:06 +0100
On Tue 24 Jul 2018, Paul Eggert wrote:

> Eli Zaretskii wrote:
>
>> Do we really need to have identical or consistent behavior for fixnums
>> and bignums?  They are different beasts, so the behavior could be
>> different, provided that it makes sense for each of the varieties.
>
> I don't know what inconsistent behavior would make sense here. There's a
> longstanding tradition in Lisp that integer arithmetic just works, and I don't
> see why Emacs would want to fight against that tradition here. Although there
> may be some low-level functions that distinguish between fixnums and bignums
> for efficiency reasons, the vast majority of Lisp functions should not
> distinguish them, and 'format' should be one of those functions.
>> Maybe we should merge the branch first, let the dust settle and let
>> people use the new functionality, then revisit this stuff with more
>> experience on our hands.
>
> This particular patch is not primarily about bignums. It's more about (read
> (printf "#x%x" N)) returning N, which is basic functionality that should work
> even if we never add bignums. The fact that the patch also will make bignums
> easier is just icing on the cake.

It makes things more consistent at a cost of incomatibility with long
standing behaviour, and of making (format "%x") output useless for
humans to read. That is far too high a price for consistency.

> Although I understand the concern about the patch, the concern doesn't seem to
> be warranted, and any compatibility issues can easily be addressed by setting
> binary-as-signed.

No. The default value for this option should preserve backward
compatible behaviour.

    AndyM





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#32252; Package emacs. (Wed, 25 Jul 2018 14:18:01 GMT) Full text and rfc822 format available.

Message #80 received at 32252 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Paul Eggert <eggert <at> cs.ucla.edu>
Cc: 32252 <at> debbugs.gnu.org, eller.helmut <at> gmail.com
Subject: Re: bug#32252: [PATCH] %o and %x now format signed numbers
Date: Wed, 25 Jul 2018 17:17:26 +0300
> Cc: 32252 <at> debbugs.gnu.org
> From: Paul Eggert <eggert <at> cs.ucla.edu>
> Date: Tue, 24 Jul 2018 17:54:57 -0700
> 
> Eli Zaretskii wrote:
> 
> > Do we really need to have identical or consistent behavior for fixnums
> > and bignums?  They are different beasts, so the behavior could be
> > different, provided that it makes sense for each of the varieties.
> 
> I don't know what inconsistent behavior would make sense here. There's a 
> longstanding tradition in Lisp that integer arithmetic just works, and I don't 
> see why Emacs would want to fight against that tradition here. Although there 
> may be some low-level functions that distinguish between fixnums and bignums for 
> efficiency reasons, the vast majority of Lisp functions should not distinguish 
> them, and 'format' should be one of those functions.

I agree that this would be nice to have, but I'm not sure we should
absolutely require that, at least not yet.  Not before we have enough
experience to be sure we have good reasons for changing long-standing
behavior.

> Although I understand the concern about the patch, the concern doesn't seem to 
> be warranted, and any compatibility issues can easily be addressed by setting 
> binary-as-signed.

Well, we've seen such movies in the past, and we know we've been wrong
in at least some cases.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#32252; Package emacs. (Wed, 25 Jul 2018 17:22:01 GMT) Full text and rfc822 format available.

Message #83 received at 32252 <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 32252 <at> debbugs.gnu.org, eller.helmut <at> gmail.com
Subject: Re: bug#32252: [PATCH] %o and %x now format signed numbers
Date: Wed, 25 Jul 2018 10:21:43 -0700
On 07/24/2018 07:41 PM, Eli Zaretskii wrote:
> As for counting the number of 'f's, how is that different from
> counting leading zeros?

The 'f's contribute to the value, the leading zeros do not.  For 
example, in Emacs 26 #x3fffffffffffffff is 2**62 (since it is rounded to 
a floating point number) whereas the visually-similar number 
#x3ffffffffffffff is (2**58 - 1). Although the rounding error should go 
away once we have bignums, the notational problems will become worse if 
%x and %o continue to print in a machine-dependent way.

That being said, it appears that there are enough qualms about the 
change that I plan to install it with the new variable set the other 
way. I.e., the default will be the current behavior and people can set 
the new variable to get the new behavior, to try it this behavior out to 
see whether they have problems.





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#32252; Package emacs. (Wed, 25 Jul 2018 17:29:03 GMT) Full text and rfc822 format available.

Message #86 received at 32252 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Paul Eggert <eggert <at> cs.ucla.edu>
Cc: 32252 <at> debbugs.gnu.org, eller.helmut <at> gmail.com
Subject: Re: bug#32252: [PATCH] %o and %x now format signed numbers
Date: Wed, 25 Jul 2018 20:28:08 +0300
> Cc: eller.helmut <at> gmail.com, 32252 <at> debbugs.gnu.org
> From: Paul Eggert <eggert <at> cs.ucla.edu>
> Date: Wed, 25 Jul 2018 10:21:43 -0700
> 
> That being said, it appears that there are enough qualms about the 
> change that I plan to install it with the new variable set the other 
> way. I.e., the default will be the current behavior and people can set 
> the new variable to get the new behavior, to try it this behavior out to 
> see whether they have problems.

Thank you.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#32252; Package emacs. (Wed, 25 Jul 2018 20:17:01 GMT) Full text and rfc822 format available.

Message #89 received at 32252 <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Andreas Schwab <schwab <at> suse.de>
Cc: 32252 <at> debbugs.gnu.org, Eli Zaretskii <eliz <at> gnu.org>,
 Helmut Eller <eller.helmut <at> gmail.com>
Subject: Re: bug#32252: [PATCH] %o and %x now format signed numbers
Date: Wed, 25 Jul 2018 13:16:27 -0700
Andreas Schwab wrote:
>> It's more about (read (printf "#x%x" N)) returning N, which is basic
>> functionality that should work
> Where is that documented?

You're right, it's not. It's not even documented that (read (printf "%s" N)) 
should work for any number N. I'll add something along these lines. I'll also 
warn that (read (printf "#x%x" N)) might not work.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#32252; Package emacs. (Wed, 25 Jul 2018 21:57:01 GMT) Full text and rfc822 format available.

Message #92 received at 32252 <at> debbugs.gnu.org (full text, mbox):

From: Drew Adams <drew.adams <at> oracle.com>
To: rms <at> gnu.org
Cc: 32252 <at> debbugs.gnu.org, eggert <at> cs.ucla.edu, eller.helmut <at> gmail.com
Subject: RE: bug#32252: [PATCH] %o and %x now format signed numbers
Date: Wed, 25 Jul 2018 14:56:04 -0700 (PDT)
>   > > Although it is indeed an incompatible change, I surveyed the existing
>   > > Emacs source code and couldn't find anything that the change would
>   > > break.
> 
>   > Inadequate.  Never wholly irrelevant, but certainly not
>   > sufficient.  You surveyed something mostly irrelevant.
> 
> How about saying "incomplete"?  It states the valid point but is far less harsh.

Incomplete, of course; thank you.

But also inadequate, IMO - or insufficient, if you prefer - perhaps that is less harsh than inadequate.

The intention was not to be harsh but to say that, while it is good to check the sources distributed with Emacs, it is not good enough.

"Incomplete" tells part of the story, but it doesn't imply that there is a problem. (Unless there is agreement on a completeness requirement -  I wasn't assuming such agreement.)

Saying it's not sufficient to just check the Emacs sources says both that doing so is incomplete _and_ that such an incomplete search is not enough.

But you're no doubt right that there is likely more agreement that such a search is incomplete than there is that it's also not enough.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#32252; Package emacs. (Wed, 25 Jul 2018 23:48:02 GMT) Full text and rfc822 format available.

Message #95 received at 32252 <at> debbugs.gnu.org (full text, mbox):

From: Brett Gilio <brettg <at> posteo.net>
To: Paul Eggert <eggert <at> cs.ucla.edu>
Cc: 32252 <at> debbugs.gnu.org, Eli Zaretskii <eliz <at> gnu.org>,
 Helmut Eller <eller.helmut <at> gmail.com>
Subject: Re: bug#32252: [PATCH] %o and %x now format signed numbers
Date: Wed, 25 Jul 2018 18:33:34 -0500
Paul Eggert writes:
> I don't know what inconsistent behavior would make sense here. 
> There's a
> longstanding tradition in Lisp that integer arithmetic just 
> works, and I don't
> see why Emacs would want to fight against that tradition here. 
> Although there
> may be some low-level functions that distinguish between fixnums 
> and bignums for
> efficiency reasons, the vast majority of Lisp functions should 
> not distinguish
> them, and 'format' should be one of those functions.
>> Maybe we should merge the branch first, let the dust settle and 
>> let
>> people use the new functionality, then revisit this stuff with 
>> more
>> experience on our hands.

Paul, I agree with you here. However, I wonder what you mean by 
"just
works" in contrast to what Eli suggested about the inconsistency 
in
behavior between the different function definitions for fixnums 
and
bignums.

How would that be working against the lisp tradition?



-- 
Brett M. Gilio
Free Software Foundation, Member
https://parabola.nu | https://emacs.org




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#32252; Package emacs. (Thu, 26 Jul 2018 07:27:02 GMT) Full text and rfc822 format available.

Message #98 received at 32252 <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Brett Gilio <brettg <at> posteo.net>
Cc: 32252 <at> debbugs.gnu.org, Eli Zaretskii <eliz <at> gnu.org>,
 Helmut Eller <eller.helmut <at> gmail.com>
Subject: Re: bug#32252: [PATCH] %o and %x now format signed numbers
Date: Thu, 26 Jul 2018 00:26:43 -0700
Brett Gilio wrote:
> I wonder what you mean by "just
> works" in contrast to what Eli suggested about the inconsistency in
> behavior between the different function definitions for fixnums and
> bignums.

I meant that ordinarily Emacs Lisp programmers should not worry whether an 
integer's internal representation is a bignum or a fixnum. Functions like +, -, 
*, /,  format, read, etc. should accept and generate mathematically correct 
integer values regardless of whether their inputs are fixnums or bignums. If an 
integer fits in a fixnum it is presumably represented that way, but by and large 
Emacs programs should not care about this detail.

That is how other Lisps do it, it works well for them, and Emacs Lisp should do 
likewise.




Reply sent to Paul Eggert <eggert <at> cs.ucla.edu>:
You have taken responsibility. (Thu, 26 Jul 2018 07:45:01 GMT) Full text and rfc822 format available.

Notification sent to Paul Eggert <eggert <at> cs.ucla.edu>:
bug acknowledged by developer. (Thu, 26 Jul 2018 07:45:02 GMT) Full text and rfc822 format available.

Message #103 received at 32252-done <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 32252-done <at> debbugs.gnu.org, eller.helmut <at> gmail.com
Subject: Re: bug#32252: [PATCH] %o and %x now format signed numbers
Date: Thu, 26 Jul 2018 00:44:34 -0700
[Message part 1 (text/plain, inline)]
Eli Zaretskii wrote:
>> Cc: eller.helmut <at> gmail.com, 32252 <at> debbugs.gnu.org
>> From: Paul Eggert <eggert <at> cs.ucla.edu>
>>
>> That being said, it appears that there are enough qualms about the
>> change that I plan to install it with the new variable set the other
>> way. I.e., the default will be the current behavior and people can set
>> the new variable to get the new behavior, to try it this behavior out to
>> see whether they have problems.
> 
> Thank you.

OK, I installed the attached patch which does that, and am closing the bug 
report. I plan to run with binary-as-unsigned set to nil and to report any 
problems I encounter. I encourage others (particularly skeptics :-) to do the same.
[0001-o-and-x-can-now-format-signed-integers.txt (text/plain, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#32252; Package emacs. (Thu, 26 Jul 2018 08:01:02 GMT) Full text and rfc822 format available.

Message #106 received at 32252 <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Helmut Eller <eller.helmut <at> gmail.com>
Cc: 32252 <at> debbugs.gnu.org
Subject: Re: bug#32252: [PATCH] %o and %x now format signed numbers
Date: Thu, 26 Jul 2018 00:59:56 -0700
Helmut Eller wrote:

> What's more interesting:
> (format "%x" (lognot 8)) => "-9"
> or
> (format "%x" (lognot 8)) => "3ffffffffffffff7"
> 
> For me, the first version is totally useless.

Shrug. It's what Common Lisp and Scheme do, and it works pretty well once you 
get used to it. Programs that need negative integers displayed modulo some power 
of 2 can use the mod or logand functions; that's the mathematically right way to 
do it anyway, and it's machine-independent.

> Of course there have been proposals: Do your bignum stuff with a
> different format specifier.

And prohibit %x on bignums? That would make little sense. Common Lisp and Scheme 
don't have any such prohibition; why should Emacs Lisp? Again, programs that 
need just the low-order bits of a negative integer can use 'mod' or a mask.

> Here is another proposal: Add a read syntax for unsigned fixnums like
> #x3fffffffffffffffu or alternatively #xu3fffffffffffffff.

That's heading down the wrong path. Emacs Lisp does not have unsigned fixnums, 
so why add a syntax for a data type that does not exist? And Emacs Lisp should 
not add such a data type, as it is a low-level machine concept unsuitable for 
Lisp, is not needed in Emacs Lisp, and would cause unnecessary complexity in 
documentation and implementation.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#32252; Package emacs. (Thu, 26 Jul 2018 08:05:02 GMT) Full text and rfc822 format available.

Message #109 received at 32252-done <at> debbugs.gnu.org (full text, mbox):

From: Helmut Eller <eller.helmut <at> gmail.com>
To: Paul Eggert <eggert <at> cs.ucla.edu>
Cc: 32252-done <at> debbugs.gnu.org
Subject: Re: bug#32252: [PATCH] %o and %x now format signed numbers
Date: Thu, 26 Jul 2018 10:04:28 +0200
> OK, I installed the attached patch which does that, and am closing the
> bug report. I plan to run with binary-as-unsigned set to nil and to
> report any problems I encounter. I encourage others (particularly
> skeptics :-) to do the same.

So you actually changed the default behavior even if you said you
wouldn't?

Helmut




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#32252; Package emacs. (Thu, 26 Jul 2018 08:17:02 GMT) Full text and rfc822 format available.

Message #112 received at 32252-done <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Helmut Eller <eller.helmut <at> gmail.com>
Cc: 32252-done <at> debbugs.gnu.org
Subject: Re: bug#32252: [PATCH] %o and %x now format signed numbers
Date: Thu, 26 Jul 2018 01:16:02 -0700
[Message part 1 (text/plain, inline)]
Helmut Eller wrote:
> So you actually changed the default behavior even if you said you
> wouldn't?

That was not my intent. Sorry, I messed up the default settings in a last-minute 
change. Thanks for catching that so quickly. I installed the attached to fix it.
[0001-src-editfns.c-syms_of_editfns-Fix-typo-in-previous-c.patch (text/x-patch, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#32252; Package emacs. (Thu, 26 Jul 2018 08:44:02 GMT) Full text and rfc822 format available.

Message #115 received at 32252 <at> debbugs.gnu.org (full text, mbox):

From: Helmut Eller <eller.helmut <at> gmail.com>
To: Paul Eggert <eggert <at> cs.ucla.edu>
Cc: 32252 <at> debbugs.gnu.org
Subject: Re: bug#32252: [PATCH] %o and %x now format signed numbers
Date: Thu, 26 Jul 2018 10:43:52 +0200
On Thu, Jul 26 2018, Paul Eggert wrote:

> Helmut Eller wrote:
>
>> What's more interesting:
>> (format "%x" (lognot 8)) => "-9"
>> or
>> (format "%x" (lognot 8)) => "3ffffffffffffff7"
>>
>> For me, the first version is totally useless.
>
> Shrug. It's what Common Lisp and Scheme do, and it works pretty well
> once you get used to it.

It's because I happen to know a thing or two about Common Lisp that I
know that I almost always would prefer the way that Emacs Lisp prints
negative fixnums.

> Programs that need negative integers
> displayed modulo some power of 2 can use the mod or logand functions;
> that's the mathematically right way to do it anyway, and it's
> machine-independent.

Do you think I don't know that?  It's always possible to write a helper
function that does the formatting in the variant that you need.

>> Of course there have been proposals: Do your bignum stuff with a
>> different format specifier.
>
> And prohibit %x on bignums? That would make little sense.

It would prohibit only negative bignums just like negative flonums are
forbidden.  Besides I still think that it would make much more sense to
print flonums the way %a does in C; another reason for having %a or
another format specifier to do the hex conversion in a world with
bignums.

> Common Lisp and Scheme don't have any such prohibition; why should
> Emacs Lisp?

Because Emacs Lisp was very successful without bignums.  Even more
successful than most other Lisps with all their fancy bignums, complex
numbers, ratios and other numeric stuff that hardly anyone needs.  And
the stuff that almost everybody would like to have like, fast unboxed
arithmetic, is not offered in a reliable and portable way.

>> Here is another proposal: Add a read syntax for unsigned fixnums like
>> #x3fffffffffffffffu or alternatively #xu3fffffffffffffff.
>
> That's heading down the wrong path. Emacs Lisp does not have unsigned
> fixnums, so why add a syntax for a data type that does not exist?  And
> Emacs Lisp should not add such a data type, as it is a low-level
> machine concept unsuitable for Lisp, is not needed in Emacs Lisp, and
> would cause unnecessary complexity in documentation and
> implementation.

In my mind Emacs does have negative fixnums and there are various ways
to write negative fixnums.  Of course a special syntax is not absolutely
needed but it may be convenient.

Helmut




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#32252; Package emacs. (Thu, 26 Jul 2018 09:17:01 GMT) Full text and rfc822 format available.

Message #118 received at 32252 <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Helmut Eller <eller.helmut <at> gmail.com>
Cc: 32252 <at> debbugs.gnu.org
Subject: Re: bug#32252: [PATCH] %o and %x now format signed numbers
Date: Thu, 26 Jul 2018 02:15:52 -0700
Helmut Eller wrote:
>> And prohibit %x on bignums? That would make little sense.
> It would prohibit only negative bignums just like negative flonums are
> forbidden.

So under this proposal %x would generate ambiguous output once we add bignums? 
For example, on a 32-bit platform (format "%x" -1) would generate the same 
output as (format "%x" #x3fffffff), even though -1 and #x3fffffff would be 
different integers? That doesn't sound like a good idea.

> it would make much more sense to print flonums the way %a does in C

It would make sense to add an %a specification, like C's %a. But C's %a formats 
floating-point numbers, and surely Emacs Lisp's %a should be similar. That is, 
%a should treat integers the way the other floating-point specs do (%e, %f, %g).

>> Common Lisp and Scheme don't have any such prohibition; why should
>> Emacs Lisp?
> 
> Because Emacs Lisp was very successful without bignums.

This appears to be more an argument against bignums than anything else. I've 
used Emacs Lisp without bignums for many years, and it's *always* been a 
hindrance. I would much rather have bignums, as they would make a lot of things 
simpler. I agree that Emacs Lisp does not much need complex numbers or ratios.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#32252; Package emacs. (Thu, 26 Jul 2018 09:32:01 GMT) Full text and rfc822 format available.

Message #121 received at 32252 <at> debbugs.gnu.org (full text, mbox):

From: Andreas Schwab <schwab <at> suse.de>
To: Helmut Eller <eller.helmut <at> gmail.com>
Cc: 32252 <at> debbugs.gnu.org, Paul Eggert <eggert <at> cs.ucla.edu>
Subject: Re: bug#32252: [PATCH] %o and %x now format signed numbers
Date: Thu, 26 Jul 2018 11:31:13 +0200
On Jul 26 2018, Helmut Eller <eller.helmut <at> gmail.com> wrote:

> Because Emacs Lisp was very successful without bignums.

The lack of bignums requires workarounds like the first two elements of
(current-time) or the 11th and 12th element of (file-attributes).

Andreas.

-- 
Andreas Schwab, SUSE Labs, schwab <at> suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#32252; Package emacs. (Thu, 26 Jul 2018 09:40:02 GMT) Full text and rfc822 format available.

Message #124 received at 32252 <at> debbugs.gnu.org (full text, mbox):

From: Helmut Eller <eller.helmut <at> gmail.com>
To: Paul Eggert <eggert <at> cs.ucla.edu>
Cc: 32252 <at> debbugs.gnu.org
Subject: Re: bug#32252: [PATCH] %o and %x now format signed numbers
Date: Thu, 26 Jul 2018 11:39:47 +0200
On Thu, Jul 26 2018, Paul Eggert wrote:

> Helmut Eller wrote:
>>> And prohibit %x on bignums? That would make little sense.
>> It would prohibit only negative bignums just like negative flonums are
>> forbidden.
>
> So under this proposal %x would generate ambiguous output once we add
> bignums? For example, on a 32-bit platform (format "%x" -1) would
> generate the same output as (format "%x" #x3fffffff), even though -1
> and #x3fffffff would be different integers? That doesn't sound like a
> good idea.

Indeed, had forgotten that case.

>>> Common Lisp and Scheme don't have any such prohibition; why should
>>> Emacs Lisp?
>>
>> Because Emacs Lisp was very successful without bignums.
>
> This appears to be more an argument against bignums than anything
> else. I've used Emacs Lisp without bignums for many years, and it's
> *always* been a hindrance. I would much rather have bignums, as they
> would make a lot of things simpler.

Well, it's an argument to promote the special role of fixnums.

Helmut




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#32252; Package emacs. (Thu, 26 Jul 2018 09:41:02 GMT) Full text and rfc822 format available.

Message #127 received at 32252 <at> debbugs.gnu.org (full text, mbox):

From: Robert Pluim <rpluim <at> gmail.com>
To: Andreas Schwab <schwab <at> suse.de>
Cc: 32252 <at> debbugs.gnu.org, Paul Eggert <eggert <at> cs.ucla.edu>,
 Helmut Eller <eller.helmut <at> gmail.com>
Subject: Re: bug#32252: [PATCH] %o and %x now format signed numbers
Date: Thu, 26 Jul 2018 11:40:33 +0200
Andreas Schwab <schwab <at> suse.de> writes:

> On Jul 26 2018, Helmut Eller <eller.helmut <at> gmail.com> wrote:
>
>> Because Emacs Lisp was very successful without bignums.
>
> The lack of bignums requires workarounds like the first two elements of
> (current-time) or the 11th and 12th element of (file-attributes).

Not to mention having to represent IP addresses as vectors, thus
forcing operations on them to be byte by byte.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#32252; Package emacs. (Thu, 26 Jul 2018 09:57:02 GMT) Full text and rfc822 format available.

Message #130 received at 32252 <at> debbugs.gnu.org (full text, mbox):

From: Helmut Eller <eller.helmut <at> gmail.com>
To: Andreas Schwab <schwab <at> suse.de>
Cc: 32252 <at> debbugs.gnu.org, Paul Eggert <eggert <at> cs.ucla.edu>
Subject: Re: bug#32252: [PATCH] %o and %x now format signed numbers
Date: Thu, 26 Jul 2018 11:56:13 +0200
On Thu, Jul 26 2018, Andreas Schwab wrote:

> On Jul 26 2018, Helmut Eller <eller.helmut <at> gmail.com> wrote:
>
>> Because Emacs Lisp was very successful without bignums.
>
> The lack of bignums requires workarounds like the first two elements of
> (current-time) or the 11th and 12th element of (file-attributes).

Yes, that's one of the few places where bignums would be useful. But
having a time data-type, maybe just a struct and functions like time-add
etc, would also be good solution.  How often does one need to print a
time value in hex notation?  Probably so rareley that format-time-string
doesn't even support that.

Helmut




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#32252; Package emacs. (Thu, 26 Jul 2018 12:53:02 GMT) Full text and rfc822 format available.

Message #133 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Andy Moreton <andrewjmoreton <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: Re: bug#32252: [PATCH] %o and %x now format signed numbers
Date: Thu, 26 Jul 2018 13:52:27 +0100
On Wed 25 Jul 2018, Paul Eggert wrote:

> Andreas Schwab wrote:
>>> It's more about (read (printf "#x%x" N)) returning N, which is basic
>>> functionality that should work
>> Where is that documented?
>
> You're right, it's not. It's not even documented that (read (printf "%s" N))
> should work for any number N. I'll add something along these lines. I'll also
> warn that (read (printf "#x%x" N)) might not work.

I think you meant (read (format "%s" N)).

    AndyM





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#32252; Package emacs. (Thu, 26 Jul 2018 12:58:03 GMT) Full text and rfc822 format available.

Message #136 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Andy Moreton <andrewjmoreton <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: Re: bug#32252: [PATCH] %o and %x now format signed numbers
Date: Thu, 26 Jul 2018 13:54:21 +0100
On Thu 26 Jul 2018, Paul Eggert wrote:

> Brett Gilio wrote:
>> I wonder what you mean by "just
>> works" in contrast to what Eli suggested about the inconsistency in
>> behavior between the different function definitions for fixnums and
>> bignums.
>
> I meant that ordinarily Emacs Lisp programmers should not worry whether an
> integer's internal representation is a bignum or a fixnum. Functions like +,
> -, 
> *, /,  format, read, etc. should accept and generate mathematically correct
> integer values regardless of whether their inputs are fixnums or bignums. If
> an integer fits in a fixnum it is presumably represented that way, but by and
> large Emacs programs should not care about this detail.
>
> That is how other Lisps do it, it works well for them, and Emacs Lisp should
> do likewise.

That is uncontroversial for arithmetic operations, but how are bitwise
logical operations handled in other lisps with bignums ?

    AndyM





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#32252; Package emacs. (Thu, 26 Jul 2018 16:57:02 GMT) Full text and rfc822 format available.

Message #139 received at 32252 <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Helmut Eller <eller.helmut <at> gmail.com>, Andreas Schwab <schwab <at> suse.de>
Cc: 32252 <at> debbugs.gnu.org
Subject: Re: bug#32252: [PATCH] %o and %x now format signed numbers
Date: Thu, 26 Jul 2018 09:55:53 -0700
On 07/26/2018 02:56 AM, Helmut Eller wrote:
> How often does one need to print a
> time value in hex notation?

It happens every time I run Emacs, in standard code shipped with Emacs. 
I discovered this while doing compatibility checking before I proposed 
this change. (The code in question continues to work just fine when 
binary-as-unsigned is nil.)


> format-time-string doesn't even support that.

We're talking about 'format' not 'format-time-string', and Emacs code 
does apply 'format' with %x to the tricky little integers that 
'current-time' returns. It's a real hassle, and this hassle is pervasive 
in Emacs. Having bignums would simplify it significantly.

And this problem is not limited to times. It's also file sizes, buffer 
and string sizes (currently limited to fixnums, but they shouldn't be), 
glyph codes, inode numbers, device numbers, file descriptor numbers, 
inotify masks, windowing parameters, and other stuff I don't even know 
about. It's pervasive and is a real hassle.

By the way, the format %x compatibility checking I mentioned is partly 
why I have confidence that the practical effects of this change will be 
minor. Many of the problems that I thought might happen, don't in fact 
happen, because people who attempt to format negative numbers with %x 
have already run into portability hassles on 32- vs 64-bit platforms, 
and so they have written their code so that the platform choice doesn't 
matter, either by ensuring that the integer is nonnegative or by not 
caring what string is generated so long as it doesn't lose information. 
Code written like this (and so far, that's all the code I've found) 
works just fine when 'format'  %x works like it does in Common Lisp or 
Scheme.





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#32252; Package emacs. (Thu, 26 Jul 2018 17:17:02 GMT) Full text and rfc822 format available.

Message #142 received at 32252 <at> debbugs.gnu.org (full text, mbox):

From: Helmut Eller <eller.helmut <at> gmail.com>
To: Paul Eggert <eggert <at> cs.ucla.edu>
Cc: Andreas Schwab <schwab <at> suse.de>, 32252 <at> debbugs.gnu.org
Subject: Re: bug#32252: [PATCH] %o and %x now format signed numbers
Date: Thu, 26 Jul 2018 19:16:02 +0200
On Thu, Jul 26 2018, Paul Eggert wrote:

> We're talking about 'format' not 'format-time-string', and Emacs code
> does apply 'format' with %x to the tricky little integers that
> 'current-time' returns. It's a real hassle, and this hassle is
> pervasive in Emacs. Having bignums would simplify it significantly.

Where is that code?  And why would it be difficult to teach
format-time-string to deal with the tricky bits that current-time
returns.

Helmut




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#32252; Package emacs. (Thu, 26 Jul 2018 17:20:01 GMT) Full text and rfc822 format available.

Message #145 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Helmut Eller <eller.helmut <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: Re: bug#32252: [PATCH] %o and %x now format signed numbers
Date: Thu, 26 Jul 2018 19:18:48 +0200
On Thu, Jul 26 2018, Andy Moreton wrote:

>> That is how other Lisps do it, it works well for them, and Emacs Lisp should
>> do likewise.
>
> That is uncontroversial for arithmetic operations, but how are bitwise
> logical operations handled in other lisps with bignums ?

In Common Lisp those are defined to behave as if integers were
represented in two's complement form, regardless of how integers are
represented internally.

Interestinlgy, Common Lisp has ASH but no direct equivalent to Emacs
Lisp's lsh.  Let's see how the bignum proponents extend lsh.

Helmut





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#32252; Package emacs. (Thu, 26 Jul 2018 17:51:02 GMT) Full text and rfc822 format available.

Message #148 received at 32252 <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Helmut Eller <eller.helmut <at> gmail.com>
Cc: Andreas Schwab <schwab <at> suse.de>, 32252 <at> debbugs.gnu.org
Subject: Re: bug#32252: [PATCH] %o and %x now format signed numbers
Date: Thu, 26 Jul 2018 10:50:35 -0700
On 07/26/2018 10:16 AM, Helmut Eller wrote:
> Where is that code?

One example is url-digest-auth-make-cnonce. This was the first I ran 
into. No doubt there are others.

> And why would it be difficult to teach
> format-time-string to deal with the tricky bits that current-time
> returns.

?! format-time-string already does that. And it's a hassle. Other Emacs 
Lisp code inspects timestamps directly too. And it's a hassle for that 
code too. Bignums would significantly lessen this hassle. Surely this is 
obvious.





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#32252; Package emacs. (Thu, 26 Jul 2018 18:37:02 GMT) Full text and rfc822 format available.

Message #151 received at 32252 <at> debbugs.gnu.org (full text, mbox):

From: Helmut Eller <eller.helmut <at> gmail.com>
To: Paul Eggert <eggert <at> cs.ucla.edu>
Cc: 32252 <at> debbugs.gnu.org
Subject: Re: bug#32252: [PATCH] %o and %x now format signed numbers
Date: Thu, 26 Jul 2018 20:35:53 +0200
On Thu, Jul 26 2018, Paul Eggert wrote:

> On 07/26/2018 10:16 AM, Helmut Eller wrote:
>> Where is that code?
>
> One example is url-digest-auth-make-cnonce. This was the first I ran
> into. No doubt there are others.

And how would url-digest-auth-make-cnonce look with bignums?

>> And why would it be difficult to teach
>> format-time-string to deal with the tricky bits that current-time
>> returns.
>
> ?! format-time-string already does that. And it's a hassle. Other
> Emacs Lisp code inspects timestamps directly too. And it's a hassle
> for that code too. Bignums would significantly lessen this
> hassle. Surely this is obvious.

To me it's not so obvious.  E.g. current-time is supposed to "return the
current time, as the number of seconds since [epoch]".  So, how are you
going to represent micro-seconds with bignums?

Or, e.g. disassemble_lisp_time deals with formats that are the form
(HIGH LOW USEC PSEC) or formats that were used in previous Emacs
versions.  With bignums, disassemble_lisp_time has to support the old
formats and bignums too.

Helmut




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#32252; Package emacs. (Thu, 26 Jul 2018 21:08:01 GMT) Full text and rfc822 format available.

Message #154 received at 32252 <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Helmut Eller <eller.helmut <at> gmail.com>
Cc: 32252 <at> debbugs.gnu.org
Subject: Re: bug#32252: [PATCH] %o and %x now format signed numbers
Date: Thu, 26 Jul 2018 14:07:36 -0700
Helmut Eller wrote:
> On Thu, Jul 26 2018, Paul Eggert wrote:
> 
>> On 07/26/2018 10:16 AM, Helmut Eller wrote:
>>> Where is that code?
>>
>> One example is url-digest-auth-make-cnonce. This was the first I ran
>> into. No doubt there are others.
> 
> And how would url-digest-auth-make-cnonce look with bignums?

Just like it does now. It would not need to change.

> With bignums, disassemble_lisp_time has to support the old
> formats and bignums too.

Yes, of course. That's not much trouble. The point is that other Lisp code can 
simply deal with just one integer rather than a tricky list of four integers 
with mixed bases.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#32252; Package emacs. (Fri, 27 Jul 2018 03:21:01 GMT) Full text and rfc822 format available.

Message #157 received at 32252 <at> debbugs.gnu.org (full text, mbox):

From: Richard Stallman <rms <at> gnu.org>
To: Drew Adams <drew.adams <at> oracle.com>
Cc: 32252 <at> debbugs.gnu.org, eggert <at> cs.ucla.edu, eller.helmut <at> gmail.com
Subject: Re: bug#32252: [PATCH] %o and %x now format signed numbers
Date: Thu, 26 Jul 2018 23:20:38 -0400
[[[ To any NSA and FBI agents reading my email: please consider    ]]]
[[[ whether defending the US Constitution against all enemies,     ]]]
[[[ foreign or domestic, requires you to follow Snowden's example. ]]]

  > The intention was not to be harsh

I know that, so I am not rebuking you.  I'm asking you to make
a little extra effort so that you won't inadvertently hurt people's
feelings.

				      but to say that, while it is
  > good to check the sources distributed with Emacs, it is not good
  > enough.

Said that way, it's not harsh at all.

Can you see how to say things the non-harsh way the first time?


-- 
Dr Richard Stallman
President, Free Software Foundation (https://gnu.org, https://fsf.org)
Internet Hall-of-Famer (https://internethalloffame.org)






Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#32252; Package emacs. (Thu, 23 Aug 2018 09:38:01 GMT) Full text and rfc822 format available.

Message #160 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Helmut Eller <eller.helmut <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: Re: bug#32252: [PATCH] %o and %x now format signed numbers
Date: Thu, 23 Aug 2018 11:37:37 +0200
On Thu, Jul 26 2018, Paul Eggert wrote:

> Helmut Eller wrote:
>> So you actually changed the default behavior even if you said you
>> wouldn't?
>
> That was not my intent. Sorry, I messed up the default settings in a
> last-minute change. Thanks for catching that so quickly. I installed
> the attached to fix it.

So you actually changed the default behavior again even if you said you
wouldn't?

Helmut





bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Thu, 20 Sep 2018 11:24:05 GMT) Full text and rfc822 format available.

bug unarchived. Request was from snickerbockers <snickerbockers <at> washemu.org> to control <at> debbugs.gnu.org. (Mon, 04 Jul 2022 00:39:01 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#32252; Package emacs. (Mon, 04 Jul 2022 01:10:02 GMT) Full text and rfc822 format available.

Message #167 received at 32252 <at> debbugs.gnu.org (full text, mbox):

From: snickerbockers <snickerbockers <at> washemu.org>
To: 32252 <at> debbugs.gnu.org
Subject: i find binary-as-unsigned to be very helpful
Date: Mon, 04 Jul 2022 01:03:26 +0000
hello,

I use binary-as-unsigned in my .emacs, and I saw that the help
page
said to e-mail you if I find it useful.  Below is a function i
made that
displays a 32-bit two's complement of a given integer in hex.  I
do a
lot of reverse-engineering of low-level programs, so it is very
useful
for me to have a quick way to see how a given integer is actually
represented in the hardware.  if binary-as-unsigned wasn't
available to
make format do most of the work for me, this function would be a
lot
longer and more complicated.

(defun to-hex(value)
 "convert a signed int to its 32-bit two's complement in hex
 notation"
 (interactive "svalue:")
(let ((binary-as-unsigned t))
 (message (substring (format "%08x" (cl-parse-integer value))
 -8))))

(global-set-key (kbd "C-c h") 'to-hex)

Thanks,
snickerbockers






bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Mon, 01 Aug 2022 11:24:05 GMT) Full text and rfc822 format available.

This bug report was last modified 2 years and 322 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.