On 7/30/14, 4:17 AM, "Ola Fosheim Grøstad" <ola.fosheim.grostad+dl...@gmail.com>" wrote:
On Wednesday, 30 July 2014 at 03:32:50 UTC, Walter Bright wrote:
On 7/29/2014 7:08 PM, Timon Gehr wrote:
Of course version(assert) is a language feature. Always double-check
your claims.

It's even documented: http://dlang.org/version.html

You're right. My mistake. I'd forgotten about that.


Not a bit. The distinction utterly escapes me.
This is unfortunate, but I don't know what else to say.

I don't either. I still have no idea what the difference between
assume(i<6) and assert(i<6) is supposed to be.

main(){
   foobar();
   assert(false==true)
}

With assert():

main(){
   foobar();
}

Could you show an example that's a bit more complex and useful? I'm with Walter that I don't see any difference between assert and assume.

For example:

---
int x = ...;
int y = ...;

assert(x + y == 3);

writeln(x + y);
---

If the assert fails then the program crashes in non-release mode. So after the assert the compiler knows that "x + y == 3" so that it can replace "writeln(x + y)" with "writeln(3)" (assuming the compiler is the smartest on earth).

Now, if you compile in release mode, according to Walter, all the "asserts" are gone (which, as a side note, is something I don't like: in every case it should throw an AssertError). So the question is: can the compiler still replace that writeln call? It should, but since there's nothing there preventing x + y to be different than 3 (the assertion is gone), the compiler can't replace it anymore.

With assume... what's the difference? You say the compiler should replace it anyway because that's what you assume? There's nothing left at release mode to verify that for you.

Could you elaborate this example using assert and assume?

Thanks!

Reply via email to