Understanding issorted's lt keyword

help?> issorted
search: issorted InsertionSort

  issorted(v, lt=isless, by=identity, rev:Bool=false, order::Ordering=Forward)

  Test whether a vector is in sorted order. The lt, by and rev keywords modify what order is considered to be sorted just as they do for sort.

help?> sort
[...] 

  sort(v; alg::Algorithm=defalg(v), lt=isless, by=identity, rev::Bool=false, order::Ordering=Forward)

The default lt function is isless.

help?> isless
[...]

  isless(x, y)

  Test whether x is less than y, according to a fixed total order. isless is not defined on all pairs of values (x, y). However, if it is defined, it is expected to satisfy the
  following:

    •  If isless(x, y) is defined, then so is isless(y, x) and isequal(x, y), and exactly one of those three yields true.

Note that lt = <= does not satisfy that property, since for x == y, all three (lt(x, y), lt(y, x), isequal(x, y)) are true.

˜Perhaps more intuitively, ask yourself how you might implement issorted, and what you’d expect it to be able to do just given the <= function?~ [ Edit: I’m not sure what I had meant by this]

2 Likes