> 4. External resources (files, I/O): this would be a very difficult topic if not for our simple question. Only writing to a file or outputting to an I/O stream is considered an effect, as only the process of writing mutates external state. Reading data creates new state, but does not modify it, therefore reading data of various sorts is not an effect. Because of this, printing is effectful, but reading from stdin is not.<p>Lost me at this part. Of course reading is a side-effect. A function which reads from a file/console cannot be <i>pure</i>. Purity implies referential transparency - a function given the same arguments will always return the same result.<p>If we consider the example given:<p><pre><code> pub fn read_guess() -> int {
return io.read_int("Take a guess (0-100): ");
}
</code></pre>
We should take `read_int` to be effectful because it will have the effect of advancing the position to read from in the console's buffer. If it didn't, it would always read from the same position, so even if the user took a second guess, the first guess would be read again the second time `read_int` is called. So given that `read_int` is effectful, so too is `read_guess`.<p>> 1. Well, creating a variable is creating new state, but it’s not changing the state, therefore creating a variable is not an effect, but changing it is.<p>Creating a local variable isn't a side-effect, but <i>allocating</i> a variable is a side effect. Sure enough, if we also free the allocation before leaving scope, we can avoid propagating that effect, but if you return a value that contains anything allocated by a function, then the function becomes effectful.