[swift-evolution] Marking sort and sorted with rethrows
Dmitri Gribenko
gribozavr at gmail.com
Thu Jun 9 03:07:00 CDT 2016
On Wed, Jun 8, 2016 at 11:25 PM, Brent Royal-Gordon via
swift-evolution <swift-evolution at swift.org> wrote:
> I actually think there *is* a sensible way to define the behavior of a throwing `sort(_:)`: you treat the comparison as though it returned `false` and continue sorting.
This can create inconsistent sorting predicates, which we would want
to catch as issues with the code and trap.
For example, your predicate can establish that a < b and b < c, but a
< c is throwing which is treated as returning false -- clearly, a
contradiction.
Dmitri
--
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com>*/
More information about the swift-evolution
mailing list