2 ms·
>> IMHO in a declarative language your example should be an error. You defined x twice. This would be an error in a language with immutable data structures. De
by YeGoblynQueenne 7y ago
>> IMHO in a declarative language your example should be an error. You defined x twice.
This would be an error in a language with immutable data structures. Declarative and immutable are not the same thing and there is nothing that says a declarative language must have immutable data structures.
- sp332 7y agoI think the idea is that declarative statements use "equals" like math uses equals, not as assignment. If you say x = 1 and then later say x = 2, that is a contradiction. Usually if you evaluate each statement in order from top to bottom, that is procedural programming. And if you don't do that, it's hard to assign multiple values to one variable because you need a way for the compiler to know when the variable has each value.
- the_af 7y ago> This would be an error in a language with immutable data structures It's an error from the point of view of equational thinking; (im)mutabilty is not involved. The name `x` cannot be 1 and 3 simultaneously. It's either 1 or 3. So in the allegedly declarative program, the programmer first claimed name `x` is bound to the value 1, but later claimed it's 3. That's the error. This has nothing to do with mutating data structures. Like the sibling comment notes, there is not "first-this-then-that" order of evaluation, so you cannot read this as "first `x` means 1, but later it means 3", because there are no notions of "first" and "later".