[英]Does an impure function return anything?
An impure function does not return anything.一个不纯的函数不返回任何东西。 That is what my computer textbook says.
我的计算机教科书就是这么说的。 I am not sure it is correct as by definition an impure function is a function which changes the state of the parameters passed to it.
我不确定它是否正确,因为根据定义,不纯函数是一个改变传递给它的参数状态的函数。 The parameter is generally an object.
参数通常是一个对象。
eg:例如:
void impurefunc(Class object)
{
object.var = 9; //object's variable changed
}
If it returns anything does it remain impure?如果它返回任何东西,它是否仍然不纯?
An impure function does not return anything.
一个不纯的函数不返回任何东西。 That is what a computer textbook says.
计算机教科书上是这么说的。
It's wrong.这是错的。 An impure function can indeed return anything after doing whatever impure things it does.
一个不纯的函数在做了任何不纯的事情之后确实可以返回任何东西。 This is true in Java and every other language I know of.
这在 Java 和我所知道的所有其他语言中都是如此。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.