<div dir="ltr"><div>> var s = ""</div><div>> s.append("c")</div><div>></div><div>> This code looks pretty straightforward,</div><div><br></div><div>This looks to me like you're adding a string, which can be done via </div><div><br></div><div>s += "c"</div><div><br></div><div>Yes, I know adding a character can theoretically be a bit more performant, but why would that be a consideration for static strings? Compiler should optimize both expressions above to the same result.</div><div><br></div><div>> UInt : u // or uint</div><div>> Int16 : i16</div><div>> Int32 : i32</div><div><br></div><div>I think </div><div><br></div><div>let number = 56i32</div><div><br></div><div>is much less readable than </div><div><br></div><div>let number: Int32 = 56</div><div><br></div><div>so probably best not to encourage it.</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Dec 12, 2015 at 1:48 AM, Marc Knaup 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:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Too bad that string literals don't conform to a specific protocol.<div><br></div><div>This would also be a nice but doesn't work:</div><div>
<p><font face="monospace, monospace"><span>// </span></font><span style="font-family:monospace,monospace">StaticString:</span><span style="font-family:monospace,monospace"> </span><span style="font-family:monospace,monospace">"An simple string designed to represent text that is 'knowable at compile-time'."<br></span><span style="font-family:monospace,monospace">extension</span><span style="font-family:monospace,monospace"> </span><span style="font-family:monospace,monospace">StaticString</span><span style="font-family:monospace,monospace"> {</span></p><p><font face="monospace, monospace"><span> var</span><span> x: </span><span>Int</span><span> {<br></span><span> return</span><span> </span><span>123<br></span> }<br>}<br><span><br>print</span><span>(</span><span>"abc"</span><span>.x)</span></font><br></p></div></div><div><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Dec 11, 2015 at 11:38 PM, Joe Groff 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:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I was a little disappointed something like this didn't already work:<br>
<br>
struct Foo: StringLiteralConvertible { var f: Foo { return self } }<br>
struct Bar: StringLiteralConvertible { var b: Bar { return self } }<br>
<br>
"x".f // currently a failed lookup in String; could produce a Foo<br>
"y".b // same, for Bar<br>
<br>
-Joe<br>
<span><br>
> On Dec 10, 2015, at 11:07 AM, Kevin Ballard via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:<br>
><br>
</span><div><div>> The fact that Swift uses the exact same syntax ("a") for String, Character, and UnicodeScalar can get annoying at times. When unconstrained it's always String, and the only way to disambiguate between the two when used in a context that takes both Character and UnicodeScalar is to explicitly constraint it further, e.g. with `"a" as Character`. A trivial example of this in action is<br>
><br>
> var s = ""<br>
> s.append("c")<br>
><br>
> This code looks pretty straightforward, but it throws an ambiguity error (and the annoying part is, it doesn't actually matter which way it's resolved, the behavior is the same).<br>
><br>
> Having to type `"c" as Character` and `"c" as UnicodeScalar` can get pretty annoying if you have to do it a lot. It would be great to reduce this typing a bit.<br>
><br>
> My initial proposal here is to introduce string literal suffixes. Let me type something like `"c"c` for a Character and `"c"us` for a UnicodeScalar (and maybe `"c"s` to explicitly mean a String, although that's the default if unconstrained). AFAIK this is not ambiguous with the current syntax, as I don't believe it's ever legal to put an identifier like that after a string.<br>
><br>
> Ideally this could be extended by library code with new suffixes. The obvious way to do that is to allow for a new type of "operator" declaration, perhaps something like `literal operator c { type Character }` (where `literal` is a context-sensitive keyword), which declares the suffix and the type (the actual type construction will be done with StringLiteralConvertible, StringInterpolationConvertible, UnicodeScalarLiteralConvertible, or ExtendedGraphemeClusterLiteralConvertible). If the same suffix is declared in two different modules that are imported into the same program, they're unambiguous within their source modules, and within the parent module using the suffix operator will be ambiguous unless further constrained (e.g. similar to using a function that's overloaded on its return type).<br>
><br>
> One possible library use for this would be something like `"^\s*foo"r ` for a regular expression (although regular expressions probably also want some sort of "raw" string literal syntax to deal with escapes, but that's orthogonal to this proposal).<br>
><br>
> Syntax is up for debate. I picked postfix characters because I believe it's ambiguous and it has precedent, both in C's numeric literals, and in C++11's user-defined literals (although C++11 has a required underscore before the literal, I believe this is just to allow C++11 to define its own new suffixes without ambiguity). This syntax could also work for numeric literals, come to think of it, with the same declaration and using IntegerLiteralConvertible or FloatLiteralConvertible. Heck, it could work for array and dictionary literals too, though that's less likely to be useful.<br>
><br>
> FWIW, Playground color and image literals have the form [#Color(colorLiteralRed: 1, blue: 0, green: 0, alpha: 1)#] and [#Image(imageLiteral: "hi.png")#]. These are interesting, but don't solve the original problem (of having to type out the full type name) so this syntax is not appropriate for this feature (but the syntax is fine for what Playgrounds use it for, which is to embed literal colors/images into the source code).<br>
><br>
> -Kevin Ballard<br>
> _______________________________________________<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>
_______________________________________________<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>
</div></div></blockquote></div><br></div>
</div></div><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=1p9Jer2O6jVE9KWvo-2B9iUaEyN8slp4IizyiLwsfp54OJpALiap2f-2FNHd-2FbuRc-2FiCZLLJzHy4hiIBf0Lx0qBEWHytCuVHqk-2Fym8RT89-2BrzqK2eb28RFug1bry-2FqZxPPcq43tvSMhRIrBpOtfS-2FHIAgKvZLZ30s6aU1yVySNM2F1mU-2FSag0J-2Bl2G90NSSq6-2Bzg8gdu9t86QSAbdTBR7liSr7Uiqee2zM8Sdh0UWkL5BqM-3D" alt="" width="1" height="1" border="0" style="min-height:1px!important;width:1px!important;border-width:0!important;margin-top:0!important;margin-bottom:0!important;margin-right:0!important;margin-left:0!important;padding-top:0!important;padding-bottom:0!important;padding-right:0!important;padding-left:0!important">
<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>