<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=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jun 2, 2017, at 2:11 AM, Jaden Geller <<a href="mailto:jaden.geller@gmail.com" class="">jaden.geller@gmail.com</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="">Comments inline.<br class=""><div class=""><br class=""><div class=""><div class=""><div class=""><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 class=""><br class=""></div><div class="">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 class=""><br class=""></div><div class="">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 class=""><br class=""></div><div class="">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 class=""><br class=""></div><div class="">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 class=""><br class=""></div><div class="">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 class="">```</div><div class="">Sparse([1: “foo”, 5: “bar”, 100: “baz”], default: “”)</div><div class="">```</div></div></div></div></div></div></div></blockquote></div><br class=""><div class="">I’m not asking how to do this in current Swift with current types, but fixed-sized arrays in a future Swift. I’m asking if this mixing of array- and dictionary-literals for these advanced-array literals would be too hard for compiler implementors to implement.</div><div class=""><br class=""></div><div class=""><div class=""><div style="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 class=""><br class=""></div></div></div></div></body></html>