(no title)
ekipan | 1 month ago
const f = (x) => {
const y = x + 1;
return y + 1;
}
y is an immutable variable. In f(3), y is 4, and in f(7), y is 8.I've only glanced at this Zen-C thing but I presume it's the same story.
ekipan | 1 month ago
const f = (x) => {
const y = x + 1;
return y + 1;
}
y is an immutable variable. In f(3), y is 4, and in f(7), y is 8.I've only glanced at this Zen-C thing but I presume it's the same story.
Deanoumean|1 month ago
throwaway17_17|1 month ago
1) A ‘variable’ is an identifier which is bound to a fixed value by a definition;
2) a ‘variable’ is a memory location, or a higher level approximation abstracting over memory locations, which is set to and may be changed to a value by an assignment;
Both of the above are acceptable uses of the word. I am of the mindset that the non-independent existence of these two meanings in both languages and in discourse are a large and fundamental problem.
I take the position that, inspired by mathematics, a variable should mean #1. Thereby making variables immutably bound to a fixed value. Meaning #2 should have some other name and require explicit use thereof.
From the PLT and Maths background, a mutable variable is somewhat oxymoronic. So, I agree let’s not copy JavaScript, but let’s also not be dismissive of the usage of terminology that has long standing meanings (even when the varied meanings of a single term are quite opposite).
antonvs|1 month ago
In a function f(x), x is a variable because each time f is invoked, a different value can be provided for x. But that variable can be immutable within the body of the function. That’s what’s usually being referred to by “immutable variable”.
This terminology is used across many different languages, and has nothing to do with Javascript specifically. For example, it’s common to describe pure functional languages by saying something like “all variables are immutable” (https://wiki.haskell.org/A_brief_introduction_to_Haskell).
esrauch|1 month ago
In Rust if you define with "let x = 1;" it's an immutable variable, and same with Kotlin "val x = 1;"
ekipan|1 month ago