bug-gnu-emacs
[Top][All Lists]
Advanced

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

bug#32252: [PATCH] %o and %x now format signed numbers


From: Helmut Eller
Subject: bug#32252: [PATCH] %o and %x now format signed numbers
Date: Thu, 26 Jul 2018 10:43:52 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

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





reply via email to

[Prev in Thread] Current Thread [Next in Thread]