On Friday, 26 July 2013 at 00:38:46 UTC, John Colvin wrote:
After a few weeks of not getting around to it, here's my second post:


http://foreach-hour-life.blogspot.co.uk/2013/07/the-first-corner-n-for-echo.html

I tried to post a comment on your blog, but I failed. Anyways, I wanted to post:

In regards to the whole "spaces only *between*" elements issue, it is always good to know that writef knows how to print a range, and knows how to add a "separator" tokens. This make it trivailly easy to print a range of elements, adding tokens *only* between each elements.

I know it's not necessarily what you want to teach, but it *is* incredibly useful. Your first example becomes the trivial:

import std.stdio : writefln;
void main(string[] args)
{
    assert(args.length);
    args = args[1 .. $];
    debug writefln("[%(%s, %)]", args);
    else writefln("%-(%s %)", args);
}

when invoked with "a b c", it prints:
a b c
If compiled with "-debug" to boot, you can add extra "visual" tokens to check there are no trailing symbols:
["a", "b", "c"]

See? Who needs a foreach, or a loop, or functional programming ;)

Reply via email to