digitalmars.D.learn - write multiple lines without "\n" with writeln
- Suliman (24/24) Nov 20 2014 In dco source code I have found:
- uri (10/34) Nov 20 2014 "In all string literal forms, an EndOfLine is regarded as a
- bearophile (4/5) Nov 20 2014 And it's a nice handy design.
- Suliman (14/14) Nov 20 2014 I understand it.
- bearophile (14/28) Nov 20 2014 If I compile and run this program:
- Adam D. Ruppe (11/20) Nov 20 2014 There's no quoted newline there. You could do:
- uri (6/11) Nov 20 2014 For Wysiwyg strings I agree that it's great but I prefer
- Ary Borenszweig (16/29) Nov 20 2014 In Crystal we chose the following: you can have two consecutive string
- ketmar via Digitalmars-d-learn (5/8) Nov 21 2014 On Thu, 20 Nov 2014 14:23:23 -0300
- "Marc =?UTF-8?B?U2Now7x0eiI=?= <schuetzm gmx.net> (6/15) Nov 21 2014 AFAIK yes. There was a change to guarantee that string literals
- Ary Borenszweig (2/16) Nov 21 2014 What's concatenation by juxtaposition?
- Adam D. Ruppe (5/6) Nov 21 2014 When "foo" "bar" turns into "foobar". The two string literals are
- Ary Borenszweig (4/9) Nov 21 2014 Ah, I see. Yes, I guess that's a bug-prone thing to have. And since
In dco source code I have found: void ShowUsage() { writeln(" dco build tool " ~ strVersion ~ " written by FrankLIKE. Usage: dco [<switches...>] <files...> for example: dco or: dco app.d build for dfl2: dco .... } I do not see here any "\n". Why this code is output all one by line, and not in single line? Why my code: writeln("App name:" ~ appName ~ "App version:" ~ appVersion ~ "To see help please use -h\\-help option"); writeln(args); output: App name:CoolAppApp version:0.0.1To see help please use -h\-help option[".\\app1 .exe"]
Nov 20 2014
On Thursday, 20 November 2014 at 08:28:11 UTC, Suliman wrote:In dco source code I have found: void ShowUsage() { writeln(" dco build tool " ~ strVersion ~ " written by FrankLIKE. Usage: dco [<switches...>] <files...> for example: dco or: dco app.d build for dfl2: dco .... } I do not see here any "\n". Why this code is output all one by line, and not in single line? Why my code: writeln("App name:" ~ appName ~ "App version:" ~ appVersion ~ "To see help please use -h\\-help option"); writeln(args); output: App name:CoolAppApp version:0.0.1To see help please use -h\-help option[".\\app1 .exe"]"In all string literal forms, an EndOfLine is regarded as a single \n character." http://dlang.org/lex.html It's by design but is *really* annoying and should be limited to WysiwygString literals IMO. Auto-formatting with clang-format or astyle can mess up writeln formatting completely. Cheers, uri
Nov 20 2014
uri:It's by designAnd it's a nice handy design. Bye, bearophile
Nov 20 2014
I understand it. I expect what concatenation symbol will stay new line in new line and not append it's to current: writeln( "first string" "second" ~ "string" ); I expect: first string second" string" but not: first stringsecondstring
Nov 20 2014
Suliman:I understand it. I expect what concatenation symbol will stay new line in new line and not append it's to current: writeln( "first string" "second" ~ "string" ); I expect: first string second" string" but not: first stringsecondstringIf I compile and run this program: void main() { import std.stdio; writeln( "first string" "second" ~ "string" ); } I see this output (and it's correct, as expected): first stringsecondstring Bye, bearophile
Nov 20 2014
On Thursday, 20 November 2014 at 11:08:24 UTC, Suliman wrote:writeln( "first string" "second" ~ "string" ); I expect: first string second" string"There's no quoted newline there. You could do: writeln( "first string second string"); with the newlines enclosed in the quotes, then you'd get what you want. (There's no extra indenting in my example because the indent would show up too when inside quotes) But if it isn't in the quotes, newlines are basically ignored by the compiler like any other whitespace in the code.
Nov 20 2014
On Thursday, 20 November 2014 at 10:41:24 UTC, bearophile wrote:uri:For Wysiwyg strings I agree that it's great but I prefer C/C++/Python like behaviour for double quoted strings. I guess it's what I'm used to :) Cheers, uriIt's by designAnd it's a nice handy design. Bye, bearophile
Nov 20 2014
On 11/20/14, 9:05 AM, uri wrote:On Thursday, 20 November 2014 at 10:41:24 UTC, bearophile wrote:In Crystal we chose the following: you can have two consecutive string literals but only if they are separated by a `\` at the end of the line. So this is a syntax error: foo("bar" "baz") But this is ok: foo("bar" \ "baz") Likewise, this is an error: But this is ok: ["foo", "bar" \ "baz", "qux"] This way you avoid silly typing mistakes while at the same time you allow splitting a string across several lines without having to concatenate them at runtime.uri:For Wysiwyg strings I agree that it's great but I prefer C/C++/Python like behaviour for double quoted strings. I guess it's what I'm used to :) Cheers, uriIt's by designAnd it's a nice handy design. Bye, bearophile
Nov 20 2014
On Thu, 20 Nov 2014 14:23:23 -0300 Ary Borenszweig via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> wrote:This way you avoid silly typing mistakes while at the same time you=20 allow splitting a string across several lines without having to=20 concatenate them at runtime.i bet that current D frontend is able to concatenate string literals in compile time.
Nov 21 2014
On Friday, 21 November 2014 at 15:00:31 UTC, ketmar via Digitalmars-d-learn wrote:On Thu, 20 Nov 2014 14:23:23 -0300 Ary Borenszweig via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> wrote:AFAIK yes. There was a change to guarantee that string literals concatenated by ~ are joined at compile time. The goal was to deprecated concatenation by juxtaposition, which hasn't happened yet, though.This way you avoid silly typing mistakes while at the same time you allow splitting a string across several lines without having to concatenate them at runtime.i bet that current D frontend is able to concatenate string literals in compile time.
Nov 21 2014
On 11/21/14, 1:59 PM, "Marc Schütz" <schuetzm gmx.net>" wrote:On Friday, 21 November 2014 at 15:00:31 UTC, ketmar via Digitalmars-d-learn wrote:What's concatenation by juxtaposition?On Thu, 20 Nov 2014 14:23:23 -0300 Ary Borenszweig via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> wrote:AFAIK yes. There was a change to guarantee that string literals concatenated by ~ are joined at compile time. The goal was to deprecated concatenation by juxtaposition, which hasn't happened yet, though.This way you avoid silly typing mistakes while at the same time you allow splitting a string across several lines without having to concatenate them at runtime.i bet that current D frontend is able to concatenate string literals in compile time.
Nov 21 2014
On Friday, 21 November 2014 at 17:43:27 UTC, Ary Borenszweig wrote:What's concatenation by juxtaposition?When "foo" "bar" turns into "foobar". The two string literals are right next to each other, no operator or anything else in between, so they are combined.
Nov 21 2014
On 11/21/14, 2:46 PM, Adam D. Ruppe wrote:On Friday, 21 November 2014 at 17:43:27 UTC, Ary Borenszweig wrote:Ah, I see. Yes, I guess that's a bug-prone thing to have. And since there's already `~` to concatenate strings (even at compile time) removing that feature would be good.What's concatenation by juxtaposition?When "foo" "bar" turns into "foobar". The two string literals are right next to each other, no operator or anything else in between, so they are combined.
Nov 21 2014