sorear/niecza

`cmp` always says that string is bigger when using cmp on number and string

Opened this issue · 2 comments

niecza> '42' cmp 123456789
Decrease
niecza> '42' cmp -123456789
Decrease
niecza> '42' cmp NaN
Decrease
niecza> 42 cmp 'abcdef'
Increase

I don't know what it should do, but this behavior doesn't make sense.

I don't know what it should do either, and the spec is silent. What would help this bug be resolved faster is concrete suggestions for a cmp algorithm that satisfies both the Principle of Least Astonishment and the axioms of a total order predicate. It would be interesting to know how "real users" think cmp should behave.

There is list of things which could be done in this case.

  • Throwing exception (but well, Perl is not Python or Ruby)
  • Checking if string looks like number and comparing it as number, string otherwise
  • Acting like comparing strings (Perl 5 users friendly and Rakudo does this)
  • Acting like comparing numbers (but that would be pretty surprising, so it shouldn't be done)

But whatever happens, it should be consistent and inserted into specification.