April 04, 2017
On Tuesday, 4 April 2017 at 05:36:55 UTC, evilrat wrote:
> On Tuesday, 4 April 2017 at 05:18:26 UTC, Dukc wrote:
>> On Tuesday, 4 April 2017 at 02:43:26 UTC, evilrat wrote:
>>> [...]
>>
>> But if all you want is to construct some code in interpreter-like way at compile time, string mixin does precisely that.
>
> No, just static symbols will be enough. Not really interpreter but common day-to-day things like print some formatted stuff while keep it readable.
>
> I know it is easy to do with string.format() but it'll add more commas, templates, mixins or all at once, which is without decent tools like Visual Assist for C++ doesn't really makes it better.
>
> void printStuff()
> {
> int someInt = calcSmth();
> string someName = getSmthDisplayName();
> // ... do other things ...
> writeln("Your item: {#someName} = {#someInt}");
> }

writeln("Your item: ", someName, " = ", someInt");

????
April 04, 2017
On Tuesday, 4 April 2017 at 05:53:00 UTC, Patrick Schluter wrote:
> On Tuesday, 4 April 2017 at 05:36:55 UTC, evilrat wrote:
>> On Tuesday, 4 April 2017 at 05:18:26 UTC, Dukc wrote:
>>> On Tuesday, 4 April 2017 at 02:43:26 UTC, evilrat wrote:
>>>> [...]
>>>
>
> writeln("Your item: ", someName, " = ", someInt");
>
> ????

This works due to variadic args nature of writeln, but the point is that it might be used with simple string assignment and other functions that takes one string, besides, the point is to avoid clutter and improve readability of code.
April 04, 2017
On Tuesday, 4 April 2017 at 06:13:24 UTC, evilrat wrote:
> On Tuesday, 4 April 2017 at 05:53:00 UTC, Patrick Schluter wrote:
>> On Tuesday, 4 April 2017 at 05:36:55 UTC, evilrat wrote:
>>> On Tuesday, 4 April 2017 at 05:18:26 UTC, Dukc wrote:
>>>> On Tuesday, 4 April 2017 at 02:43:26 UTC, evilrat wrote:
>>>>> [...]
>>>>
>>
>> writeln("Your item: ", someName, " = ", someInt");
>>
>> ????
>
> This works due to variadic args nature of writeln, but the point is that it might be used with simple string assignment and other functions that takes one string, besides, the point is to avoid clutter and improve readability of code.

text("Your item: ", someName, " = ", someInt");
April 04, 2017
On Tuesday, 4 April 2017 at 07:21:09 UTC, Andrea Fontana wrote:
> On Tuesday, 4 April 2017 at 06:13:24 UTC, evilrat wrote:
>> On Tuesday, 4 April 2017 at 05:53:00 UTC, Patrick Schluter wrote:
>>> On Tuesday, 4 April 2017 at 05:36:55 UTC, evilrat wrote:
>>>> On Tuesday, 4 April 2017 at 05:18:26 UTC, Dukc wrote:
>>>>> On Tuesday, 4 April 2017 at 02:43:26 UTC, evilrat wrote:
>>>>>> [...]
>>>>>
>>>
>>> writeln("Your item: ", someName, " = ", someInt");
>>>
>>> ????
>>
>> This works due to variadic args nature of writeln, but the point is that it might be used with simple string assignment and other functions that takes one string, besides, the point is to avoid clutter and improve readability of code.
>
> text("Your item: ", someName, " = ", someInt");

Well, thanks, I guess... But it seems no one else interested in such feature. I get it.
Sure this shouldn't be top priority thing and it can(it surely will) be hard to implement in compiler, and this maybe not an option for such a little benefit, but at least I can dream one day it will made it in D, yay.
April 04, 2017
On 4/3/2017 11:24 AM, Meta wrote:
> I don't know how fold expressions could be emulated in D.

http://dlang.org/phobos/std_algorithm_iteration.html#.fold
April 04, 2017
On Tuesday, 4 April 2017 at 08:16:48 UTC, evilrat wrote:
>
> Well, thanks, I guess... But it seems no one else interested in such feature. I get it.
> Sure this shouldn't be top priority thing and it can(it surely will) be hard to implement in compiler, and this maybe not an option for such a little benefit, but at least I can dream one day it will made it in D, yay.

There is a library solution in scriptlike: https://p0nce.github.io/d-idioms/#String-interpolation-as-a-library

I think you only ever miss it when doing web stuff.
April 04, 2017
On Tuesday, 4 April 2017 at 10:40:19 UTC, Guillaume Piolat wrote:
> On Tuesday, 4 April 2017 at 08:16:48 UTC, evilrat wrote:
>>
>> Well, thanks, I guess... But it seems no one else interested in such feature. I get it.
>> Sure this shouldn't be top priority thing and it can(it surely will) be hard to implement in compiler, and this maybe not an option for such a little benefit, but at least I can dream one day it will made it in D, yay.
>
> There is a library solution in scriptlike: https://p0nce.github.io/d-idioms/#String-interpolation-as-a-library
>
> I think you only ever miss it when doing web stuff.

Сool, i was thinking about the same, just make interp with alias and mixin... But this lib has some other interesting functions too! Though not in Phobos, but at least dub makes it super quick to use. Thanks!

No, not web stuff, just quick dirty concepting stuff. Unfortunatelly this days I usually deal with C++ only :/
April 04, 2017
On Tuesday, 4 April 2017 at 02:43:26 UTC, evilrat wrote:
> String interpolation would be nice too, it would really help with readability!

This really isn't in the spirit of D and is better left to library functions which give the user far more power and flexibility. Incorporating such a feature into the language raises many questions and concerns:

* It becomes a language feature thereby further bloating the language and runtime
* What if you want it to be @nogc?
* What if you want to combine it with allocators?
* What if you want to store the result in a particular buffer?
* What if you want the result to be lazily evaluated?
* What if you want an input range of chars? ... that is lazily evaluated?
* What if you want to format the arguments in a specific way?

Given the ease in which such a feature can be implemented and used as a library function, I don't see interpolated strings as being a necessary feature in D.
April 04, 2017
On Tuesday, 4 April 2017 at 05:04:04 UTC, Dukc wrote:
> On Monday, 3 April 2017 at 21:43:41 UTC, Meta wrote:
>> On Monday, 3 April 2017 at 21:33:20 UTC, Timon Gehr wrote:
>> Any suggestions as to how to get something similar working?
>
> auto fold(string op, Args...)(Args args)
> {
>     foreach(e; args[1 .. $]) args[0] += e;
>     return args[0];
> }
>
> void main()
> {
>     import std.stdio;
>     fold!"+"(1, 2, 3).writeln; //6
> }

This does work I guess. I'm not sure if the foreach will be unrolled or not but if it is I guess this is fairly close to the C++ example. However, it's still more verbose. My goal was to emulate almost exactly what C++ was doing by using a template so you could just write "fold!('+', args)" and have it automatically rewritten as "Args[0] + Args[1] + Args[2] ...". However it gets difficult because the compiler is trying to interpret args at compile time.
April 04, 2017
On Tuesday, 4 April 2017 at 08:38:32 UTC, Walter Bright wrote:
> On 4/3/2017 11:24 AM, Meta wrote:
>> I don't know how fold expressions could be emulated in D.
>
> http://dlang.org/phobos/std_algorithm_iteration.html#.fold

Not quite the same as this is a fold over a TypeTuple/AliasSeq. You could of course do:

only(args).fold!"a + b"()

But the semantics are different.