Re: Interpolated strings

2017-08-25 Thread Seb via Digitalmars-d
On Thursday, 24 August 2017 at 11:57:59 UTC, Petar Kirov [ZombineDev] wrote: On Thursday, 24 August 2017 at 11:07:16 UTC, Suliman wrote: All modern languages like Dart and C# have string interpolation. Sharp example: Console.WriteLine($"Hello {args[0]}!"); Who can summary is there any

Re: Interpolated strings

2017-08-25 Thread Gary Willoughby via Digitalmars-d
On Thursday, 24 August 2017 at 11:07:16 UTC, Suliman wrote: All modern languages like Dart and C# have string interpolation. Sharp example: Console.WriteLine($"Hello {args[0]}!"); Who can summary is there any objective reasons why it's not realized in D? Maybe you ought to read this entire

Re: Interpolated strings

2017-08-24 Thread Biotronic via Digitalmars-d
On Thursday, 24 August 2017 at 11:07:16 UTC, Suliman wrote: All modern languages like Dart and C# have string interpolation. Sharp example: Console.WriteLine($"Hello {args[0]}!"); Who can summary is there any objective reasons why it's not realized in D? As Raymond Chen once said[1],

Re: Interpolated strings

2017-08-24 Thread via Digitalmars-d
On Thursday, 24 August 2017 at 11:07:16 UTC, Suliman wrote: All modern languages like Dart and C# have string interpolation. Sharp example: Console.WriteLine($"Hello {args[0]}!"); Who can summary is there any objective reasons why it's not realized in D? No one has submitted a DIP for that

Re: Interpolated strings

2017-08-24 Thread Suliman via Digitalmars-d
All modern languages like Dart and C# have string interpolation. Sharp example: Console.WriteLine($"Hello {args[0]}!"); Who can summary is there any objective reasons why it's not realized in D?

Re: Interpolated strings

2017-04-21 Thread Kapps via Digitalmars-d
On Thursday, 20 April 2017 at 18:28:30 UTC, Atila Neves wrote: On Monday, 17 April 2017 at 19:38:33 UTC, Kapps wrote: On Saturday, 15 April 2017 at 20:04:13 UTC, Jonas Drewsen wrote: [...] C# got this feature recently. I didn't expect it to be a significant difference, but I do find it a

Re: Interpolated strings

2017-04-21 Thread Nick Sabalausky (Abscissa) via Digitalmars-d
On 04/21/2017 08:45 AM, Gary Willoughby wrote: On Friday, 21 April 2017 at 12:32:01 UTC, Nick Sabalausky (Abscissa) wrote: "Completely unnecessary" features like that are exactly what make D worthwhile in the first place. Otherwise may as well stick to C++ or Java. Multiple ways of doing the

Re: Interpolated strings

2017-04-21 Thread bitwise via Digitalmars-d
On Friday, 21 April 2017 at 12:45:39 UTC, Gary Willoughby wrote: Go and Rust are both smashing D in popularity and user share, maybe we could learn why that's the case. Can't rely on RAII, can't rely on GC. This is the single biggest problem to me. GC performs slowly, and RAII is

Re: Interpolated strings

2017-04-21 Thread Nick Treleaven via Digitalmars-d
then year? Which argument is which?), and interpolated strings have the problem of exposing variable names to the translators (who are probably non-coders), potentially opening up the possibility of arbitrary code execution via l10n strings. This is machine checkable though, the translation

Re: Interpolated strings

2017-04-21 Thread Nick Treleaven via Digitalmars-d
On Thursday, 20 April 2017 at 21:34:44 UTC, Steven Schveighoffer wrote: Dmitry's solution is superior I think: $"{a} times 3 is {a * 3}" -> AliasSeq!(a, " times 3 is ", a * 3) +1, this is more flexible. Would work fine with writeln. Yep, and std.conv.text. We might want a function that

Re: Interpolated strings

2017-04-21 Thread Nick Treleaven via Digitalmars-d
On Thursday, 20 April 2017 at 19:02:20 UTC, Kagamin wrote: Also how various kinds of strings would work? r$"{can}\i\has{slashes}" $`same {here}` r"" and `` are WysiwygStrings. Interpolation is not WYSIWYG. $"" would need to support escaping of the interpolation start character, so may as

Re: Interpolated strings

2017-04-21 Thread Anonymouse via Digitalmars-d
On Friday, 21 April 2017 at 12:45:39 UTC, Gary Willoughby wrote: Multiple ways of doing the same thing are not valuable or progressive. Go and Rust are both smashing D in popularity and user share, maybe we could learn why that's the case. Corporate backing and word-of-mouth? I recall

Re: Interpolated strings

2017-04-21 Thread ketmar via Digitalmars-d
Gary Willoughby wrote: Go and Rust are both smashing D in popularity and user share, maybe we could learn why that's the case. 'cause go backed by google, and rust backed by mozilla.

Re: Interpolated strings

