<div dir="ltr">So the [Int]() is shorthand for Array<Int>()</div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jan 5, 2016 at 1:01 PM, Jeremy Pereira <span dir="ltr"><<a href="mailto:jeremy.j.pereira@googlemail.com" target="_blank">jeremy.j.pereira@googlemail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><br>
> On 5 Jan 2016, at 12:51, James Campbell <<a href="mailto:james@supmenow.com">james@supmenow.com</a>> wrote:<br>
><br>
> The problem for me is that is so counter intuitive I didn't even know you could do that.<br>
<br>
</span>The first one is a bit counter intuitive and I agree that<br>
<br>
var distanceCache: [Int: Int] = []<br>
<br>
might be an improvement, albeit not one I think many people would agree is worth doing. However, the second one is a natural extrapolation from the equivalent array syntax i.e.<br>
<br>
var array = [Int]()<br>
var dictionary = [String: Int]()<br>
<div class="HOEnZb"><div class="h5"><br>
><br>
> On Tue, Jan 5, 2016 at 12:50 PM, Jeremy Pereira <<a href="mailto:jeremy.j.pereira@googlemail.com">jeremy.j.pereira@googlemail.com</a>> wrote:<br>
> I don’t understand what the problem is<br>
><br>
> > On 5 Jan 2016, at 12:39, James Campbell via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br>
> ><br>
> > See this code:<br>
> > var distanceCache: [Int: Int] = Dictionary<Int, Int>()<br>
> ><br>
> > It is very long and tedious to write especially if what I am storing changes.<br>
> ><br>
> > I propose we be allowed to do the following:<br>
> > var distanceCache: [Int: Int] = []<br>
><br>
> You can do<br>
><br>
> var distanceCache: [Int: Int] = [:]<br>
><br>
> Also<br>
><br>
> var distanceCache2 = [Int: Int]()<br>
><br>
><br>
> > Perhaps this dictionary syntax is just confusing and it was a bad idea to make it the same as an array. Most languages use "{" so why did swift choose to share "[" with arrays and dictionaries.<br>
><br>
> It’s not the same, you need the colons inside. I imagine that braces were discarded on the grounds that it would confuse the compiler with respect to closures, for example<br>
><br>
> var myClosure = {} // is a variable of type () -> ()<br>
><br>
><br>
> ><br>
> > --<br>
> > Wizard<br>
> > <a href="mailto:james@supmenow.com">james@supmenow.com</a><br>
> > <a href="tel:%2B44%207523%20279%20698" value="+447523279698">+44 7523 279 698</a><br>
> > _______________________________________________<br>
> > swift-evolution mailing list<br>
> > <a href="mailto:swift-evolution@swift.org">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>
><br>
><br>
><br>
> --<br>
> Wizard<br>
> <a href="mailto:james@supmenow.com">james@supmenow.com</a><br>
> <a href="tel:%2B44%207523%20279%20698" value="+447523279698">+44 7523 279 698</a><br>
<br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div><span style="font-size:16px;line-height:19.2px"></span><span style="font-size:12.8px"> Wizard</span><br></div><div><a href="mailto:james@supmenow.com" target="_blank">james@supmenow.com</a></div><div>+44 7523 279 698</div></div></div></div></div></div>
</div>