3 ms·
No, that's an example of recursion. With recursion you aren't mutating the variable, you're shadowing its definition. This is a subtle, but important, distincti
by chongli 14y ago
No, that's an example of recursion. With recursion you aren't mutating the variable, you're shadowing its definition. This is a subtle, but important, distinction.
- Gravityloss 14y agoRecursion? The "function" is not calling itself at all. I'm quite sure that is not recursion, neither in the mathematical nor computer science sense.
- chongli 14y agoRecursion is how you implement a sum without mutation (an imperative loop is how you'd implement it with mutation). You've merely given me the function written in a declarative notation.
- Gravityloss 14y agoI think we are talking about different things. For example, if you integrate x^2 dx from x=0 to 10, x changes continuously. It's clear that x is not fixed to any particular value.
- chongli 13y agoYeah, you're talking about the mathematical definition of a bound variable. Functional programming languages use this whenever you define a function: foo x = x * 2 Every time you call foo, x is bound to a new value (but only within the scope of foo). This is not the same as mutating some memory location associated with the name x.