digitalmars.D.learn - Range format specifiers in other languages?
- =?UTF-8?Q?Ali_=c3=87ehreli?= (9/9) Oct 11 2020 I find D's %( and %) range format specifiers very useful:
- Max Haughton (6/15) Oct 11 2020 I think rust can do something similar with struct pretty
- =?UTF-8?Q?Ali_=c3=87ehreli?= (3/5) Oct 11 2020 This feature is already among my slides for an upcoming conference. ;)
- Imperatorn (3/12) Oct 11 2020 To people trying to learn, why is that % before ( needed in the
- Adam D. Ruppe (3/5) Oct 11 2020 The %( ... %) stuff is expanded and repeated for each element
- Imperatorn (4/9) Oct 11 2020 Thanks, it seems there are some pretty powerful formatting
- H. S. Teoh (26/37) Oct 12 2020 Indeed.
I find D's %( and %) range format specifiers very useful: import std.stdio; import std.range; void main() { 5.iota.writefln!"%(%s, %)"; // Prints 0, 1, 2, 3, 4 } Are there similar features in other languages? Thank you, Ali
Oct 11 2020
On Sunday, 11 October 2020 at 23:57:31 UTC, Ali Çehreli wrote:I find D's %( and %) range format specifiers very useful: import std.stdio; import std.range; void main() { 5.iota.writefln!"%(%s, %)"; // Prints 0, 1, 2, 3, 4 } Are there similar features in other languages? Thank you, AliI think rust can do something similar with struct pretty printing. The syntax has curly braces in it but I can't recall it right now. Possibly worth showing off (especially given that some people at first don't even know the templated format string exists)
Oct 11 2020
On 10/11/20 5:44 PM, Max Haughton wrote:Possibly worth showing off (especially given that some people at first don't even know the templated format string exists)This feature is already among my slides for an upcoming conference. ;) Ali
Oct 11 2020
On Sunday, 11 October 2020 at 23:57:31 UTC, Ali Çehreli wrote:I find D's %( and %) range format specifiers very useful: import std.stdio; import std.range; void main() { 5.iota.writefln!"%(%s, %)"; // Prints 0, 1, 2, 3, 4 } Are there similar features in other languages? Thank you, AliTo people trying to learn, why is that % before ( needed in the format string?
Oct 11 2020
On Monday, 12 October 2020 at 00:46:37 UTC, Imperatorn wrote:To people trying to learn, why is that % before ( needed in the format string?The %( ... %) stuff is expanded and repeated for each element inside the given array.
Oct 11 2020
On Monday, 12 October 2020 at 00:59:33 UTC, Adam D. Ruppe wrote:On Monday, 12 October 2020 at 00:46:37 UTC, Imperatorn wrote:Thanks, it seems there are some pretty powerful formatting options: https://dlang.org/phobos/std_format.htmlTo people trying to learn, why is that % before ( needed in the format string?The %( ... %) stuff is expanded and repeated for each element inside the given array.
Oct 11 2020
On Mon, Oct 12, 2020 at 05:51:21AM +0000, Imperatorn via Digitalmars-d-learn wrote:On Monday, 12 October 2020 at 00:59:33 UTC, Adam D. Ruppe wrote:Indeed. %(...%) is one of my favorite because it can be nested, so it's a very useful quick-n-dirty tool for debugging ranges. With .chunks and .map, you can format just about any range-based data in a one-liner for dumping debug info. Another cool one is the `,` digit-grouper: import std; void main() { writefln("%,2d", 1234567890); writefln("%,3d", 1234567890); writefln("%,4d", 1234567890); writefln("%,3?d", '_', 1234567890); writefln("%,4?d", '\'', 1234567890); writefln("%,4?.2f", '\'', 1234567890.123); } Output: 12,34,56,78,90 1,234,567,890 12,3456,7890 1_234_567_890 12'3456'7890 12'3456'7890.12 T -- Век живи - век учись. А дураком помрёшь.On Monday, 12 October 2020 at 00:46:37 UTC, Imperatorn wrote:Thanks, it seems there are some pretty powerful formatting options: https://dlang.org/phobos/std_format.htmlTo people trying to learn, why is that % before ( needed in the format string?The %( ... %) stuff is expanded and repeated for each element inside the given array.
Oct 12 2020