Jonathan M Davis:
> Comparator functions are pretty much always binary predicates.
And I think this has to change a bit in D. Because mapping functions are quite
handy (despite requiring more memory, so it can't be the only way to do things
in D, and both ways need to be supported).
In Python3 sort/sorted/min/max don't take a comparator function, they only take
a key mapping function.
It's often used in Haskell too:
import Data.List (sortBy)
import Data.Ord (comparing)
main = print $ sortBy (comparing length) [[1,3,1], [5], [7,7]]
> It would be incredibly bizarre for it to do otherwise,
It's not bizarre at all :-) If you want to express such value judgements then I
suggest you to look at more programming languages, so better know what you are
talking about.
> and taking simply the property to compare
> would be extremely limiting.
It gives some limitations in some uncommon cases (where using a comparator is
better), but surely it's not 'extremely limiting'. I am using _only_ key
(mapping) functions in Python since years, and I am writing all kinds of
programs with it.
> For instance, what if you you wanted to compare
> using two properties? That's completely straightforward with a binary
> predicate and utterly impossible when you pass the property to be compared
> instead of a proper predicate.
It's extremely simple to do :-)
(p){ return tuple(p.foo, p.bar); }
Bye,
bearophile