3 ms·
The article asserts that anything that includes a conditional must be imperative because it dictates control flow. Under that view, the definition of the Fibona
by soraminazuki 4y ago
The article asserts that anything that includes a conditional must be imperative because it dictates control flow. Under that view, the definition of the Fibonacci sequence would be imperative.
F(n) = 1 (n = 1)
F(n) = 1 (n = 2)
F(n) = F(n - 1) + F(n - 2) (n > 2)
But the above definition says nothing about how you should calculate the value of F(n). As a matter of fact, math tells us that the definition of F(n) can be converted to a formula that doesn't include conditionals. In other words, the conditional in the original definition of F(n) has no direct relationship to the actual control flow of programs that calculate F(n).
It follows that F(n) is defined declaratively, invalidating the claim that declarative expressions can't contain conditionals.