Introducing the notion of variable, in programming languages as well as in mathematics, is no easy task.
For starters, asking whether variables may vary can come handy, as an awakener: being familiar with a name (here: “variable”) does not mean that one knows what this name means.
The whole thing is actually non-trivial:
there are names (e.g., “mileage”);
Anton: Er, why “mileage”?Alfrothul: Your mileage may vary?Anton: Harrumph.
there are denotations: what the names stand for;
distinguishing between name and denotation is not obvious at all:
Besides, sometimes the mapping from name to denotation can be modified, as in Python, C, Java, etc., which seemingly makes it possible for variables, well, yes, to vary. In that light, ML’s take of having immutable names and having a specific kind of mutable values (namely references) is pretty logical: a variable does not vary, but the reference it denotes may mutate. (In denotational-semantics parlance, the environment maps names to locations and the store maps locations to storable values.)
Then there is scope, which determines where to look for to find the denotation of a name in its context: is this context lexical, i.e., solely based on where this name was declared (i.e., on the grammatical structure of the program at hand), or dynamic, i.e., also depending on when this name was declared last (i.e., on the way the program has been executed so far)?
And then there is also the binding strategy (call by value, call by name, call by need, call by reference, and whatnot), which determines the nature of what is denoted: the result of evaluating an expression (call by value), the promise of evaluating an expression (call by name), the promise of evaluating an expression and to remember the result of this evaluation (call by need), or then again the pointer to a denotable value (call by reference), the copy of a denotable value (call by copy/value), etc.
Not being aware of most of these dimensions (nor even of the existence of these dimensions), no wonder that newcomers find variables confusing: no simplistic explanation fits.
Loki: Never mind all of that. Let me tell you about recursive definitions.
In mathematics, a variable stands for all the possible things it might denote: an immensely convenient shorthand. Often, variables are referred to by the name of a representative variable, typically “x”, as in “the x of an equation” and in the title of Steven Strogatz‘s book, “The Joy of x”.
It is often considered good form that the name of a variable reflects the nature of what this variable denotes. That was part of the language definition of Fortran where variables whose name starts with I, J, K, L, M, or N denote integers and all the others denote floating-point numbers. Ditto in OCaml where capitalized names are used for data constructors, which includes exceptions. Adhering to the plural naming convention from Haskell is also considered good form.
And then there are situations where the prototypical name of a variable stands for what this variable denotes: an x-coordinate or a y-coordinate, a delta and an epsilon, etc., which newcomers have to take on faith to bootstrap their understanding.
Anton (surprised): And that’s all?
Alfrothul: Nothing about metavariables?
Dana (enjoying herself): And metasyntactic variables?
The present musing is the spinoff of an email exchange with Hanne Gottliebsen on 01 Feb 2020.