2017-04-21 Thread Gary Willoughby via Digitalmars-d
On Friday, 21 April 2017 at 12:32:01 UTC, Nick Sabalausky (Abscissa) wrote: "Completely unnecessary" features like that are exactly what make D worthwhile in the first place. Otherwise may as well stick to C++ or Java. Multiple ways of doing the same thing are not valuable or progressive.

Re: Interpolated strings

2017-04-21 Thread Nick Sabalausky (Abscissa) via Digitalmars-d
On 04/21/2017 04:11 AM, Gary Willoughby wrote: On Thursday, 20 April 2017 at 18:28:30 UTC, Atila Neves wrote: I don't understand how writeln($"{a} times 3 is {a * 3}"); is even marginally better than writeln(a, " times 3 is ", a * 3); // look ma, works right now! It's not even fewer

Re: Interpolated strings

2017-04-21 Thread Gary Willoughby via Digitalmars-d
On Thursday, 20 April 2017 at 18:28:30 UTC, Atila Neves wrote: I don't understand how writeln($"{a} times 3 is {a * 3}"); is even marginally better than writeln(a, " times 3 is ", a * 3); // look ma, works right now! It's not even fewer characters. Atila This! This is bloat that doesn't

Re: Interpolated strings

2017-04-20 Thread Nick Sabalausky (Abscissa) via Digitalmars-d
10.3f", rec.id, rec.name, rec.amount); writefln(" %20s %10s", rec.altName, rec.comment); writefln(" %20s %6s", rec.address, rec.postalCode); } Meh, I'd argue that's just an example of why interpolated strings need sup

Re: Interpolated strings

2017-04-20 Thread Steven Schveighoffer via Digitalmars-d
On 4/18/17 4:50 AM, Walter Bright wrote: On 4/15/2017 4:51 PM, cym13 wrote: Removing imports is a good point, the first concrete one to be mentionned. I'm not sure it matters that much though as I think those imports are generic enough that I believe they would be imported anyway, but it's a

Re: Interpolated strings

2017-04-20 Thread H. S. Teoh via Digitalmars-d
On Thu, Apr 20, 2017 at 03:32:18PM -0400, Nick Sabalausky (Abscissa) via Digitalmars-d wrote: [...] > IMO, the only time a format string should be used instead of > std.conv.text() or interpolated strings is when: > > 1. You're just rendering *one* value at a time with non-standard

Re: Interpolated strings

2017-04-20 Thread Nick Sabalausky (Abscissa) via Digitalmars-d
s format string syntax was vastly better...for a format string, anyway...) IMO, the only time a format string should be used instead of std.conv.text() or interpolated strings is when: 1. You're just rendering *one* value at a time with non-standard formatting options (ie, left-/right-justified, l

Re: Interpolated strings

2017-04-20 Thread Kagamin via Digitalmars-d
Also how various kinds of strings would work? r$"{can}\i\has{slashes}" $`same {here}` $q{{balanced}braces} For templates it's straightforward.

Re: Interpolated strings

