<div dir="ltr"><div class="gmail_default" style="font-family:georgia,serif">I am not a software scientist. I have to explain things with examples. For example, in Framework headers.</div><div class="gmail_default" style="font-family:georgia,serif"><br></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div class="gmail_default" style="font-family:georgia,serif"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span style="color:rgb(187,44,162)">extension</span><span style="color:rgb(0,0,0)"> </span><span style="">Array</span><span style="color:rgb(0,0,0)"> : </span><span style="">RangeReplaceableCollection</span><span style="color:rgb(0,0,0)"> {</span><br><span style="color:rgb(0,0,0)">    </span><span style="">/// Creates a new, empty array.<br></span><span style="">    </span><span style="color:rgb(0,132,0)">///<br></span><span style="color:rgb(0,0,0)">    </span><span style="">/// This is equivalent to initializing with an empty array literal.<br></span><span style="color:rgb(0,0,0)">    </span><span style="">/// For example:<br></span><span style="">    </span><span style="color:rgb(0,132,0)">///<br></span><span style="color:rgb(0,0,0)">    </span><span style="">///     var emptyArray = Array&lt;Int&gt;()<br></span><span style="color:rgb(0,0,0)">    </span><span style="">///     print(emptyArray.isEmpty)<br></span><span style="color:rgb(0,0,0)">    </span><span style="">///     // Prints &quot;true&quot;<br></span><span style="">    </span><span style="color:rgb(0,132,0)">///<br></span><span style="color:rgb(0,0,0)">    </span><span style="">///     emptyArray = []<br></span><span style="color:rgb(0,0,0)">    </span><span style="">///     print(emptyArray.isEmpty)<br></span><span style="color:rgb(0,0,0)">    </span><span style="">///     // Prints &quot;true&quot;<br></span><span style="color:rgb(0,0,0)">    </span><span style="">public</span><span style="color:rgb(0,0,0)"> </span><span style="">init</span><span style="color:rgb(0,0,0)">()</span></blockquote></div><div class="gmail_default" style="font-family:georgia,serif"><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(187,44,162)"><br></p></div></blockquote><div class="gmail_default" style="font-family:georgia,serif">
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><span style=""></span></p>
</div><div class="gmail_default" style="font-family:georgia,serif">











<div><font color="#000000">In Swift source code.</font></div><div><font color="#000000"><br></font></div></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div class="gmail_default" style="font-family:georgia,serif"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">extension ${Self} : RangeReplaceableCollection, _ArrayProtocol {<br>  /// Creates a new, empty array.<br>  ///<br>  /// This is equivalent to initializing with an empty array literal.<br>  /// For example:<br>  ///<br>  ///     var emptyArray = Array&lt;Int&gt;()<br>  ///     print(emptyArray.isEmpty)<br>  ///     // Prints &quot;true&quot;<br>  ///<br>  ///     emptyArray = []<br>  ///     print(emptyArray.isEmpty)<br>  ///     // Prints &quot;true&quot;<br>  @_semantics(&quot;array.init&quot;)<br>  public init() {<br>    _buffer = _Buffer()<br>  }</blockquote><div><br></div></div></blockquote><span style="font-family:georgia,serif"><div class="gmail_default" style="font-family:georgia,serif;display:inline">​So I am confident to say, if there is no protocol limits on init() to be empty. You can do what ever with Array&lt;Int&gt;(), maybe </div></span><br><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">l<div class="gmail_default" style="font-family:georgia,serif;display:inline">​et foo = Array&lt;Int&gt;() // means [1] is OK​, as there is no limitation prohibits you to do so.</div></blockquote><div><br></div></blockquote><div class="gmail_default" style="font-family:georgia,serif;display:inline">​So there always must be a protocol saying init() to be an empty collection. We just don&#39;t know why it is put in ​</div><font face="georgia, serif">RangeReplaceableCollection. <div class="gmail_default" style="font-family:georgia,serif;display:inline">​at the moment.​</div></font><div><font face="georgia, serif"><br></font></div><div><div class="gmail_default" style="font-family:georgia,serif;display:inline">Conforming chains(collection part only):</div><font face="georgia, serif"><br></font></div><div><font face="georgia, serif"><div class="gmail_default" style="font-family:georgia,serif;display:inline">Array:</div>MutableCollection<div class="gmail_default" style="font-family:georgia,serif;display:inline">​:</div>Collection:<div class="gmail_default" style="font-family:georgia,serif;display:inline">​</div>Sequence <div class="gmail_default" style="font-family:georgia,serif;display:inline">​</div></font></div><div><font face="georgia, serif"><div class="gmail_default" style="font-family:georgia,serif;display:inline">Array:</div>RandomAccessCollection:<div class="gmail_default" style="font-family:georgia,serif;display:inline">​​</div>BidirectionalCollection:<div class="gmail_default" style="font-family:georgia,serif;display:inline">​​</div>Collection<div class="gmail_default" style="font-family:georgia,serif;display:inline">​</div></font><span style="font-family:georgia,serif">:</span><div class="gmail_default" style="font-family:georgia,serif;display:inline">​</div><span style="font-family:georgia,serif">Sequence </span><div class="gmail_default" style="font-family:georgia,serif;display:inline">​</div></div><div><font face="georgia, serif"><div class="gmail_default" style="font-family:georgia,serif;display:inline">A​rray:</div>RangeReplaceableCollection:<div class="gmail_default" style="font-family:georgia,serif;display:inline">​</div>Collection</font><span style="font-family:georgia,serif">​</span><span style="font-family:georgia,serif">:</span><div class="gmail_default" style="font-family:georgia,serif;display:inline">​</div><span style="font-family:georgia,serif">Sequence </span><div class="gmail_default" style="font-family:georgia,serif;display:inline">​</div></div><div><font face="georgia, serif"><div class="gmail_default" style="display:inline"><br></div></font></div><div><font face="georgia, serif"><div class="gmail_default" style="display:inline">For Sequence protocol, there is no mutating functions.</div></font></div><div><div class="gmail_default" style="font-family:georgia,serif">​</div><div class="gmail_default" style="font-family:georgia,serif">For Collection protocol, the mutating functions are removeFirst(), removeFirst(Int), split(_:_:_) and  popFirst(). As you can imaging, an empty collection can call none of the functions.</div></div><div class="gmail_default" style="font-family:georgia,serif"><br></div><div class="gmail_default" style="font-family:georgia,serif">For MutableCollection, BidirectionalCollection, RandomAccessCollection, the situations are similar. They just don&#39;t have extra mutating functions nor an empty collection can&#39;t call these mutating functions.</div><div class="gmail_default" style="font-family:georgia,serif"><br></div><div class="gmail_default" style="font-family:georgia,serif">For RangeReplaceableCollection protocol, below mutating function works in an empty collection</div><div class="gmail_default" style="font-family:georgia,serif"><br></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div class="gmail_default" style="font-family:georgia,serif">func append&lt;S&gt;(contentsOf: S)</div></blockquote><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div class="gmail_default"><font face="georgia, serif">func removeAll(keepingCapacity: Bool)</font></div></blockquote><font face="georgia, serif"><br></font><div class="gmail_default" style="font-family:georgia,serif">Maybe that is why the must have init() is put here.</div><div><div><font face="georgia, serif"><br></font><div><span style="font-family:georgia,serif"><div class="gmail_default" style="font-family:georgia,serif;display:inline">Zhaoxin​</div></span><br></div></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jul 7, 2016 at 12:10 AM, Tim Vermeulen <span dir="ltr">&lt;<a href="mailto:tvermeulen@me.com" target="_blank">tvermeulen@me.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div>I never said a RangeReplaceableCollection shouldn’t be empty. I just think it’s strange that it requires an empty initialiser (while the Collection protocol doesn’t).</div><div><div class="h5"><br><div><blockquote type="cite"><div>On 6 Jul 2016, at 16:33, Zhao Xin &lt;<a href="mailto:owenzx@gmail.com" target="_blank">owenzx@gmail.com</a>&gt; wrote:</div><br><div><div dir="ltr">N<div class="gmail_default" style="font-family:georgia,serif;display:inline">​o. You didn&#39;t catch what I meant. I meant it should be like an equation. ​If foo is a </div><span style="font-family:georgia,serif">​</span><font face="georgia, serif">RangeReplaceableCollection,<div class="gmail_default" style="font-family:georgia,serif;display:inline">​ </div></font><span style="font-family:georgia,serif">foo</span><font face="georgia, serif"><div class="gmail_default" style="font-family:georgia,serif;display:inline"> minus </div></font><span style="font-family:georgia,serif">foo</span><font face="georgia, serif"><div class="gmail_default" style="display:inline"> equates zero, zero means an empty collection. Both side of the equation should be with the same unit, the unit is </div></font><span style="font-family:georgia,serif">RangeReplaceableCollection.<div class="gmail_default" style="font-family:georgia,serif;display:inline">​ Below code also shows init() is useful in </div></span><font face="georgia, serif">RangeReplaceableCollection.<div class="gmail_default" style="font-family:georgia,serif;display:inline">​​</div></font><div><span style="font-family:georgia,serif"><div class="gmail_default" style="font-family:georgia,serif;display:inline"><br></div></span></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:rgb(187,44,162)">var</span><span> foo = </span><span style="color:rgb(112,61,170)">Array</span><span>&lt;</span><span style="color:rgb(112,61,170)">Int</span><span>&gt;()</span></div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">
</p><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:rgb(79,129,135)">foo</span><span>.</span><span style="color:rgb(61,29,129)">append</span><span>(contentsOf: [</span><span style="color:rgb(39,42,216)">2</span><span>,</span><span style="color:rgb(39,42,216)">4</span><span>,</span><span style="color:rgb(39,42,216)">6</span><span>,</span><span style="color:rgb(39,42,216)">8</span><span>])</span></div></blockquote></blockquote>
<div><div><font face="georgia, serif"><div class="gmail_default" style="font-family:georgia,serif;display:inline"><br></div></font></div><div><font face="georgia, serif"><div class="gmail_default" style="font-family:georgia,serif;display:inline">​Zhaoxin</div></font></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jul 6, 2016 at 10:07 PM, Tim Vermeulen <span dir="ltr">&lt;<a href="mailto:tvermeulen@me.com" target="_blank">tvermeulen@me.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">You wouldn’t need an empty initialiser to remove all elements from a collection, right? You could just use `replaceRange` instead.<br>
<br>
&gt; Now I understood you concerns. Have you ever thought of if a non-empty RangeReplaceableCollection being removed all of its elements, which makes the collection to be an empty collection. That shouldn&#39;t change theRangeReplaceableCollection to be a non-RangeReplaceableCollection. Sothe empty collection must also be aRangeReplaceableCollection.<br>
&gt;<br>
&gt; &gt; init()<br>
&gt; (<a>file:///Users/zhaoxin/Library/Application%20Support/Dash/DocSets/Apple_API_Reference/Apple_API_Reference.docset/Contents/Resources/Documents/</a><a href="http://developer.apple.com/reference/swift/rangereplaceablecollection/1641467-init.html" rel="noreferrer" target="_blank">developer.apple.com/reference/swift/rangereplaceablecollection/1641467-init.html</a>)&gt; Creates a new, empty collection.<br>
&gt;<br>
&gt; Zhaoxin<br>
<span>&gt;<br>
&gt; On Wed, Jul 6, 2016 at 9:09 PM, Tim Vermeulen&lt;<a href="mailto:tvermeulen@me.com" target="_blank">tvermeulen@me.com</a>(mailto:<a href="mailto:tvermeulen@me.com" target="_blank">tvermeulen@me.com</a>)&gt;wrote:<br>
&gt; &gt; I’m not allowing generic subscripts. The collection is declared as `AnyIndexArray&lt;Index: Strideable, Element where Index.Stride == Int&gt;` and it can be subscripted with type `Index`.<br>
&gt; &gt;<br>
&gt; &gt; Either way, it’s not really important. I’m mostly wondering why RangeReplaceableCollection needs an empty initialiser.<br>
&gt; &gt;<br>
&gt; &gt; &gt;Then how you defined the index to conform toStrideable? Below code does work as it seams that you can&#39;t use generics in subscripts.<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt;subscript&lt;T:Strideable&gt;(index:T) -&gt;Element<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt;Zhaoxin<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt;<br>
</span>&gt; &gt; &gt;On Wed, Jul 6, 2016 at 8:32 PM, Tim Vermeulen&lt;<a href="mailto:tvermeulen@me.com" target="_blank">tvermeulen@me.com</a>(mailto:<a href="mailto:tvermeulen@me.com" target="_blank">tvermeulen@me.com</a>)(mailto:<a href="mailto:tvermeulen@me.com" target="_blank">tvermeulen@me.com</a>)&gt;wrote:<br>
<span>&gt; &gt; &gt;&gt;<br>
&gt; &gt; &gt;&gt;&gt;On 6 Jul 2016, at 14:03, Zhao Xin&lt;<a href="mailto:owenzx@gmail.com" target="_blank">owenzx@gmail.com</a>(mailto:<a href="mailto:owenzx@gmail.com" target="_blank">owenzx@gmail.com</a>)(mailto:<a href="mailto:owenzx@gmail.com" target="_blank">owenzx@gmail.com</a>)&gt;wrote:<br>
&gt; &gt; &gt;&gt;&gt;According to the document of Swift 3, Array has already conformed protocolRangeReplaceableCollection.<br>
&gt; &gt; &gt;&gt;<br>
&gt; &gt; &gt;&gt;That’s exactly why I also want to conform my wrapper to that protocol? I think there’s a misunderstanding. I’m making a collection that can be subscripted with any index (that conforms to Strideable), but behaves like an array otherwise.<br>
&gt; &gt; &gt;&gt;<br>
&gt; &gt; &gt;&gt;&gt;<br>
&gt; &gt; &gt;&gt;&gt;Zhaoxin<br>
&gt; &gt; &gt;&gt;&gt;<br>
</span><span>&gt; &gt; &gt;&gt;&gt;On Wed, Jul 6, 2016 at 7:09 PM, Tim Vermeulen via swift-users&lt;<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>(mailto:<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>)(mailto:<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>)&gt;wrote:<br>
&gt; &gt; &gt;&gt;&gt;&gt;RangeReplaceableCollection has three initialisers: init(), init(_:) and init(repeating:count:). The latter two are implemented using the empty initialiser. But why are these initialisers part of this particular protocol? As far as I can tell, no other methods of this protocol depend on these initialisers. The requirement of the empty initialiser makes it impossible to have a collection conform to this protocol that needs additional data for its initialisation.<br>
&gt; &gt; &gt;&gt;&gt;&gt;<br>
&gt; &gt; &gt;&gt;&gt;&gt;For instance, I was making an array that works with any Strideable indices, not just integers. A startIndex is needed for its initialisation, so I can’t really conform it to RangeReplaceableCollection. If I do it anyways (with a fatalError() in the required empty initialiser) everything seems to work just fine, except for the protocol’s three initialisers.<br>
&gt; &gt; &gt;&gt;&gt;&gt;<br>
&gt; &gt; &gt;&gt;&gt;&gt;Perhaps these initialisers should be moved to a (possible new) different protocol?<br>
&gt; &gt; &gt;&gt;&gt;&gt;_______________________________________________<br>
&gt; &gt; &gt;&gt;&gt;&gt;swift-users mailing list<br>
</span>&gt; &gt; &gt;&gt;&gt;&gt;<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>(mailto:<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>)(mailto:<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>)<br>
&gt; &gt; &gt;&gt;&gt;&gt;<a href="https://lists.swift.org/mailman/listinfo/swift-users" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-users</a><br>
&gt; &gt; &gt;&gt;&gt;<br>
&gt; &gt; &gt;&gt;<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt;<br>
&gt;<br>
&gt;<br>
&gt; </blockquote></div><br></div>
</div></blockquote></div><br></div></div></div></blockquote></div><br></div>