lua-users home
lua-l archive

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


On Tue, Mar 25, 2014 at 12:19 PM, Dirk Laurie <dirk.laurie@gmail.com> wrote:
>> Java, C#, Javascript, Python, and PHP all agree that right shifts
>> are arithmetic shifts.
>
> Thanks for this nearly complete list (Perl is missing) of languages
> that I love to hate. Why is Perl missing? Because you did not look
> it up or because it fails to fit the bill?

I didn't look it up. I don't use Perl too often so I didn't think
about it while I was doing a few quick searches.

>> Having Lua disagree in this respect violates the principle of least surprise.
>
> The principle of least surprise, IMHO, demands that the idiom
> x << m >> (64-n) should give a non-negative number less than 2^n,
> consisting of the n bits starting at the (m+1)-st th bit from the left,
> irrespective of whether that bit is a 0 or a 1.

The important thing is that algorithms implemented in other languages
should be straightforwardly portable. Having an algorithm that needs
changed for Lua and Lua alone is the violation of the principle of
least surprise.

/s/ Adam