January 03, 2011 What is an Effect? | ||||
---|---|---|---|---|
| ||||
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 |
January 03, 2011 Re: What is an Effect? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Manfred_Nowak | 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.
|
Copyright © 1999-2021 by the D Language Foundation