How to hand in a closure variable

Bienlein jeti789 at web.de
Fri Apr 4 06:51:03 PDT 2014


Thanks so far. I have another one, though. Not trying to tease 
people, I really don't know ;-).

This compiles and runs:

immutable int a = (int val) {
	if(1 == 1) {
		return val;
	} else {
		return 456;
	}
}(123);	
	
writeln(a);

Whereas this does not compile:

immutable int b = (int) {
	if(1 == 1) {
		return 123;
	} else {
		return 456;
	}
}(); // line x	

However, this does compile and displays correctly 123:

immutable int b = (int) {
	if(1 == 1) {
		return 123;
	} else {
		return 456;
	}
}(1); // line y	
		
writeln(b);

Note it says () in line x and (1) in line y. The (1) in line y is 
redundant, but the stuff then compiles.


More information about the Digitalmars-d-learn mailing list