GNU bug report logs - #56641
Deprecate `lsh`

Previous Next

Package: emacs;

Reported by: Mattias Engdegård <mattiase <at> acm.org>

Date: Tue, 19 Jul 2022 13:39:01 UTC

Severity: normal

Done: Mattias Engdegård <mattiase <at> acm.org>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Mattias Engdegård <mattiase <at> acm.org>
To: Po Lu <luangruo <at> yahoo.com>
Cc: Eli Zaretskii <eliz <at> gnu.org>, stefankangas <at> gmail.com, 56641 <at> debbugs.gnu.org
Subject: bug#56641: Deprecate `lsh`
Date: Wed, 20 Jul 2022 13:57:27 +0200
20 juli 2022 kl. 05.20 skrev Po Lu <luangruo <at> yahoo.com>:

> It might be rare, but there's nothing wrong with using lsh for its
> intended purpose, which is handling negative numbers correctly in
> several different situations.

The purpose of `lsh` is not breaking old code. (It used to have a different purpose but it vanished when bignums were introduced.)
There is no reasonable use for it in new code. Even in the unlikely event of code that just happens to need that sort of quirky behaviour, it is much better implemented explicitly where it's used, in terms of `ash`.

> Byte-compiler warnings are supposed to point out problems.  Using lsh is
> not a problem

You are right that most uses of `lsh` are perfectly innocuous but that's because they are used in a way where `ash` would give the same result. This is often true even when the return values of `lsh` and `ash` differ, as in

  (logand (lsh x -16) #xff)

which would give the same result even for negative x if `lsh` were replaced with `ash`.

However there is a potential problem since the behaviour of `lsh` is strongly platform-dependent, and it's impossible to write correct code without taking that into account (consider replacing -16 with -24 above). Users may not be aware of how it works and mistakenly think it is the 'unsigned' or 'logical' shift that they know from other languages.





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

Previous Next


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