Progopedia - encyclopedia of programming languages

Anders F Björklund afb at algonet.se
Mon Nov 23 23:40:45 PST 2009


Andrei Alexandrescu wrote:

>> Okay.  I added a D entry.  It should be checked for accruacy.  I 
>> haven't added programming examples yet; I'll add at least the three 
>> example types shown on at http://progopedia.com/ (Hello world, 
>> Factorial, Fibonacci).
> 
> Excellent, thanks JMNorris! This is exactly the kind of publicity D 
> needs now.

Strangely, the Hello World program is not the one that is in D:

import std.c.stdio;

int main(char[][] args)
{
     printf("hello world\n");
     printf("args.length = %d\n", args.length);
     for (int i = 0; i < args.length; i++)
         printf("args[%d] = '%s'\n", i, cast(char *)args[i]);
     return 0;
}

But instead some half-way variant of the updated version for D:

import std.stdio;

void main(string[] args)
{
     writefln("hello world");
     foreach(string arg; args)
         writefln("%s", arg);
}

Otherwise I think that is a good example of the differences,
even though it doesn't cover puts/writeln or handle errors...

And of course it makes a couple of assumptions such as the
terminal being in UTF-8. But I guess that's a Windows issue ?

--anders


PS. I think I call that program "echo" rather than "hello".
     Even had a first version "nothing" that prints nothing:
     http://gdcmac.sourceforge.net/GettingStarted.pdf (Mac)
     http://gdcwin.sourceforge.net/GettingStarted.pdf (Win)


More information about the Digitalmars-d-announce mailing list