On 05/04/2012 10:51 AM, Iain wrote:

If you want Iain I'll put this version by Ali Çehreli in Rosettacode:

import std.stdio, core.thread;

void main() {
write("Enter a time to sleep (in seconds): ");

long secs;
readf(" %d", &secs);

writeln("Sleeping...");
Thread.sleep(dur!"seconds"(secs));
writeln("Awake!");
}


Bye,
bearophile

That's great, and thanks to Ali for explaining.

Out of interest, is there a coordinated effort to update things like
Rosetta or the dsource.org tutorials to use D2.0? I find one of the big
stumbling blocks to learning is that half of the tutorials and code
snippets out there are obsolete!


As far as I know, people maintain sites individually.

It is unfortunate but not surprising that many sites have been outdated considering the amount of changes to D in the recent years. I had to rewrite a number of chapters and go over many examples since I have started the original book a number of years ago. (See my shiny new signature. ;))

Somewhat off-topic, I have just hit a broken example today when translating the "null and is" chapter. This used to print 0:

    writeln(null);

but now causes an obscure compilation error:

.../dmd/phobos/std/stdio.d(1562): Error: undefined identifier 'length'
.../dmd/phobos/std/stdio.d(1562): Error: undefined identifier 'ptr', did you mean 'template tr(C1,C2,C3,C4 = immutable(char))'? deneme.d(76953): Error: template instance std.stdio.writeln!(typeof(null)) error instantiating

It takes the 'null' value to be a "Specialization for strings - a very frequent case".

This is a bug, right? But what should printing 'null' do anyway? Print 0 as before, or "null"?

Ali

--
D Programming Language Tutorial: http://ddili.org/ders/d.en/index.html

Reply via email to