lazyを使ってみる。

ifをいろいろ作ってみました。いい感じです。
言語内言語をやるのにとてもいい感じです。

void if2(bool b, lazy void a1, lazy void a2) {
	if (b[0]) a1();
	else      a2();
}
bool if_(bool[]  b ...) { return b.dup;}

void main() {
	if2(true,
		printf("a1\n"),
		printf("a2\n")
	);
	if_(true).if2(
		printf("a1\n")
	,
		printf("a2\n")
	);

	If (true) [
		printf("ohoho\n")
	][
		printf("ohoho2\n")
	];

	If (false) [
		printf("ohoho\n")
	][
		printf("ohoho2\n")
	];
}

class If {
	static If opCall(bool b) { return new If(b); }
	bool b;
	this(bool b) { this.b = b; }
	Else opIndex(lazy void a) {
		if (b) {
			a(); return Else(true);
		} else {
			return Else(false);
		}
	}
}

class Else {
	static Else opCall(bool b) { return new Else(b); }
	bool b;
	this(bool b) { this.b = b; }
	void opIndex(lazy void a) {
		if (!b) a(); 
	}
}