On 7/7/13 10:08 AM, John Colvin wrote:
On Sunday, 7 July 2013 at 16:06:43 UTC, Andrei Alexandrescu wrote:
On 7/7/13 8:55 AM, Andrei Alexandrescu wrote:
Here's a conformant implementation for reference:
http://www.scs.stanford.edu/histar/src/pkg/echo/echo.c

Hmm, that's actually not so good, it doesn't ensure that I/O was
successful. Anyhow, here's a possibility:

import std.stdout;
void main(string[] args)
{
const appendNewline = args.length > 1 && args[1] == "-n";
foreach (i, arg; args[appendNewline + 1 .. $])
{
if (i) write(' ');
write(arg);
}
if (nl) writeln();
}

Right structure, wrong logic? Shouldn't it be:

import std.stdio;
void main(string[] args)
{
const noNewline = args.length > 1 && args[1] == "-n";
foreach (i, arg; args[noNewline + 1 .. $])
{
if (i) write(' ');
write(arg);
}
if (!noNewline) writeln();
}

or am I being dumb?

No, I am :o).

Yeah, I reckon it will get quite interesting as I get in to the details.
It's easy to see these basic utilities as trivial but they most
certainly aren't, if you want to get them 100% right for all the options.

Cool!


Andrei

Reply via email to