2017-04-20 Thread Nick Sabalausky (Abscissa) via Digitalmars-d
On 04/20/2017 02:40 PM, Nick Sabalausky (Abscissa) wrote: auto exho() { return writeln("${name} and this are app ${age*365*24} hours!"); } Correction: auto exho() { return writeln( ""~ _interp_text(name)~ " and this are app "~

Re: Interpolated strings

2017-04-20 Thread Nick Sabalausky (Abscissa) via Digitalmars-d
On 04/20/2017 06:23 AM, Martin Tschierschke wrote: and this not? import scriptlike; // with exho definition outside the scope of the used vars auto exho(string x)(){return mixin("writeln("~interp!x~")");} void main() { auto name = userInput!string("Please enter your name"); auto age =

Re: Interpolated strings

2017-04-20 Thread Adam D. Ruppe via Digitalmars-d
On Thursday, 20 April 2017 at 18:28:30 UTC, Atila Neves wrote: writeln($"{a} times 3 is {a * 3}"); is even marginally better than writeln(a, " times 3 is ", a * 3); // look ma, works right now! Matching up the correct commas and quotes is a bit of a pain in the latter. Though I don't

Re: Interpolated strings

2017-04-20 Thread Atila Neves via Digitalmars-d
On Monday, 17 April 2017 at 19:38:33 UTC, Kapps wrote: On Saturday, 15 April 2017 at 20:04:13 UTC, Jonas Drewsen wrote: [...] C# got this feature recently. I didn't expect it to be a significant difference, but I do find it a substantial improvement. Not only does it clearly show what goes

Re: Interpolated strings

2017-04-20 Thread Faux Amis via Digitalmars-d
On 2017-04-19 03:45, Jon Degenhardt wrote: On Saturday, 15 April 2017 at 20:04:13 UTC, Jonas Drewsen wrote: I've been wanting to have support for interpolated strings in D for some time now that will allow you to write e.g.: [...] One place I'd appreciate interpolated strings

Re: Interpolated strings

2017-04-20 Thread Kagamin via Digitalmars-d
On Thursday, 20 April 2017 at 10:23:30 UTC, Martin Tschierschke wrote: Can it be possible to allow a function to be defined outside the scope of use to return a "mixin object"? That's basically what I propose: https://forum.dlang.org/post/msotbcaqipiiqxiup...@forum.dlang.org this can be

Re: Interpolated strings

2017-04-20 Thread Martin Tschierschke via Digitalmars-d
On Wednesday, 19 April 2017 at 17:51:05 UTC, Nick Sabalausky (Abscissa) wrote: On 04/17/2017 03:41 PM, Jonas Drewsen wrote: [...] exho!"The number ${num} doubled is ${num * 2}!" Also, it only works if you're just sending the string to writeln. It doesn't help the general case :( you can

Re: Interpolated strings

2017-04-19 Thread Walter Bright via Digitalmars-d
I forgot to mention - the pros and cons of whether the string interpolation is compile time or run time is a critical decision.

Re: Interpolated strings

2017-04-19 Thread Walter Bright via Digitalmars-d
On 4/19/2017 5:04 AM, Jonas Drewsen wrote: On Tuesday, 18 April 2017 at 08:42:38 UTC, Walter Bright wrote: On 4/15/2017 1:04 PM, Jonas Drewsen wrote: [...] Thanks for doing the work to make a sample implementation, too. I don't know if this will make it into D, but Jonas is a fine example of

Re: Interpolated strings

2017-04-19 Thread H. S. Teoh via Digitalmars-d
}02d-%{day}02d", [ "year": yearsSinceEpoch + 1970, "month": zeroBasedMonth + 1, "day": zeroBasedDay + 1 ]); This way, implementation details like zero-based counting, years since the Unix Epoch, etc

Re: Interpolated strings

2017-04-19 Thread Patrick Schluter via Digitalmars-d
On Wednesday, 19 April 2017 at 13:04:08 UTC, Jonathan Marler wrote: On Wednesday, 19 April 2017 at 12:03:47 UTC, Stefan Koch wrote: On Wednesday, 19 April 2017 at 11:59:51 UTC, Jonas Drewsen wrote: I can think of 3 reasons. 1. Requires GC. NOTE: I believe that most applcations should use

Re: Interpolated strings

2017-04-19 Thread H. S. Teoh via Digitalmars-d
On Tue, Apr 18, 2017 at 05:30:31PM -0700, Walter Bright via Digitalmars-d wrote: [...] > Reminds me of a story from the 1980s. Microsoft's MASM stood for > "Macro Assembler". Inevitably, Microsoft programmers invented a pile > of macros that sort of turned asm programming into a pseudo-high-level

Re: Interpolated strings

2017-04-19 Thread Meta via Digitalmars-d
On Wednesday, 19 April 2017 at 15:07:55 UTC, Jonas Drewsen wrote: I'm talking about building format strings just yet... I'm just working with the suggestion that Walter brought up with converting the interpolated string into something that can be fed into format e.g.: $"The date is {%04d

Re: Interpolated strings

2017-04-19 Thread Nick Sabalausky (Abscissa) via Digitalmars-d
On 04/17/2017 03:41 PM, Jonas Drewsen wrote: On Monday, 17 April 2017 at 19:12:37 UTC, Martin Tschierschke wrote: defining a new method exho! (derived from echo + mixin...:-) auto exho(string x)(){ return mixin("writeln("~interp!x~")");} You can just write: exho!"The number ${num}

Re: Interpolated strings

2017-04-19 Thread jmh530 via Digitalmars-d
On Wednesday, 19 April 2017 at 16:19:09 UTC, Ola Fosheim Grøstad wrote: Yup. And actually also "while" and "for". More minimal languages just have: block, conditional and jump-to-start-of-block. This reminds me of Rust's mid-level IR for some reason. For instance, according to one of the

Re: Interpolated strings

2017-04-19 Thread Ola Fosheim Grøstad via Digitalmars-d
On Wednesday, 19 April 2017 at 09:49:16 UTC, Jacob Carlborg wrote: On 2017-04-19 08:51, Ola Fosheim Grøstad wrote: If you want AST-macros in D you should also argue for redefining the core language, and turn everything that is unnecessary and that can be done as lowering into macros (e.g.

Re: Interpolated strings

2017-04-19 Thread Jonas Drewsen via Digitalmars-d
On Wednesday, 19 April 2017 at 14:02:43 UTC, Stefan Koch wrote: On Wednesday, 19 April 2017 at 12:10:33 UTC, Jonas Drewsen wrote: On Wednesday, 19 April 2017 at 12:03:47 UTC, Stefan Koch wrote: On Wednesday, 19 April 2017 at 11:59:51 UTC, Jonas Drewsen wrote: What about supporting an

Re: Interpolated strings

2017-04-19 Thread Adam D. Ruppe via Digitalmars-d
On Wednesday, 19 April 2017 at 12:03:47 UTC, Stefan Koch wrote: I really don't see how string interpolation is better then ` "The date is " ~ format("%04d", year)); ` That code is hideous, not hard to beat on every level... inefficient, hard to read. The built in thing could potentially

Re: Interpolated strings

2017-04-19 Thread Stefan Koch via Digitalmars-d
On Wednesday, 19 April 2017 at 12:10:33 UTC, Jonas Drewsen wrote: On Wednesday, 19 April 2017 at 12:03:47 UTC, Stefan Koch wrote: On Wednesday, 19 April 2017 at 11:59:51 UTC, Jonas Drewsen wrote: What about supporting an optional prefix inside the {} like: int year = 2017; format($"The date

Re: Interpolated strings

2017-04-19 Thread Jonathan Marler via Digitalmars-d
On Wednesday, 19 April 2017 at 12:03:47 UTC, Stefan Koch wrote: On Wednesday, 19 April 2017 at 11:59:51 UTC, Jonas Drewsen wrote: What about supporting an optional prefix inside the {} like: int year = 2017; format($"The date is {%04d year}"); so if there is a % immediately following the {

Re: Interpolated strings

2017-04-19 Thread Jonas Drewsen via Digitalmars-d
On Wednesday, 19 April 2017 at 12:03:47 UTC, Stefan Koch wrote: On Wednesday, 19 April 2017 at 11:59:51 UTC, Jonas Drewsen wrote: What about supporting an optional prefix inside the {} like: int year = 2017; format($"The date is {%04d year}"); so if there is a % immediately following the {

Re: Interpolated strings

2017-04-19 Thread Jonas Drewsen via Digitalmars-d
On Tuesday, 18 April 2017 at 08:42:38 UTC, Walter Bright wrote: On 4/15/2017 1:04 PM, Jonas Drewsen wrote: [...] Thanks for doing the work to make a sample implementation, too. I don't know if this will make it into D, but Jonas is a fine example of a champion. Thanks for the feedback.

Re: Interpolated strings

2017-04-19 Thread Stefan Koch via Digitalmars-d
On Wednesday, 19 April 2017 at 11:59:51 UTC, Jonas Drewsen wrote: What about supporting an optional prefix inside the {} like: int year = 2017; format($"The date is {%04d year}"); so if there is a % immediately following the { then the chars until next whitespace is format specifier. You can

Re: Interpolated strings

2017-04-19 Thread Jonas Drewsen via Digitalmars-d
On Wednesday, 19 April 2017 at 00:08:19 UTC, Walter Bright wrote: On 4/18/2017 2:56 PM, Jonathan Marler wrote: Have you thought about supporting format specifiers as well? I looked at the C# version and it looks like they can specify them using a colon like this: $"{a} in hex is {a:x}"

Re: Interpolated strings

2017-04-19 Thread Nick Treleaven via Digitalmars-d
On Wednesday, 19 April 2017 at 00:08:19 UTC, Walter Bright wrote: There are additional problems, such as: $"{a} in %s {b}" % should be escaped: "%s in %%s %s". There would be no use for a single % otherwise. and positional parameters: $"{a} in {0}" That would be literal 0: `"%s

Re: Interpolated strings

2017-04-19 Thread Jacob Carlborg via Digitalmars-d
On 2017-04-19 08:51, Ola Fosheim Grøstad wrote: If you want AST-macros in D you should also argue for redefining the core language, and turn everything that is unnecessary and that can be done as lowering into macros (e.g. "for each"). If D had AST macros from the beginning, then yes,

Re: Interpolated strings

2017-04-19 Thread Jacob Carlborg via Digitalmars-d
On 2017-04-19 02:30, Walter Bright wrote: I'm not saying you cannot do cool and useful things with AST macros. My position is it encourages absolutely awful code as (usually inexperienced) programmers compete to show how clever their macros are. The language gets balkanized into a collection

Re: Interpolated strings

2017-04-19 Thread Martin Tschierschke via Digitalmars-d
On Monday, 17 April 2017 at 19:41:14 UTC, Jonas Drewsen wrote: On Monday, 17 April 2017 at 19:12:37 UTC, Martin Tschierschke wrote: defining a new method exho! (derived from echo + mixin...:-) auto exho(string x)(){ return mixin("writeln("~interp!x~")");} You can just write:

Re: Interpolated strings

2017-04-19 Thread Ola Fosheim Grøstad via Digitalmars-d
On Wednesday, 19 April 2017 at 03:49:09 UTC, bpr wrote: I don't think I've ever heard from Common Lisp, Scheme or Clojure programmers that they'd like to remove macros from their respective languages for the reasons you mention. I don't see the disasters there. The Julia folks looked at the

Re: Interpolated strings

2017-04-18 Thread bpr via Digitalmars-d
On Wednesday, 19 April 2017 at 00:30:31 UTC, Walter Bright wrote: I'm not saying you cannot do cool and useful things with AST macros. My position is it encourages absolutely awful code as (usually inexperienced) programmers compete to show how clever their macros are. I'd think that that's

Re: Interpolated strings

2017-04-18 Thread Jon Degenhardt via Digitalmars-d
On Saturday, 15 April 2017 at 20:04:13 UTC, Jonas Drewsen wrote: I've been wanting to have support for interpolated strings in D for some time now that will allow you to write e.g.: [...] One place I'd appreciate interpolated strings is as an option when working with heredoc strings

Re: Interpolated strings

2017-04-18 Thread Walter Bright via Digitalmars-d
On 4/18/2017 4:58 PM, bpr wrote: Here's how it's done in Nim, a statically typed language similar to D, but with Python syntax, and macros. It takes some knowledge to understand, sure, macros are not a beginner tool, but wouldn't say this is extremely complex. I bet a D-with-macros would have a

Re: Interpolated strings

2017-04-18 Thread Walter Bright via Digitalmars-d
On 4/18/2017 2:56 PM, Jonathan Marler wrote: Have you thought about supporting format specifiers as well? I looked at the C# version and it looks like they can specify them using a colon like this: $"{a} in hex is {a:x}" There are additional problems, such as: $"{a} in %s {b}" and

Re: Interpolated strings

2017-04-18 Thread bpr via Digitalmars-d
On Tuesday, 18 April 2017 at 08:01:14 UTC, Jacob Carlborg wrote: On 2017-04-18 08:59, Stefan Koch wrote: The corresponding ast-macros would be extremely complex No, it's not that complex. Here's how it's done in Nim, a statically typed language similar to D, but with Python syntax, and

Re: Interpolated strings

2017-04-18 Thread Faux Amis via Digitalmars-d
On 2017-04-18 23:56, Jonathan Marler wrote: I've thought about it and decided, I like this idea. I've only used interpolated strings in PHP which left a bad taste, but I realized that interpolating strings makes it impossible for your format string and your arguments to get out of sync

Re: Interpolated strings

2017-04-18 Thread H. S. Teoh via Digitalmars-d
On Tue, Apr 18, 2017 at 09:56:28PM +, Jonathan Marler via Digitalmars-d wrote: [...] > I've thought about it and decided, I like this idea. I've only used > interpolated strings in PHP which left a bad taste, but I realized > that interpolating strings makes it impossible for yo

Re: Interpolated strings

2017-04-18 Thread Jonathan Marler via Digitalmars-d
t simpler than Jonas' proposed implementation. I've thought about it and decided, I like this idea. I've only used interpolated strings in PHP which left a bad taste, but I realized that interpolating strings makes it impossible for your format string and your arguments to get out of sync. This

Re: Interpolated strings

2017-04-18 Thread Kagamin via Digitalmars-d
On Tuesday, 18 April 2017 at 08:50:07 UTC, Walter Bright wrote: It may not be necessary to have any dependencies on any import. $"{a} times 3 is {a*3}" could be rewritten by the parser to: "%s times 3 is %s", a, a * 3 and that is that. (I.e. just an AST rewrite.) It would be quite a

Re: Interpolated strings

2017-04-18 Thread Jacob Carlborg via Digitalmars-d
On 2017-04-18 10:50, Walter Bright wrote: It may not be necessary to have any dependencies on any import. $"{a} times 3 is {a*3}" could be rewritten by the parser to: "%s times 3 is %s", a, a * 3 and that is that. (I.e. just an AST rewrite.) It would be quite a bit simpler than

Re: Interpolated strings

2017-04-18 Thread Walter Bright via Digitalmars-d
On 4/15/2017 4:51 PM, cym13 wrote: Removing imports is a good point, the first concrete one to be mentionned. I'm not sure it matters that much though as I think those imports are generic enough that I believe they would be imported anyway, but it's a real point. It may not be necessary to

Re: Interpolated strings

2017-04-18 Thread Walter Bright via Digitalmars-d
On 4/15/2017 1:04 PM, Jonas Drewsen wrote: [...] Thanks for doing the work to make a sample implementation, too. I don't know if this will make it into D, but Jonas is a fine example of a champion.

Re: Interpolated strings

2017-04-18 Thread Jacob Carlborg via Digitalmars-d
On 2017-04-18 08:59, Stefan Koch wrote: The corresponding ast-macros would be extremely complex No, it's not that complex. , slow and worst of all not checkable. What do you mean "not checkable"? -- /Jacob Carlborg

Re: Interpolated strings

2017-04-18 Thread Stefan Koch via Digitalmars-d
On Tuesday, 18 April 2017 at 06:54:11 UTC, Jacob Carlborg wrote: On 2017-04-17 21:28, Jonas Drewsen wrote: The page could also list pre-approved language changes such as async functions (which Walter wants afaik). Another feature that can be implemented with AST macros. This is starting to

Re: Interpolated strings

2017-04-18 Thread Jacob Carlborg via Digitalmars-d
On 2017-04-17 21:28, Jonas Drewsen wrote: The page could also list pre-approved language changes such as async functions (which Walter wants afaik). Another feature that can be implemented with AST macros. This is starting to get ridicules. So many features have been added and are talked

Re: Interpolated strings

2017-04-17 Thread Jonas Drewsen via Digitalmars-d
On Monday, 17 April 2017 at 19:12:37 UTC, Martin Tschierschke wrote: defining a new method exho! (derived from echo + mixin...:-) auto exho(string x)(){ return mixin("writeln("~interp!x~")");} You can just write: exho!"The number ${num} doubled is ${num * 2}!" It requires 'num' to

Re: Interpolated strings

2017-04-17 Thread Kapps via Digitalmars-d
On Saturday, 15 April 2017 at 20:04:13 UTC, Jonas Drewsen wrote: Hi all I've been wanting to have support for interpolated strings in D for some time now that will allow you to write e.g.: auto a = 7; writeln( $"{a} times 3 is {a*3}" ); Code speaks louder that words so I've

Re: Interpolated strings

2017-04-17 Thread Jonas Drewsen via Digitalmars-d
On Saturday, 15 April 2017 at 20:04:13 UTC, Jonas Drewsen wrote: Hi all I've been wanting to have support for interpolated strings in D for some time now that will allow you to write e.g.: auto a = 7; writeln( $"{a} times 3 is {a*3}" ); Code speaks louder that words so I've

Re: Interpolated strings

2017-04-17 Thread Martin Tschierschke via Digitalmars-d
ed is ${num * 2}!") ); Maybe I'm overlooking something obvious, but I haven't been able to find a way to change it to either a template mixin or even just a plain template without sacrificing to whole point of interpolated strings: specifying the arguments 100% inline. What I think

Re: Interpolated strings

2017-04-17 Thread Jonas Drewsen via Digitalmars-d
On Sunday, 16 April 2017 at 00:25:19 UTC, Stanislav Blinov wrote: On Saturday, 15 April 2017 at 23:58:18 UTC, Adam D. Ruppe wrote: On Saturday, 15 April 2017 at 23:11:42 UTC, Stanislav Blinov wrote: How about... it removes an import or two? It doesn't actually remove the dependency, it is

Re: Interpolated strings

2017-04-17 Thread Jonathan M Davis via Digitalmars-d
On Monday, April 17, 2017 18:10:23 Jonas Drewsen via Digitalmars-d wrote: > On Sunday, 16 April 2017 at 08:01:02 UTC, Jacob Carlborg wrote: > > On 2017-04-15 22:04, Jonas Drewsen wrote: > >> [...] > > > > My initial reaction is that this is something that can be > > implemented as library code if

Re: Interpolated strings

2017-04-17 Thread Jonas Drewsen via Digitalmars-d
On Sunday, 16 April 2017 at 08:01:02 UTC, Jacob Carlborg wrote: On 2017-04-15 22:04, Jonas Drewsen wrote: [...] My initial reaction is that this is something that can be implemented as library code if the language would have support for AST macros. On the other hand, this is something I

Re: Interpolated strings

2017-04-17 Thread crimaniak via Digitalmars-d
On Sunday, 16 April 2017 at 16:10:15 UTC, Nick Sabalausky (Abscissa) wrote: Yea, and note, I'm still open to the idea of better names than "interp". I'm still not entirely happy with that name. I'm even half-tempted to use "_". When I needed interpolation, I did not know about this library. So

Re: Interpolated strings

2017-04-17 Thread Jacob Carlborg via Digitalmars-d
On 2017-04-16 18:10, Nick Sabalausky (Abscissa) wrote: What I think would be ideal is a language enhancement to allow "interp" to do its job without the extra syntactical noise. That would not only give us good interpolates strings, but would likely have other applications as well. It's

Re: Interpolated strings

2017-04-16 Thread Nick Sabalausky (Abscissa) via Digitalmars-d
overlooking something obvious, but I haven't been able to find a way to change it to either a template mixin or even just a plain template without sacrificing to whole point of interpolated strings: specifying the arguments 100% inline. What I think would be ideal is a language enhancement

Re: Interpolated strings

2017-04-16 Thread Jacob Carlborg via Digitalmars-d
On 2017-04-15 22:04, Jonas Drewsen wrote: Hi all I've been wanting to have support for interpolated strings in D for some time now that will allow you to write e.g.: auto a = 7; writeln( $"{a} times 3 is {a*3}" ); Code speaks louder that words so I've made a PR that adds th

Re: Interpolated strings

2017-04-15 Thread Russel Winder via Digitalmars-d
On Sat, 2017-04-15 at 21:48 +, cym13 via Digitalmars-d wrote: > […] > structure is alike. This makes it *so* much easier. I want to be  > able to find bugs easily. I want D to be like python on that  > part. Not perl. Not ruby. Python now has string interpolation, f-strings. -- Russel.

Re: Interpolated strings

2017-04-15 Thread Dmitry Olshansky via Digitalmars-d
On 4/15/17 10:04 PM, Jonas Drewsen wrote: Hi all I've been wanting to have support for interpolated strings in D for some time now that will allow you to write e.g.: auto a = 7; writeln( $"{a} times 3 is {a*3}" ); Code speaks louder that words so I've made a PR that adds th

Re: Interpolated strings

2017-04-15 Thread Stanislav Blinov via Digitalmars-d
On Saturday, 15 April 2017 at 23:58:18 UTC, Adam D. Ruppe wrote: On Saturday, 15 April 2017 at 23:11:42 UTC, Stanislav Blinov wrote: How about... it removes an import or two? It doesn't actually remove the dependency, it is just syntax sugar over it (there is precedent for this in the

Re: Interpolated strings

2017-04-15 Thread Adam D. Ruppe via Digitalmars-d
On Saturday, 15 April 2017 at 23:11:42 UTC, Stanislav Blinov wrote: How about... it removes an import or two? It doesn't actually remove the dependency, it is just syntax sugar over it (there is precedent for this in the language, the pow operator calls a Phobos function, but it means you

Re: Interpolated strings

2017-04-15 Thread cym13 via Digitalmars-d
On Saturday, 15 April 2017 at 23:11:42 UTC, Stanislav Blinov wrote: On Saturday, 15 April 2017 at 21:38:24 UTC, cym13 wrote: On Saturday, 15 April 2017 at 20:20:49 UTC, Stanislav Blinov wrote: On Saturday, 15 April 2017 at 20:12:41 UTC, cym13 wrote: On Saturday, 15 April 2017 at 20:04:13 UTC,

Re: Interpolated strings

2017-04-15 Thread Stanislav Blinov via Digitalmars-d
On Saturday, 15 April 2017 at 21:38:24 UTC, cym13 wrote: On Saturday, 15 April 2017 at 20:20:49 UTC, Stanislav Blinov wrote: On Saturday, 15 April 2017 at 20:12:41 UTC, cym13 wrote: On Saturday, 15 April 2017 at 20:04:13 UTC, Jonas Drewsen wrote: This has been proposed before, and I still

Re: Interpolated strings

2017-04-15 Thread cym13 via Digitalmars-d
On Saturday, 15 April 2017 at 20:45:23 UTC, Jonas Drewsen wrote: On Saturday, 15 April 2017 at 20:20:49 UTC, Stanislav Blinov wrote: On Saturday, 15 April 2017 at 20:12:41 UTC, cym13 wrote: On Saturday, 15 April 2017 at 20:04:13 UTC, Jonas Drewsen wrote: This has been proposed before, and I

Re: Interpolated strings

2017-04-15 Thread cym13 via Digitalmars-d
On Saturday, 15 April 2017 at 20:20:49 UTC, Stanislav Blinov wrote: On Saturday, 15 April 2017 at 20:12:41 UTC, cym13 wrote: On Saturday, 15 April 2017 at 20:04:13 UTC, Jonas Drewsen wrote: This has been proposed before, and I still don't see the added value compared to: auto a=7;

Re: Interpolated strings

2017-04-15 Thread Jonas Drewsen via Digitalmars-d
On Saturday, 15 April 2017 at 21:03:27 UTC, Xinok wrote: On Saturday, 15 April 2017 at 20:04:13 UTC, Jonas Drewsen wrote: Hi all I shared my thoughts on such a feature just a couple weeks ago: https://forum.dlang.org/post/oedeijdewmhazaqaz...@forum.dlang.org Most of you points applies to

Re: Interpolated strings

2017-04-15 Thread Jonas Drewsen via Digitalmars-d
On Saturday, 15 April 2017 at 20:57:33 UTC, Jack Stouffer wrote: On Saturday, 15 April 2017 at 20:04:13 UTC, Jonas Drewsen wrote: ... First, there's a process for language additions, please see https://github.com/dlang/DIPs/blob/master/README.md Secondly, I can tell you that any proposal

Re: Interpolated strings

2017-04-15 Thread Xinok via Digitalmars-d
On Saturday, 15 April 2017 at 20:04:13 UTC, Jonas Drewsen wrote: Hi all I shared my thoughts on such a feature just a couple weeks ago: https://forum.dlang.org/post/oedeijdewmhazaqaz...@forum.dlang.org

Re: Interpolated strings

2017-04-15 Thread Jack Stouffer via Digitalmars-d
On Saturday, 15 April 2017 at 20:04:13 UTC, Jonas Drewsen wrote: ... First, there's a process for language additions, please see https://github.com/dlang/DIPs/blob/master/README.md Secondly, I can tell you that any proposal that can be solved via the standard library has a very low chance

Re: Interpolated strings

2017-04-15 Thread Jonas Drewsen via Digitalmars-d
On Saturday, 15 April 2017 at 20:35:56 UTC, crimaniak wrote: On Saturday, 15 April 2017 at 20:04:13 UTC, Jonas Drewsen wrote: The compiler will basically lower the $"..." string to a mixin that concatenates the expression parts of the (inside the {}) and the plain text parts. It's easy

Re: Interpolated strings

2017-04-15 Thread Jonas Drewsen via Digitalmars-d
On Saturday, 15 April 2017 at 20:20:49 UTC, Stanislav Blinov wrote: On Saturday, 15 April 2017 at 20:12:41 UTC, cym13 wrote: On Saturday, 15 April 2017 at 20:04:13 UTC, Jonas Drewsen wrote: This has been proposed before, and I still don't see the added value compared to: auto a=7;

Re: Interpolated strings

2017-04-15 Thread crimaniak via Digitalmars-d
On Saturday, 15 April 2017 at 20:04:13 UTC, Jonas Drewsen wrote: The compiler will basically lower the $"..." string to a mixin that concatenates the expression parts of the (inside the {}) and the plain text parts. It's easy implementable as a library (see

Re: Interpolated strings

2017-04-15 Thread Stanislav Blinov via Digitalmars-d
On Saturday, 15 April 2017 at 20:12:41 UTC, cym13 wrote: On Saturday, 15 April 2017 at 20:04:13 UTC, Jonas Drewsen wrote: This has been proposed before, and I still don't see the added value compared to: auto a=7; writeln(a, " times 3 is ", a*3); besides adding compiler complexity,

Re: Interpolated strings

2017-04-15 Thread cym13 via Digitalmars-d
On Saturday, 15 April 2017 at 20:04:13 UTC, Jonas Drewsen wrote: Hi all I've been wanting to have support for interpolated strings in D for some time now that will allow you to write e.g.: auto a = 7; writeln( $"{a} times 3 is {a*3}" ); Code speaks louder that words so I've

Interpolated strings

2017-04-15 Thread Jonas Drewsen via Digitalmars-d
Hi all I've been wanting to have support for interpolated strings in D for some time now that will allow you to write e.g.: auto a = 7; writeln( $"{a} times 3 is {a*3}" ); Code speaks louder that words so I've made a PR that adds this support to ddmd as a RFC [1]. Th

Re: Scriptlike v0.9.4 - Perl-like interpolated strings, full examples and more.

2015-09-26 Thread Jacob Carlborg via Digitalmars-d-announce
On 2015-09-25 23:28, H. S. Teoh via Digitalmars-d-announce wrote: It's to work around a dmd bug that doesn't allow overloads between templates and non-templates. But I just checked, looks like that bug may have been fixed since, so now the following overloads would work: void

Re: Scriptlike v0.9.4 - Perl-like interpolated strings, full examples and more.

2015-09-25 Thread Nick Sabalausky via Digitalmars-d-announce
On 09/23/2015 08:42 PM, Meta wrote: What about even just removing the syntax distinction between string mixins and template mixins? mixin "int i = 0"; mixin declareI!(); I like that idea. It it feasible? I'd always assumed the syntaxes were different because they needed to be for some sort

Re: Scriptlike v0.9.4 - Perl-like interpolated strings, full examples and more.

2015-09-25 Thread Meta via Digitalmars-d-announce
On Friday, 25 September 2015 at 14:38:33 UTC, Nick Sabalausky wrote: I like that idea. It it feasible? I'd always assumed the syntaxes were different because they needed to be for some sort of technical reason. But now that I look at it...maybe that could work after all? At first glance I

Re: Scriptlike v0.9.4 - Perl-like interpolated strings, full examples and more.

2015-09-25 Thread H. S. Teoh via Digitalmars-d-announce
On Fri, Sep 25, 2015 at 02:14:30PM +0200, Jacob Carlborg via Digitalmars-d-announce wrote: > On 2015-09-25 02:15, H. S. Teoh via Digitalmars-d-announce wrote: > > >I wanted to work on it, but haven't actually gotten to it yet. > >Basically, the idea is relatively simple: > > > > //

Re: Scriptlike v0.9.4 - Perl-like interpolated strings, full examples and more.

2015-09-25 Thread Jacob Carlborg via Digitalmars-d-announce
On 2015-09-25 02:15, H. S. Teoh via Digitalmars-d-announce wrote: I wanted to work on it, but haven't actually gotten to it yet. Basically, the idea is relatively simple: // compile-time variant void writefln(string format="", A...)(A args) if (format.length >

Re: Scriptlike v0.9.4 - Perl-like interpolated strings, full examples and more.

2015-09-25 Thread Sönke Ludwig via Digitalmars-d-announce
Am 23.09.2015 um 16:33 schrieb Nick Sabalausky: (...) void main() { int somevar = 42; mixin interp; iwriteln!("This is ${somevar}."); int another = 17; iwriteln!("This won't work, using ${another}."); } Seems like it would be too awkward and confusing to be

  1   2   >