5 ms·
> single-assignment "variables," It's a pet peeve of mine to see people disparage the phrase "immutable variable" as a contradiction. A given variable's value
by kibwen 12y ago
> single-assignment "variables,"
It's a pet peeve of mine to see people disparage the phrase "immutable variable" as a contradiction. A given variable's value can vary each time its function is called, or each time its program is run, without ever needing to be mutated. In fact, in practice most variables don't end up requiring mutation, which was a surprise for me coming from traditional imperative languages (not to say that mutation isn't valuable, but it makes more sense for your language to make variables immutable by default rather than mutable by default).
</rant>
- dukerutledge 12y agoThis is why we call these things "values" not "variables"
- mbrock 12y agoThose are different concepts. Variables have names, values typically don't. 500 is a value; foo is a variable.
- seanmcdirmid 12y agoValues that have names are typically called objects (their identity isn't structural). Named values are necessary for having mutable fields (I.e. variables).
- mbrock 12y agoHmm, that doesn't sound right to me, at least not if "name" means "identifier" in the conventional sense (like foo). For example, stack-based languages can do field mutation without names.
- seanmcdirmid 12y agoDepends if we are talking about local stack or global heap state. If you just want to modify a register, then a locally bound name/index/stack pointer is sufficient. If you want heap allocated aliased (shared) state, you need globally unique names or addresses. The challenge is always with global state, hardly ever with locally scoped state.
- ajuc 12y agoValue is the thing associated with variable. Like 3 or "foo". Variable is just a name for value.
- mattchamb 12y agoF# doesnt actually call them variables, they call them bindings [1]. It looks like they intentionally avoid the "variable" terminology for immutable values. [1] https://msdn.microsoft.com/en-us/library/dd233238.aspx https://msdn.microsoft.com/en-us/library/dd233238.aspx
- dllthomas 12y agoRight. It's not like programmers invented the term variable and it can only reasonably refer to a mutable memory cell... we adopted it from math, where x is quite clearly a variable despite having only a single value in "x + 1 = 7".
- ubernostrum 12y ago"Variable" is still the correct name, because across multiple invocations of a function, the values -- both those passed in and those computed by execution -- will not necessarily be consistent.
- phamilton 12y agoAlso, single-assignment != immutable. Likewise, reassignment != mutable.