Subject: bug#56641: Deprecate `lsh`

From: Mattias Engdegård <[email-masked]>
Date: Wed, 20 Jul 2022 13:57:27 +0200

20 juli 2022 kl. 05.20 skrev Po Lu <[email-masked]>:

> 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.