doc icon indicating copy to clipboard operation
doc copied to clipboard

"`cmp` will first try to compare operands as strings (via coercion to `Stringy`)" NOPE

Open raiph opened this issue 1 year ago • 1 comments

Infix cmp doc begins:

cmp will first try to compare operands as strings (via coercion to Stringy)

Not true (and I don't think it's ever been true):

say <42+0i>.Stringy cmp <5+0i>.Stringy; # Less
say  42+0i          cmp  5+0i         ; # More

Note that this has nothing to do with Stringy or complex numbers.

The doc simply misstates cmp's logic.

raiph avatar Nov 18 '23 23:11 raiph

To trace the issue back:

https://github.com/Raku/doc/commit/a90a5e51c2e1188b729ce7f2f6ba46b873ad1963 The original description was already wrong. Probably there was a misunderstanding about cmp being the stringy version of <=> (that's actually leg which is somehow not even mentioned at Order and has a completely different signature).

https://github.com/Raku/doc/issues/1036 already pointed this out but the fix applied went the wrong way around it.


However, I tend to question whether cmp and <=> even have to be there. Sure, the output type of these operations are Orders but usually one would list the operations to be performed on the particular data type. I think it would be enough to informally illustrate that comparison operations (including leg actually) produce Order values, and put the type graph there. If there are specific operations for Orders then those could be added but I don't think there are (m)any.

2colours avatar Nov 25 '23 15:11 2colours