4 ms·
Had a chat about Swift over lunch today, one topic was the choice of using .. and ... to represent ranges. Interesting to see the comments of the gist focus on
by djb_hackernews 12y ago
Had a chat about Swift over lunch today, one topic was the choice of using .. and ... to represent ranges. Interesting to see the comments of the gist focus on this as well. Surely is a confusing and potentially dangerous syntax.
- gilgoomesh 12y agoInterestingly, the .. and ... operators are not part of the language but are defined in the standard library. This means you can override .. (to disable it) and define your own operator for half-closed ranges if you'd prefer (Swift supports building your own operators from combinations of punctuation characters). At least I think you could do this: I haven't tried.
- Jtsummers 12y agoInteresting, would it be possible, then, to use the perl6 style operators? (^ at either end to make it exclusive instead of inclusive)
- Someone 12y agoIf so, that opens entire new routes for obfuscation. For the subject at hand: I would like to have seen ranges use () for open endings and [] for closed ones. For example, [1..5) would include 1 but exclude (that is standard notation in mathematics. See http://en.wikipedia.org/wiki/Interval_(mathematics)#Excluding_the_endpoints http://en.wikipedia.org/wiki/Interval_(mathematics)#Excludin...) Back to the obfuscation thing: unfortunately for that goal, one cannot create prefix operators with names (, [ or { It is possible to define an infix operator named ., though. That could give whole new meaning to what look like floating point values such as 3.14.