<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Comments inline.<br class=""><div class=""><br class=""><div class=""><div class=""><div><blockquote type="cite" class=""><div class="">On Jun 1, 2017, at 10:49 PM, Daryle Walker via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">Current array literal syntax (i.e. “[a, b, c]”) works for dense and/or linear arrays, but isn’t so great later on when we add fixed-size arrays and the defined (non-zero) elements are sparse and/or the array is multi-dimensional (not nested). In these cases I’m thinking of leading each element with its coordinate:</div><div class=""><br class=""></div><div class="">… 6: a, … // complete value, linear array</div></div></div></blockquote><div><br class=""></div><div>You can already do this with a dictionary since a Int can be used as the key type.</div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">… (1, 2): b, … // complete value, multi-dimensional array</div></div></div></blockquote><div><br class=""></div><div>This would be possible if tuples of hashable types were considered hahable. Right now, you could define some point type.</div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">… (let x, let y) where y % 2 == 0: c * y + x, … // pattern of qualifying coordinates</div></div></div></blockquote><div><br class=""></div><div>You can build this sort of thing using an initializer that takes a function. You wouldn’t get this sugar, but I don’t think it is necessary.</div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">… default: d, … // when no other initializer covers an element (Use “_” instead?)</div></div></div></blockquote><div><br class=""></div><div>This one is a bit harder. I think it would be reasonable for there to exist some subtype of the dictionary literal type that also included information about a default value, but I think this should be motivated by the Swift standard library (e.g. a defaultable dictionary type).</div><div><br class=""></div><div>Right now, you can just make literal syntax default to a `nil` default value, and then you can define a function that nil-coalesces the default value. This is definitely less elegant, but I don’t think it matters a whole lot.</div><div>```</div><div>Sparse([1: “foo”, 5: “bar”, 100: “baz”], default: “”)</div><div>```</div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><br class=""></div><div class="">A complete coordinate beats a pattern, which beats a default. The issue I see here is that I’m using a colon as a separator between the coordinate expression and the value expression. Would that interfere with dictionary literal syntax? Would it help the we’ll most likely have to demand that the object receiving the literal has to have its type specified (with whatever syntax we agree on), as either a declared object with a type annotation or a function parameter (for a function either without overload or with the variant used otherwise made clear)?</div><div class=""><br class=""></div><div class="">
<div style="letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">— </div><div class="">Daryle Walker<br class="">Mac, Internet, and Video Game Junkie<br class="">darylew AT mac DOT com </div></div>
</div>
<br class=""></div>_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></div></div></div><div class="">Cheers,</div><div class="">Jaden Geller</div><div class=""><br class=""></div></body></html>