<div dir="ltr">On Mon, Jul 11, 2016 at 1:41 AM, David Sweeris via swift-evolution <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><div>The existing literals are both few and pretty foundational to programming, so I don't mind them being slightly "magical". Rather than introducing another dozen "magic" types, wouldn't it be better to allow custom literal types, and have all these types use that system?<br></div></div></blockquote><div><br></div><div>+1 to a design for that.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><div><br>- Dave Sweeris</div><div><div class="h5"><div><br>On Jul 10, 2016, at 22:48, Erica Sadun via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:<br><br></div><blockquote type="cite"><div>This is purely additive and would not be eligible for Swift 3. <div>gist: <a href="https://gist.github.com/erica/c92f6ab115af89d5c4b9161487df6a3c" target="_blank">https://gist.github.com/erica/c92f6ab115af89d5c4b9161487df6a3c</a><br><div><br></div><div>-- E</div></div><div><br></div><div><h1 style="font-size:2.25em;margin-right:0px;margin-bottom:16px;margin-left:0px;line-height:1.2;padding-bottom:0.3em;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(238,238,238);color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';background-color:rgb(255,255,255);margin-top:0px!important">Extending Swift Literals</h1><ul style="padding-left:2em;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)"><li>Proposal: TBD</li><li>Author: <a href="http://github.com/erica" style="background-color:transparent;color:rgb(64,120,192);text-decoration:none" target="_blank">Erica Sadun</a></li><li>Status: TBD</li><li>Review manager: TBD</li></ul><h2 style="margin-top:1em;margin-bottom:16px;line-height:1.225;font-size:1.75em;padding-bottom:0.3em;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(238,238,238);color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';background-color:rgb(255,255,255)"><a href="https://gist.github.com/erica/c92f6ab115af89d5c4b9161487df6a3c#introduction" style="background-color:transparent;color:rgb(64,120,192);text-decoration:none;display:inline-block;padding-right:2px;line-height:1" target="_blank"><u></u><u></u><u></u><u></u></a>Introduction</h2><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)">This proposal expands Swift's language literals to include common cross-platform concepts that need not require.</p><h2 style="margin-top:1em;margin-bottom:16px;line-height:1.225;font-size:1.75em;padding-bottom:0.3em;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(238,238,238);color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';background-color:rgb(255,255,255)"><a href="https://gist.github.com/erica/c92f6ab115af89d5c4b9161487df6a3c#motivation" style="background-color:transparent;color:rgb(64,120,192);text-decoration:none;display:inline-block;padding-right:2px;line-height:1" target="_blank"><u></u><u></u><u></u><u></u></a>Motivation</h2><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)">A Swift literal represents a fixed value in source code. A literal can be a string, a number (for example an integer), a compound value (such as an array), or one of several predefined "playground" literals including colors, resource file paths, and resource images.</p><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)">Swift literals do not have types. They are universal representations that are evaluated and their types inferred from the context in which they are used. Because their nature is typeless, the same color literal can initialize <code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px">UIColor</code>, <code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px">NSColor</code>, and <code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px">SKColor</code> instances. The type cannot be inferred from the source without the context of its destination.</p><pre style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;margin-top:0px;margin-bottom:16px;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(247,247,247);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;color:rgb(51,51,51)"><code style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;padding:0px;margin:0px;background-color:transparent;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;word-break:normal;border:0px;display:inline;overflow:visible;line-height:inherit;word-wrap:normal">let color = #colorLiteral(red: 0.8100712299, green: 0.1511939615, blue: 0.<a href="tel:4035313427" value="+14035313427" target="_blank">4035313427</a>, alpha: 1)
</code></pre><h2 style="margin-top:1em;margin-bottom:16px;line-height:1.225;font-size:1.75em;padding-bottom:0.3em;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(238,238,238);color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';background-color:rgb(255,255,255)"><a href="https://gist.github.com/erica/c92f6ab115af89d5c4b9161487df6a3c#detailed-design" style="background-color:transparent;color:rgb(64,120,192);text-decoration:none;display:inline-block;padding-right:2px;line-height:1" target="_blank"><u></u><u></u><u></u><u></u></a>Detailed Design</h2><table style="border-spacing:0px;border-collapse:collapse;margin-top:0px;margin-bottom:16px;display:block;width:888px;overflow:auto;word-break:keep-all;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)"><tbody><tr width="500" style="border-top-width:1px;border-top-style:solid;border-top-color:rgb(204,204,204)"><th colspan="3" style="padding:6px 13px;border:1px solid rgb(221,221,221)"><i>Namespace redesign<i></i></i></th></tr><tr width="500" style="background-color:rgb(248,248,248);border-top-width:1px;border-top-style:solid;border-top-color:rgb(204,204,204)"><th width="100" style="padding:6px 13px;border:1px solid rgb(221,221,221)">Kind</th><th width="200" style="padding:6px 13px;border:1px solid rgb(221,221,221)">Literal</th><th width="200" style="padding:6px 13px;border:1px solid rgb(221,221,221)">Parameters</th></tr><tr width="500" style="border-top-width:1px;border-top-style:solid;border-top-color:rgb(204,204,204)"><td width="100" style="padding:6px 13px;border:1px solid rgb(221,221,221)">Color</td><td width="200" style="padding:6px 13px;border:1px solid rgb(221,221,221)">`#literal.color(red:, green:, blue:, alpha:)`</td><td width="200" style="padding:6px 13px;border:1px solid rgb(221,221,221)">floating point values</td></tr><tr width="500" style="background-color:rgb(248,248,248);border-top-width:1px;border-top-style:solid;border-top-color:rgb(204,204,204)"><td width="100" style="padding:6px 13px;border:1px solid rgb(221,221,221)">Image</td><td width="200" style="padding:6px 13px;border:1px solid rgb(221,221,221)">`#literal.image(resourceName:)`</td><td width="200" style="padding:6px 13px;border:1px solid rgb(221,221,221)">String with resource name</td></tr><tr width="500" style="border-top-width:1px;border-top-style:solid;border-top-color:rgb(204,204,204)"><td width="100" style="padding:6px 13px;border:1px solid rgb(221,221,221)">File</td><td width="200" style="padding:6px 13px;border:1px solid rgb(221,221,221)">`#literal.file(resourceName:)`</td><td width="200" style="padding:6px 13px;border:1px solid rgb(221,221,221)">String with resource name</td></tr><tr width="500" style="background-color:rgb(248,248,248);border-top-width:1px;border-top-style:solid;border-top-color:rgb(204,204,204)"><th colspan="3" style="padding:6px 13px;border:1px solid rgb(221,221,221)"><i>General<i></i></i></th></tr><tr width="500" style="border-top-width:1px;border-top-style:solid;border-top-color:rgb(204,204,204)"><th width="100" style="padding:6px 13px;border:1px solid rgb(221,221,221)">Kind</th><th width="200" style="padding:6px 13px;border:1px solid rgb(221,221,221)">Literal</th><th width="200" style="padding:6px 13px;border:1px solid rgb(221,221,221)">Parameters</th></tr><tr style="background-color:rgb(248,248,248);border-top-width:1px;border-top-style:solid;border-top-color:rgb(204,204,204)"><td width="100" style="padding:6px 13px;border:1px solid rgb(221,221,221)">Sound</td><td width="200" style="padding:6px 13px;border:1px solid rgb(221,221,221)">`#literal.audio(resourceName:)`</td><td width="200" style="padding:6px 13px;border:1px solid rgb(221,221,221)">String with resource name</td></tr><tr width="500" style="border-top-width:1px;border-top-style:solid;border-top-color:rgb(204,204,204)"><td width="100" style="padding:6px 13px;border:1px solid rgb(221,221,221)">URL</td><td width="200" style="padding:6px 13px;border:1px solid rgb(221,221,221)">`#literal.url(string:)`, `#literal.url(filePath:)`</td><td width="200" style="padding:6px 13px;border:1px solid rgb(221,221,221)">String with resource location</td></tr><tr width="500" style="background-color:rgb(248,248,248);border-top-width:1px;border-top-style:solid;border-top-color:rgb(204,204,204)"><td width="100" style="padding:6px 13px;border:1px solid rgb(221,221,221)">Font</td><td width="200" style="padding:6px 13px;border:1px solid rgb(221,221,221)">`#literal.font(face:, size:)`</td><td width="200" style="padding:6px 13px;border:1px solid rgb(221,221,221)">string, floating point</td></tr><tr width="500" style="border-top-width:1px;border-top-style:solid;border-top-color:rgb(204,204,204)"><td width="100" style="padding:6px 13px;border:1px solid rgb(221,221,221)">Date</td><td width="200" style="padding:6px 13px;border:1px solid rgb(221,221,221)">`#literal.date(timeInterval:)`</td><td width="200" style="padding:6px 13px;border:1px solid rgb(221,221,221)">floating point offset from Unix epoch</td></tr><tr width="500" style="background-color:rgb(248,248,248);border-top-width:1px;border-top-style:solid;border-top-color:rgb(204,204,204)"><td width="100" style="padding:6px 13px;border:1px solid rgb(221,221,221)">Unicode</td><td width="200" style="padding:6px 13px;border:1px solid rgb(221,221,221)">`#literal.unicode(name:)`</td><td width="200" style="padding:6px 13px;border:1px solid rgb(221,221,221)">Official unicode name, e.g. `#literal.unicode(name:"DOG FACE")`</td></tr><tr width="500" style="border-top-width:1px;border-top-style:solid;border-top-color:rgb(204,204,204)"><th colspan="3" style="padding:6px 13px;border:1px solid rgb(221,221,221)"><i>Geometry<i></i></i></th></tr><tr width="500" style="background-color:rgb(248,248,248);border-top-width:1px;border-top-style:solid;border-top-color:rgb(204,204,204)"><th width="100" style="padding:6px 13px;border:1px solid rgb(221,221,221)">Kind</th><th width="200" style="padding:6px 13px;border:1px solid rgb(221,221,221)">Literal</th><th width="200" style="padding:6px 13px;border:1px solid rgb(221,221,221)">Parameters</th></tr><tr width="500" style="border-top-width:1px;border-top-style:solid;border-top-color:rgb(204,204,204)"><td width="100" style="padding:6px 13px;border:1px solid rgb(221,221,221)">Point</td><td width="200" style="padding:6px 13px;border:1px solid rgb(221,221,221)">`#literal.point(x:, y:)`, `#literal.point(x:, y:, z:)`, `#literal.point(x:, y:, z:, w:)`</td><td width="200" style="padding:6px 13px;border:1px solid rgb(221,221,221)">floating point values</td></tr><tr width="500" style="background-color:rgb(248,248,248);border-top-width:1px;border-top-style:solid;border-top-color:rgb(204,204,204)"><td width="100" style="padding:6px 13px;border:1px solid rgb(221,221,221)">Vector</td><td width="200" style="padding:6px 13px;border:1px solid rgb(221,221,221)">`#literal.vector(dx:, dy:)`, `#literal.vector(dx:, dy:, dz:)`, `#literal.vector(dx:, dy:, dz:, dw:)`</td><td width="200" style="padding:6px 13px;border:1px solid rgb(221,221,221)">floating point</td></tr><tr width="500" style="border-top-width:1px;border-top-style:solid;border-top-color:rgb(204,204,204)"><td width="100" style="padding:6px 13px;border:1px solid rgb(221,221,221)">Size</td><td width="200" style="padding:6px 13px;border:1px solid rgb(221,221,221)">`#literal.size(width:, height:)`, `#literal.size(width:, height:, depth:)` </td><td width="200" style="padding:6px 13px;border:1px solid rgb(221,221,221)">floating point</td></tr><tr width="500" style="background-color:rgb(248,248,248);border-top-width:1px;border-top-style:solid;border-top-color:rgb(204,204,204)"><td width="100" style="padding:6px 13px;border:1px solid rgb(221,221,221)">Rect</td><td width="200" style="padding:6px 13px;border:1px solid rgb(221,221,221)">`#literal.rect(x:, y:, width:, height:)`</td><td width="200" style="padding:6px 13px;border:1px solid rgb(221,221,221)">floating point</td></tr><tr width="500" style="border-top-width:1px;border-top-style:solid;border-top-color:rgb(204,204,204)"><td width="100" style="padding:6px 13px;border:1px solid rgb(221,221,221)">Affine Transform</td><td width="200" style="padding:6px 13px;border:1px solid rgb(221,221,221)">`#literal.affineTransform(a:,b:,c:,d:,tx:,ty:)`, `#literal.affineTransform(translateX:, translateY:)`, `#literal.affineTransform(scaleY:, scaleY:)`, `#literal.affineTransform(rotation:)`, </td><td width="200" style="padding:6px 13px;border:1px solid rgb(221,221,221)">floating point</td></tr><tr style="background-color:rgb(248,248,248);border-top-width:1px;border-top-style:solid;border-top-color:rgb(204,204,204)"><td width="100" style="padding:6px 13px;border:1px solid rgb(221,221,221)">Bezier Path</td><td width="200" style="padding:6px 13px;border:1px solid rgb(221,221,221)">`#literal.bezier("M92.21,24.29H75L73,17a8.32,8.32, 0,0,0-8.27-6.74H34.55A7.69,7.69,0,0,0,27,16.6l-2.08 4z")`</td><td width="200" style="padding:6px 13px;border:1px solid rgb(221,221,221)">String with SVG path notation</td></tr></tbody></table><h4 style="margin-top:1em;margin-bottom:16px;line-height:1.4;font-size:1.25em;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';background-color:rgb(255,255,255)"><a href="https://gist.github.com/erica/c92f6ab115af89d5c4b9161487df6a3c#not-included" style="background-color:transparent;color:rgb(64,120,192);text-decoration:none;display:inline-block;padding-right:2px;line-height:1.2" target="_blank"><u></u><u></u><u></u><u></u></a>Not included:</h4><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)"><span>Attributed Strings</span>: I would like to see a way to define attributed strings (using some system like CSS/HTML) but could not think up a simple representation similar to the others mentioned in the preceding table.</p><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)"><span>JSON Literals</span>: Again, probably too complex and possibly not worth their weight. If they could exist, they'd have to be imported via a resource or URL and transformed to a local type.</p><h2 style="margin-top:1em;margin-bottom:16px;line-height:1.225;font-size:1.75em;padding-bottom:0.3em;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(238,238,238);color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';background-color:rgb(255,255,255)"><a href="https://gist.github.com/erica/c92f6ab115af89d5c4b9161487df6a3c#impact-on-existing-code" style="background-color:transparent;color:rgb(64,120,192);text-decoration:none;display:inline-block;padding-right:2px;line-height:1" target="_blank"><u></u><u></u><u></u><u></u></a>Impact on Existing Code</h2><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)">This proposal is purely additive.</p><h2 style="margin-top:1em;margin-bottom:16px;line-height:1.225;font-size:1.75em;padding-bottom:0.3em;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(238,238,238);color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';background-color:rgb(255,255,255)"><a href="https://gist.github.com/erica/c92f6ab115af89d5c4b9161487df6a3c#alternatives-considered" style="background-color:transparent;color:rgb(64,120,192);text-decoration:none;display:inline-block;padding-right:2px;line-height:1" target="_blank"><u></u><u></u><u></u><u></u></a>Alternatives Considered</h2><div style="margin-top:0px;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255);margin-bottom:0px!important">Using distinct literal names without subsuming them into a namespaced umbrella.</div></div></div></blockquote></div></div><blockquote type="cite"><div><span>_______________________________________________</span><span class=""><br><span>swift-evolution mailing list</span><br><span><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a></span><br><span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br></span></div></blockquote></div><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></blockquote></div><br></div></div>