Yes, Maple, maybe my example was a bit confusing. My attempt was to show that the "constant" PI (an external variable) could change (in my example, I changed it to 42).
If the PI value changes, our calculateArea function will change the output for the same input (radius). The whole idea is to show that the function to be pure, it needs to not change the output, for the same input.
I will try give another example with a variable instead of a constant.
Yes, Maple, maybe my example was a bit confusing. My attempt was to show that the "constant"
PI
(an external variable) could change (in my example, I changed it to42
).If the
PI
value changes, ourcalculateArea
function will change the output for the same input (radius
). The whole idea is to show that the function to be pure, it needs to not change the output, for the same input.I will try give another example with a variable instead of a constant.
For the input
100
, we will have120
as a result. But if our tax changes, our output will change, for the same input (100
).To make our function pure, we can pass the
tax
variable to the function as a parameterFor the inputs 100 and 20, it will always be 120
For the inputs 100 and 100, it will always be 200
With this example it is a bit less confusing I think.
Thanks for the feedback!