www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - D string interpolation

reply Imperatorn <johan_forsberg_86 hotmail.com> writes:
Are there any easy ways to achieve string interpolation in D a la 
$"Hello {adjective} world"?

Thanks
Oct 04 2020
next sibling parent reply Mike Parker <aldacron gmail.com> writes:
On Sunday, 4 October 2020 at 13:16:53 UTC, Imperatorn wrote:
 Are there any easy ways to achieve string interpolation in D a 
 la $"Hello {adjective} world"?

 Thanks
Currently, no. There's a DIP from Adam and Steve currently going through the review process. It recently completed the first round of community review. They intend to make significant revisions, so it will require at least one more round of community review before moving forward. DIP 1036: https://github.com/dlang/DIPs/blob/master/DIPs/DIP1036.md The review summary and links to the discussion & feedback threads: https://github.com/dlang/DIPs/blob/master/DIPs/DIP1036.md#reviews DIP 1036 was an iteration on an earlier DIP by Walter that he and Atila ultimately rejected: https://github.com/dlang/DIPs/blob/master/DIPs/rejected/DIP1027.md
Oct 04 2020
next sibling parent Imperatorn <johan_forsberg_86 hotmail.com> writes:
On Sunday, 4 October 2020 at 14:04:04 UTC, Mike Parker wrote:
 On Sunday, 4 October 2020 at 13:16:53 UTC, Imperatorn wrote:
 [...]
Currently, no. There's a DIP from Adam and Steve currently going through the review process. It recently completed the first round of community review. They intend to make significant revisions, so it will require at least one more round of community review before moving forward. DIP 1036: https://github.com/dlang/DIPs/blob/master/DIPs/DIP1036.md The review summary and links to the discussion & feedback threads: https://github.com/dlang/DIPs/blob/master/DIPs/DIP1036.md#reviews DIP 1036 was an iteration on an earlier DIP by Walter that he and Atila ultimately rejected: https://github.com/dlang/DIPs/blob/master/DIPs/rejected/DIP1027.md
Splendid!
Oct 04 2020
prev sibling parent reply bitwise <bitwise.pvt gmail.com> writes:
On Sunday, 4 October 2020 at 14:04:04 UTC, Mike Parker wrote:
 On Sunday, 4 October 2020 at 13:16:53 UTC, Imperatorn wrote:
 [...]
[...] so it will require at least one more round of community review before moving forward. DIP 1036: https://github.com/dlang/DIPs/blob/master/DIPs/DIP1036.md
I hope they change the syntax to favor readers of code, not writers. As with D's templates, reading code is made more difficult by needlessly adding syntactical variations for language features. Example: writefln(i"I ate $apples and ${%d}bananas totaling $(apples + bananas) fruit.");
 $apples
 $(apples + bananas)
If I was trying to quickly scan code to pick out variables, there's two different things I would have to look for. Example:
 Foo!int
 Foo!(bool, int)
Same problem.
 Foo;
 Foo();
Same problem. I'm not sure if the reasoning is to try and reduce noise in the "common" case, or to appease people that think not having to type () will actually help them get things done faster, but neither reason seems valid to me. Also, why would the less significant part of the construct be in the curly braces?
 ${%d}bananas
Why not like this?
 i"{apples} bar"
 i"{apples + bananas} bar"
 i"{bananas:%d} bar"
 Bar!(int)
 Bar!(bool, int)
 Bar();
 Bar();
In all honesty, part of the reason I lost interest in D is because of the type of quirks listed above. I don't believe the intended benefit, whatever it may be, is worth the sacrifice of consistency.
Oct 04 2020
parent reply Adam D. Ruppe <destructionator gmail.com> writes:
On Sunday, 4 October 2020 at 17:53:55 UTC, bitwise wrote:
 I hope they change the syntax
The new draft ditches most the old syntax. Not much point talking about it until it is released though, but you'll probably like the new draft a lot more.
Oct 04 2020
parent bitwise <bitwise.pvt gmail.com> writes:
On Sunday, 4 October 2020 at 18:09:15 UTC, Adam D. Ruppe wrote:
 On Sunday, 4 October 2020 at 17:53:55 UTC, bitwise wrote:
 I hope they change the syntax
The new draft ditches most the old syntax. Not much point talking about it until it is released though, but you'll probably like the new draft a lot more.
Thanks =D Awesome.
Oct 04 2020
prev sibling next sibling parent reply Paul Backus <snarwin gmail.com> writes:
On Sunday, 4 October 2020 at 13:16:53 UTC, Imperatorn wrote:
 Are there any easy ways to achieve string interpolation in D a 
 la $"Hello {adjective} world"?

 Thanks
https://code.dlang.org/packages/scriptlike#string-interpolation
Oct 04 2020
parent Imperatorn <johan_forsberg_86 hotmail.com> writes:
On Sunday, 4 October 2020 at 14:19:17 UTC, Paul Backus wrote:
 On Sunday, 4 October 2020 at 13:16:53 UTC, Imperatorn wrote:
 Are there any easy ways to achieve string interpolation in D a 
 la $"Hello {adjective} world"?

 Thanks
https://code.dlang.org/packages/scriptlike#string-interpolation
Looks like an acceptable workaround for now. Thanks!
Oct 04 2020
prev sibling parent reply mw <mingwu gmail.com> writes:
On Sunday, 4 October 2020 at 13:16:53 UTC, Imperatorn wrote:
 Are there any easy ways to achieve string interpolation in D a 
 la $"Hello {adjective} world"?
I also have one: https://code.dlang.org/packages/jdiutil ``` // multiple vars separated by ';' // _S with var name; _s without var name writeln(mixin(_S!"with var name: {i; d; thePoint}")); writeln(mixin(_s!"without var name: {i; d; thePoint}")); ```
Oct 04 2020
parent reply Imperatorn <johan_forsberg_86 hotmail.com> writes:
On Sunday, 4 October 2020 at 16:27:59 UTC, mw wrote:
 On Sunday, 4 October 2020 at 13:16:53 UTC, Imperatorn wrote:
 Are there any easy ways to achieve string interpolation in D a 
 la $"Hello {adjective} world"?
I also have one: https://code.dlang.org/packages/jdiutil ``` // multiple vars separated by ';' // _S with var name; _s without var name writeln(mixin(_S!"with var name: {i; d; thePoint}")); writeln(mixin(_s!"without var name: {i; d; thePoint}")); ```
Cool
Oct 04 2020
parent mw <mingwu gmail.com> writes:
On Sunday, 4 October 2020 at 16:31:50 UTC, Imperatorn wrote:
 On Sunday, 4 October 2020 at 16:27:59 UTC, mw wrote:
 On Sunday, 4 October 2020 at 13:16:53 UTC, Imperatorn wrote:
 Are there any easy ways to achieve string interpolation in D 
 a la $"Hello {adjective} world"?
I also have one: https://code.dlang.org/packages/jdiutil ``` // multiple vars separated by ';' // _S with var name; _s without var name writeln(mixin(_S!"with var name: {i; d; thePoint}")); writeln(mixin(_s!"without var name: {i; d; thePoint}")); ```
multiple vars separated by ';' because, you can also pass in `funcCAll(arg, arg2)`
Oct 04 2020