[swift-evolution] Fixing the confusion between non-mutating algorithms and single-pass sequences

Xiaodi Wu xiaodi.wu at gmail.com
Tue Jul 12 19:01:57 CDT 2016

This more limited approach makes sense in light of the documented
reasoning. However, as a renaming proposal, I feel like I should raise some
points about the proposed name.

First, a naive interpretation of IterableOnce may cause a user to think
that a for...in loop over an IterableOnce is guaranteed to execute at least
once. It is not that a sequence is "iterable once." It could be iterable
exactly zero times. Rather, after however many iterations, the iterating
cannot take place from the beginning again.

Second, the dictionary definition of "once" lists an ambiguity, where (at
least in one source) the first meaning is "one time only." (See: <
https://www.google.com/#q=define:once>.) This could lead to
misinterpretations of the relationship where Collection is IterableOnce.

I would propose that perhaps Iterable is sufficient to convey the meaning.
There is no a priori user expectation, I think, that something iterable
remains unchanged on traversal.

On Tue, Jul 12, 2016 at 5:55 PM, Dmitri Gribenko via swift-evolution <
swift-evolution at swift.org> wrote:

> Hi,
> I'd like to continue the discussion of the issue raised by David Waite
> inhttp://thread.gmane.org/gmane.comp.lang.swift.evolution/21295/:
> > My main motivation for proposing this is the potential for developer
> confusion. As stated during one of the previous threads on the naming of
> map, flatMap, filter, etc. methods on Sequence, Sequence has a naming
> requirement not typical of the rest of the Swift standard library in that
> many methods on Sequence may or may not be destructive. As such, naming
> methods for any extensions on Sequence is challenging as the names need to
> not imply immutability.
> I'd like to focus on a particular point: methods on Sequence can
> consume elements, but the APIs are not markedmutating.
> Dave Abrahams, Max Moiseev, and I have discussed this issue and we
> agree this problem is severe and worth solving, we also think that the
> likely solutions would be source-breaking, so it is important that we
> discuss it now.
> We have discussed a few options.
> - Rejected option: remove Sequence, let IteratorProtocol model
> single-pass data streams
> - Rejected option: use a syntactic marker, like sequence.consumedIn.map {}
> - Rejected option: mutating APIs on Sequence, non-mutating APIs on
> Collection
> Proposed: rename Sequence to IterableOnce or TraversableOnce. We think
> that Sequence does not convey the single-pass restriction clearly. The
> term "sequence" has been used in math (as in "integer sequence"), and
> since the math domain does not have mutation, "sequence" can be
> understood to mean "multi-pass", since you can traverse a sequence of
> integers an arbitrary number of times.
> We think that only the last option is viable in the Swift language as
> it exists now, without creating an undue burden for API vendors and
> users.
> For more details about rejection options, please see the full writeup:
> https://gist.github.com/gribozavr/47f4717f3afc762549383e94da7f748b
> 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>*/
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160712/1e478876/attachment.html>

More information about the swift-evolution mailing list