<div dir="ltr">Yes, Rob, even though our proposals are very related, I do think that yours would fit better in a new proposal.<div><br></div><div>My first draft was also in regards to change the default behaviour - not focused on optionals though. It went through a discussion about *masking* the current fail fast behaviour (e.g. debugging would be more difficult, could lead to some unexpected bugs, etc) so that we have changed it to propose those additional subscript methods instead.</div><div><br></div><div>On the other hand, your proposal seems to be more consistent with the existing *problem* and I think it should follow the path I had tried initially, and hopefully it will get accepted. Considering my python/ruby background, I really think we need more handy and lenient operations over collections.</div><div><br></div><div>Let's keep the discussion going, but so far I am +1 for that initial idea.<br><div><br></div><div>- Luis<div><div><div class="gmail_extra"><div><div data-smartmail="gmail_signature"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr" style="font-size:small"><br></div></div></div></div></div></div></div></div></div></div></div>
<br><div class="gmail_quote">On Mon, Jun 6, 2016 at 7:02 PM, Rob Norback <span dir="ltr"><<a href="mailto:rnorback@gmail.com" target="_blank">rnorback@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><div><div><div>First of all, thank you all for bringing me up to date so quickly. I looked over the proposal and it looks awesome.<br><br></div>But as Chris mentioned, this doesn't solve the expected behavior and ambiguity of ```Array<Int?>```<br><br></div>In this case I would expect the default behavior (myArray[4]) without using myArray[checking: 4] should return a nil in this case.<br><br></div><div>And Chris, I think it would make the most sense to have myArray[0] = nil to be stored if the index is in Range, and for myArray[100] = nil to give a warning of no assignment being made because index is out of range, kind of like an unused variable. Right now myArray[100] = nil gives you EXC_BAD_INSTRUCTION. Then if you assigned myArray[100] = 200, that would have to simply change the Range.<br><br></div><div>Chris, I honestly have to think more about that ambiguity with dictionaries.<br></div><div><br></div><div>I can see that this would definitely need some further fleshing out, but it seems to be sufficiently different from Luis' proposal to perhaps merit it's own proposal.<br></div><div><br></div>It's up to you Luis, but I think this might be a bit more controversial then the changes you've proposed, making it possible for your proposal getting rejected. (I want your proposal accepted, since I would use those features today). Partial acceptance of a proposal doesn't seem to be a thing. (Once again please correct me if I'm wrong).<br></div></div><div><div><br><div class="gmail_quote"><div dir="ltr">On Mon, Jun 6, 2016 at 11:46 AM Luis Henrique B. Sousa <<a href="mailto:lshsousa@gmail.com" target="_blank">lshsousa@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr">Thanks Vladimir,<div><br></div><div>The correct link is this one (with the additional min/max operations in the implementation): </div><div><a href="https://github.com/luish/swift-evolution/blob/proposal-lenient-collection-subscripts/proposals/nnnn-more-lenient-collections-subscripts.md" target="_blank">https://github.com/luish/swift-evolution/blob/proposal-lenient-collection-subscripts/proposals/nnnn-more-lenient-collections-subscripts.md</a></div><div><br></div><div>Here is the pull request on the swift-evolution repo: <a href="https://github.com/apple/swift-evolution/pull/328" target="_blank">https://github.com/apple/swift-evolution/pull/328</a></div><div><br></div><div>Any help or suggestion to improve the proposal is welcome. :-)</div><div><br></div><div class="gmail_extra"></div></div><div dir="ltr"><div class="gmail_extra"><div><div data-smartmail="gmail_signature"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div style="font-size:small">- Luis</div></div></div></div></div></div></div></div></div></div></div></div></div><div dir="ltr"><div class="gmail_extra">
<br><div class="gmail_quote">On Mon, Jun 6, 2016 at 6:10 PM, Vladimir.S via swift-evolution <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">Please find this draft of proposal(hope this is correct link for latest version):<br>
<a href="https://github.com/luish/swift-evolution/blob/more-lenient-subscripts/proposals/nnnn-more-lenient-collections-subscripts.md" rel="noreferrer" target="_blank">https://github.com/luish/swift-evolution/blob/more-lenient-subscripts/proposals/nnnn-more-lenient-collections-subscripts.md</a><br>
<br>
The main idea is to introduce 2 new subscript methods: [clamping:] and [checking:]<br>
<br>
There was discussion in "[Proposal] More lenient subscript methods over Collections" and (older) "[Proposal] Safer half-open range operator"<div><div><br>
<br>
On 06.06.2016 19:50, Rob Norback via swift-evolution wrote:<br>
</div></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div><div>
Hi Everyone!<br>
<br>
This is my first time emailing the swift evolution list, so if this topic<br>
has already been discussed please let me know. I looked through all the<br>
accepted and rejected proposals and it doesn't seem to be on there.<br>
<br>
The main thought is that dictionaries return optionals, so why not arrays?<br>
Or other CollectionTypes for that matter. I would think this would be the<br>
expected behavior in this situation:<br>
<br>
var myArray:[String?] = []<br>
print(myArray[4])<br>
// EXC_BAD_INSTRUCTION, but could just be Optional(nil)<br>
<br>
Then you could do things like<br>
<br>
if let arrayValue = myArray[4] {<br>
// do something<br>
}<br>
<br>
Of course you could simply check with with the count, but considering<br>
Swift's use of optionals to represent empty variables rather than erroring<br>
out or returning an empty String, I think this functionality would be<br>
appropriate to include in the Swift standard library.<br>
<br>
And there's about 15,000 people who've looked for this functionality in the<br>
last year:<br>
<a href="http://stackoverflow.com/questions/25329186/safe-bounds-checked-array-lookup-in-swift-through-optional-bindings" rel="noreferrer" target="_blank">http://stackoverflow.com/questions/25329186/safe-bounds-checked-array-lookup-in-swift-through-optional-bindings</a>.<br>
<br>
Please let me know what you think.<br>
<br>
Best,<br>
Rob Norback<br>
<br>
<br></div></div>
_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
<br>
</blockquote>
_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</blockquote></div><br></div></div></blockquote></div>
</div></div></blockquote></div><br></div></div></div></div></div></div>