digitalmars.D.learn - Is this bug ? format %(%)
- novice3 (19/19) Apr 07 2021 https://run.dlang.io/is/p4NVp8
- Paul Backus (5/10) Apr 07 2021 This is actually an intentional feature (albeit kind of a stupid
- novice2 (3/5) Apr 07 2021 sorry i dont read docs so carefully
- Paul Backus (7/13) Apr 07 2021 It's not your fault--this is a pretty obscure feature, and it's
- Berni44 (9/15) Apr 07 2021 The docs of `std.format` are currently under strong revision,
- Meta (4/18) Apr 07 2021 I have created a pull request that will hopefully make this more
- =?UTF-8?Q?Ali_=c3=87ehreli?= (7/14) Apr 07 2021 For the sake of completeness, I mention this feature in a couple of=20
https://run.dlang.io/is/p4NVp8 ```d void main() { import std.stdio: writefln; string[] s = ["a", "b", "c"]; writefln("%(%s, %)", s); } ``` output ```d "a", "b", "c" ``` expected ```d a, b, c ``` there is extra quotes, wich not present in firmat specifier. is this bug, or i should change something in my code?
Apr 07 2021
On Wednesday, 7 April 2021 at 13:31:59 UTC, novice3 wrote:there is extra quotes, wich not present in firmat specifier. is this bug, or i should change something in my code?This is actually an intentional feature (albeit kind of a stupid one). From the documentation:Inside a compound format specifier, strings and characters are escaped automatically. To avoid this behavior, add '-' flag to "%(".So, you should change your code to writefln("%-(%s, %)", s);
Apr 07 2021
On Wednesday, 7 April 2021 at 13:43:18 UTC, Paul Backus wrote:So, you should change your code to writefln("%-(%s, %)", s);sorry i dont read docs so carefully thanks
Apr 07 2021
On Wednesday, 7 April 2021 at 17:04:56 UTC, novice2 wrote:On Wednesday, 7 April 2021 at 13:43:18 UTC, Paul Backus wrote:It's not your fault--this is a pretty obscure feature, and it's not documented very well. Even after you've found the correct page in the documentation (the page for `formattedWrite` [1]), you have to scroll down past multiple examples to find the text that explains it. [1] https://dlang.org/phobos/std_format.html#formattedWriteSo, you should change your code to writefln("%-(%s, %)", s);sorry i dont read docs so carefully thanks
Apr 07 2021
On Wednesday, 7 April 2021 at 17:31:09 UTC, Paul Backus wrote:It's not your fault--this is a pretty obscure feature, and it's not documented very well. Even after you've found the correct page in the documentation (the page for `formattedWrite` [1]), you have to scroll down past multiple examples to find the text that explains it. [1] https://dlang.org/phobos/std_format.html#formattedWriteThe docs of `std.format` are currently under strong revision, about 90% is already done, but that "feature" is among the other 10%. I hope to get that ready till the end of the month, so the next stable release will have better docs. Unfortunately it's much more difficult to change that strange behavior without breaking code. Currently I hope for Phobos 2.0 coming soon and meanwhile try to prepare `std.format` for that change.
Apr 07 2021
On Wednesday, 7 April 2021 at 17:31:09 UTC, Paul Backus wrote:On Wednesday, 7 April 2021 at 17:04:56 UTC, novice2 wrote:I have created a pull request that will hopefully make this more prominent on the doc page: https://github.com/dlang/phobos/pull/7944On Wednesday, 7 April 2021 at 13:43:18 UTC, Paul Backus wrote:It's not your fault--this is a pretty obscure feature, and it's not documented very well. Even after you've found the correct page in the documentation (the page for `formattedWrite` [1]), you have to scroll down past multiple examples to find the text that explains it. [1] https://dlang.org/phobos/std_format.html#formattedWriteSo, you should change your code to writefln("%-(%s, %)", s);sorry i dont read docs so carefully thanks
Apr 07 2021
On 4/7/21 10:04 AM, novice2 wrote:On Wednesday, 7 April 2021 at 13:43:18 UTC, Paul Backus wrote:For the sake of completeness, I mention this feature in a couple of=20 other places: http://ddili.org/ders/d.en/formatted_output.html#ix_formatted_output.%= -( https://www.youtube.com/watch?v=3DdRORNQIB2wA&t=3D1146s AliSo, you should change your code to =C2=A0=C2=A0=C2=A0 writefln("%-(%s, %)", s);=20 sorry i dont read docs so carefully thanks
Apr 07 2021