[swift-evolution] [Draft] Rationalizing Sequence end-operation names

Xiaodi Wu xiaodi.wu at gmail.com
Tue Jun 28 18:06:27 CDT 2016


I understand that that's your thinking. I just don't understand how you
arrived at your rule (2). It's not in the dictionary definition of the
words prefix and suffix. Nor do I find any documentation of such a rule in
Swift. Nor do I think you've shown that such a rule is necessary for
clearing up some actual confusion. Nor do I see that applying the rule and
using subscripts yields a superior solution to what we currently have.
On Tue, Jun 28, 2016 at 5:40 PM Brent Royal-Gordon <brent at architechies.com>
wrote:

> > I was in the midst of writing a reply along the same lines, so I figured
> I'd add to David's reply here. There are two characteristics I would expect
> from a method named "prefix" or "suffix".
> >
> > First, it should return a subsequence containing zero to count elements.
> (By contrast, something named "first" should return nil or one element, but
> certainly no more.)
> >
> > Second, in the case of "prefix", the first element of the subsequence
> (if any) should be the first element of the sequence; in the case of
> "suffix", the last element of the subsequence (if any) should be the last
> element of the sequence.
>
> I would phrase these things slightly differently. In my thinking, a method
> with `prefix` or `suffix` in its name:
>
>         1. Operates on a subsequence at the beginning/end of the sequence,
>
>         2. Measured *relative* to the beginning/end.
>
> An index-based operation doesn't fit this definition because an index is
> not *relative* to anything—it's an *absolute* position within the sequence.
>
> Put another way, in my view, "prefix" and "suffix" don't merely mean
> "anchored at the beginning/end". A prefix or suffix is attached to a
> "middle". There is no middle in the index-based operations.
>
> It is, of course, very possible to use methods to express what the
> index-based operations do:
>
>         friends.upTo(i)
>         friends.through(i)
>         friends.from(i)
>
> But at this point, we've basically arrived at `friends[to: i]` etc.
>
> --
> Brent Royal-Gordon
> Architechies
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160628/49c4468b/attachment.html>


More information about the swift-evolution mailing list