<div dir="ltr">And it seems no one like the #let idea, then how about just reuse typealias, or simple let?<div><br></div><div>typealias #text = #string(escape: "$")</div><div><br></div><div>or </div><div><br></div><div>let #text = #string(escape: "$")</div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">2016-03-24 21:43 GMT+08:00 Steve K. Chiu <span dir="ltr"><<a href="mailto:steve.k.chiu@gmail.com" target="_blank">steve.k.chiu@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5"><div dir="ltr"><div class="gmail_quote"><br><div dir="ltr">Perl are using heredoc notation, for example:<div><br></div><div><div>my $message = <<'END_MESSAGE';</div><div>void main() {</div><div> printf("%s\n", "hello world");</div><div>}</div><div>END_MESSAGE<br></div></div><div><br></div><div>or Perl6 </div><div><br></div><div><a href="https://doc.perl6.org/language/quoting" target="_blank">https://doc.perl6.org/language/quoting</a><br></div><div><br></div><div>Lua's multi-line raw string look like this: </div><div>(you can add extra = inside [[ and ]], in case the text contains [[ or ]])</div><div><br></div><div>local message = [[</div><div><div>void main() {</div><div> printf("%s\n", "hello world");</div><div>}</div><div>]]<br></div></div><div><br></div><div>or with ]] in text:</div><div><br></div><div>local message = [===[</div><div><div><div>void main() {</div><div> printf("[[%s]]\n", "hello world");</div><div>}</div><div>]===]<br></div></div></div><div><br></div><div>And C++11 raw string has the same mechanism as Lua (but does not remove first/last newline)</div><div><br></div><div>auto message = R"(void main() {</div><div> printf("[[%s]]\n", "hello world");</div><div>})";</div><div><br></div><div>or with )" in text:</div><div><br></div><div><div>auto message = R"===(void main() {</div><div> printf("(%s)", "hello world");</div><div>})===";</div></div><div><br></div><div><br></div><div>I think adding extra tag inside the string deliminator is actually a good idea, I would like to revise the proposal as:</div><div><br></div><div>#string(options) ``text``</div><div><br></div><div>And then you can add extra tag inside back-quote, just like Lua and C++11 raw strings, so the shortest version would look like:</div><div><br></div><div>``^\d+``</div><div><br></div><div>It is raw string (escape is disabled), useful for regexp immediately, and if you need to write `` inside the string:</div><div><br></div><div><div>let message = </div><div>`==`</div><div>void main() {</div><div> printf("``(%s)``", "hello world");</div><div>}</div><div>`==`</div></div><div><br></div><div>or with options:</div><div><br></div><div>let message =</div><div>#string(escape: "$")</div><div>``</div><div>void main() {</div><div> printf("(%s)", "$(value)");</div><div>}</div><div>``</div><div><br></div><div><br></div><div><br></div></div><div><div><div class="gmail_extra"><br><div class="gmail_quote">2016-03-24 19:46 GMT+08:00 Step C <span dir="ltr"><<a href="mailto:schristopher@bignerdranch.com" target="_blank">schristopher@bignerdranch.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Happy to see someone with a proposal on this!<br>
<span><br>
> On Mar 23, 2016, at 12:49 AM, Steve K. Chiu via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:<br>
><br>
> Hi,<br>
><br>
> I am new to swift-evolution list, here is my draft proposal for the multi-line string literal problem.<br>
> The idea had been discussed in the list before, but it seems there are no real solution to many of the string literal problem.<br>
> Let's first define what are the problem with string literal:<br>
><br>
> 1. should be able to disable escape char<br>
><br>
> 2. or better, able to replace escape char with user defined char<br>
</span>Yes!<br>
<span>><br>
> 3. should be able to write multi-line string literal, and is copy-paste friendly<br>
><br>
> 4. for multi-line string, should be able to remove first and last newline char, so user can write string in block<br>
><br>
> 5. for multi-line string, should be able to remove leading indent, or remove all indent<br>
><br>
> 6. for multi-line string, should be able to replace newline with user defined string ("\r\n", "\r", "\r", or simply " ")<br>
><br>
> 7. should be able to add feature over time, without breaking existing code<br>
><br>
> My proposal to the above problem is to introduce new 'process instruction' (not sure how to call it), in the following form:<br>
><br>
> #string(options) "text"<br>
<br>
</span>Building on our meaning for # as compile-time magic. Ok.<br>
<div><div>><br>
> for example:<br>
><br>
> #string(escape: nil) "^\d+"<br>
><br>
> #string(escape: "$", end: "<EOF>") "<br>
> $(username),<br>
> Is it 1358 yet?<br>
> <EOF>"<br>
><br>
> It is possible to add many options list above, and you can add more options over time without breaking code.<br>
><br>
> #string(<br>
> escape: Character? = "\\",<br>
> end: String? = nil,<br>
> skipEnclosureNewline: Bool = true,<br>
> skipLeadingIndent: Bool = true,<br>
> skipAllIndent: Bool = false,<br>
> newline: String? = nil<br>
> )<br>
><br>
> for 1. & 2., escape option to replace escape char, pass nil will disable escape.<br>
><br>
> for 3., end option for end-of-string mark, pass nil will disable multi-line processing.<br>
><br>
> for 4., skipEnclosureNewline will skip newline if it is the first or last char of the string.<br>
><br>
> for 5., skipLeadingIndent will skip leading indent, leading indent is the leading white-spaces of first line of multi-line string.<br>
><br>
> for 5., skipAllIndent will skip all indent, this will override skipLeadingIndent.<br>
><br>
> for 6., newline option to replace newline char in multi-line string, pass nil will disable the replacement (as-is in the source).<br>
><br>
> But there are one problem remain, as you can see, the #string with options will become very long; I don't think it is a pleasure to use such expression except for one time literal. To fix the problem, I propose yet another process instruction:<br>
><br>
> #let #rex = #string(escape: nil)<br>
> #let #mail = #string(escape: "$", end: "<EOF>")<br>
><br>
> Now you can write the string as:<br>
><br>
> #rex "^\d+"<br>
><br>
> #mail "<br>
> $(username),<br>
> Is it 1358 yet?<br>
> <EOF>"<br>
><br>
> #let should be able to be used with other # process instruction as well, for example, #available, among other things.<br>
><br>
> What do you think?<br>
<br>
</div></div>I'd like to see a comparison to how other languages, particularly Perl, handle this. I like Chris Lattner's vision for this to be the power-user version of string literals. As you identified, a problem with this solution is verbosity / noisiness. I don't like the #let #token syntax on first blush - seems macro-ish to me. But I don't have a better suggestion right now. Hmmm.<br>
<div><div><br>
<br>
><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></div><br></div>
</div></div></blockquote></div><br></div>