[swift-evolution] [pitch] One-sided Ranges

Haravikk swift-evolution at haravikk.me
Fri Apr 14 07:52:49 CDT 2017

Apologies if this comes through as a duplicate for some people, but I'm not sure if it went through the first time; I seem to have some trouble with ProofPoint, who apparently do not monitor their false positive reporting system. As such my mail server is still listed from eight months ago despite never having a single spam message reported in that time, so pretty sure ProofPoint is a massive waste of money to anyone having it inflicted upon them, as it seemingly blocks entire servers with no negative rating.

Anyway, I'll repost for anyone that didn't get it the first time; if you ignored it the first time then feel free to do-so again, just know that it shall do irreparable harm to my fragile ego:

I like the principle in general, but I have some concerns about the range syntax. Firstly my concern is that allowing either end of the range to be omitted feels like a possible bug to me, so I'm not sure if we should encourage that?

I'm wondering if a slightly better alternative might to be to retain the operators as binary but to pass Void, like so:

	let rangeFrom = 5...()
	let rangeTo = ()...5

And so-on. It's not quite as pretty, but makes it clear that no mistake was made, and allows the operators to be defined normally taking two arguments of Comparable and Void (and vice versa).

It could be neatened up if we could allow a lone underscore as Void, like so:

	let rangeFrom = 5..._
	let rangeTo = _...5

This is a bit neater looking, and should be consistent with how underscore is used elsewhere? I'm not sure if it might conflict though, but I don't think so.

Just I thought, but I dislike the idea that by forgetting a value on a range, or making some other typo, I could accidentally define an open ended range and change the behaviour of something that accepts both open and closed ranges, I think requiring something that explicitly indicates an open range is a bit better.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170414/2a4a10d8/attachment.html>

More information about the swift-evolution mailing list