Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> I don't know!

A pure function is a function whose output only depends on the paramters and not has any internal state. Which in my opinion is a somewhat useless distinction, because you can make your state/instance/whatever the first parameter, (what C and Python do) and tada, every function that doesn't use globals (or static in C), is a pure function.



a pure function doesn't have side effects. it doesn't read from nonlocal state or trigger distant changes nor perform any manner of io.

a pure function doesn't change its inputs, it simply uses them to craft it's outputs.

bringing in an object or function via parameter to perform these side effects still leaves the function impure.


I agree that a return type and a parameter are quite different things in a specific implementation, but on an abstract level, they are basically the same and there is now reason to distinguish between output parameters and the return value other than due to language syntax.

I don't see how mergeing an input and an output parameter to a single in/out parameter makes any difference, other than making it inconvenient for the caller to keep the old state around, which is often what you want. The fact that the callee than can derive the new state from the old state by only specifying the changed values does not fundamentally change anything and is only convenient for the implementation.


Is that distinct from a pure transformation?


A pure transformation is an abstract operation, a pure function implements it.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: