A very basic blog about D

John Colvin john.loughran.colvin at gmail.com
Sun Jul 7 10:08:21 PDT 2013


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?

> But then I figured echo must do escape character processing, 
> see e.g. 
> http://www.raspberryginger.com/jbailey/minix/html/echo_8c-source.html. 
> With that the blog entry would become quite interesting.
>
>
> Andrei

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.


More information about the Digitalmars-d-announce mailing list