digitalmars.D.learn - What is an Effect?
"Manfred_Nowak" <svv1999 hotmail.com> writes:
docs: | Expressions that have no effect, like (x + x), are illegal in | expression statements. But what sorts of effects are meant with this? In phobos the expressionStatement `cmp("foo", "bar");' is used in unittest.d. A comment says: | Bring in unit test for module by referencing function in it wtf? Does this mean, that a second expressionStatement `cmp("foo", "bar");' in unittest.d would be illegal, but not the first, because by the second statement the unit test of that module can no more be brought in? Is then in `int x= 42; x= 42;' the assignment of the value `42' to the varaible `x' illegal, because `x` already has this value as initialization? Furthermore: is the result of suppressing an effect nevertheless an effect, especially suppressing the default initialization of a variable? Somehow this reminds me on the time when set theory got the attribute "naive". -manfred
Jan 02 2011
Jesse Phillips <jessekphillips+D gmail.com> writes:
Manfred_Nowak Wrote:docs: | Expressions that have no effect, like (x + x), are illegal in | expression statements. But what sorts of effects are meant with this?(x + x) performs a calculation and throws out the result. x = 42; x = 42; This is performing an assignment of the same value. Note that the difference is that the first is context free. x = 42 is doing something even though it would not change behavior of the running program. The first one is just having the CPU run some computation and does not affect the state of the program.
Jan 02 2011