[OT] Stupid programmer tricks (or "Fun with RDMD")
Nick Sabalausky
a at a.a
Tue Aug 17 18:13:42 PDT 2010
"Nick Sabalausky" <a at a.a> wrote in message
news:i4fair$2grk$1 at digitalmars.com...
> "Ellery Newcomer" <ellery-newcomer at utulsa.edu> wrote in message
> news:i4f8in$2a42$1 at digitalmars.com...
>> What? No infinite loop? Your [lack of] stupidity disappoints me.
>
> Oops! Good catch! I'm so embarrased by my oversight. Here you go:
>
> $ cat rdmdFOREVER.d
> import std.process;
> void main()
> {
> system("rdmd rdmdhello.d");
> system("rdmd rdmdFOREVER.d");
> }
>
> $ rdmd rdmdFOREVER.d
> Hello world
> Hello world
> Hello world
...
And just for the hell of it:
$ cat rdmdFOREVERish.d
import std.file;
import std.process;
void main()
{
system("rdmd rdmdhello.d");
if(!exists("KILL-FOREVERish-NOW"))
system("rdmd rdmdFOREVERish.d");
}
But you don't expect to kill it MANUALLY, without even using rdmd once, do
you? So here:
$ cat killFOREVERish.d
import std.conv;
import std.file;
import std.process;
import std.stdio;
void main(string[] args)
{
int theFinalCountdown = 5; // DOOT! DO DO DOOOO DOOT!!
if(args.length > 1)
{
try theFinalCountdown = to!int(args[1]);
catch(Throwable e){}
}
if(theFinalCountdown <= 0)
{
writeln("DIE, FOREVER! DEAD DEAD DEAD!!");
mkdir("KILL-FOREVERish-NOW");
}
else
{
writeln(theFinalCountdown);
--theFinalCountdown;
system("rdmd killFOREVERish.d "~to!string(theFinalCountdown));
}
}
More information about the Digitalmars-d
mailing list