Mistake in language guide

It's supposed to be "constant".

Hey Hakim, welcome to the forum.

I've definitely run into issues around this terminology before.

Across the programming field, "variable" typically refers to "any memory/object/thing/manipulable value", even if it's not actually variable (in that it can't "vary").

Three's a few difficulties:

  • The keyword let isn't similar to the word "constant"
  • let constants aren't really constants. If they're instances of classes, the instances are mutable (It's only the reference to them that's constant).
  • The word "variable" is similar to the keyword var, even though colloquially it's often used as a generic term that includes both var variables and let constants.
  • If "variable" is reserved for var variables, then I'm not sure what word you would use to generically refer to both var variables and let constants in a general manner.

Anybody got ideas?

1 Like

It's an immutable variable no?

There might be a more formally correct answer to this, but I think in programming the term "variable" is interchangeable with "identifiable/named value".

But in this case, roomCount would be "variable" in the sense that it could have a different value each time this code block is executed, depending on the room count. A constant should have an immutable value determined at compile time.

According to TSPL, constants are declared with let and variables with var.

So yes, I think it’s a mistake and it should be “roomCount constant”.

cc @Alex_Martini

This is not how it’s defined in TSPL, though:

A constant declaration defines an immutable binding between the constant name and the value of the initializer expression; after the value of a constant is set, it cannot be changed

(emphasis mine)

But I suppose the definition varies depending on who you ask...


Thanks for the warm welcome! The first welcome I got at StackOverflow on the other hand was quite the opposite lol. This means a lot to me.

And wow I didn't know all that! Thanks for the new knowledge bud. I see, so it's similar like when a class instance is assigned to a constant, how the stored properties would still adjustable. I am a beginner and was going through the language guide meticulously, was really hoping that I maybe could contribute lol.

First of all the language guide does refer to both "var" & "let" as "variables" here.


But I also see examples where the "variable*" is specifically referred to either as "constant" or "variable"

1 Like

especially here

Sorry I can only attach one picture at a time. Well that's quite inconvenient.

You can quote text using >

> Like this

So that it'll appear

Like this

If you then also link the page, we should be able to find the text alright. The toolbar also has a few useful markup tools you could play around with.

1 Like

I agree that it's confusing that "variable" has a double meaning: 1. a name/value which may be constant or variable, 2. a variable name/value.

Immutable variable is also a sensible term, depending on the context.

1 Like

This should be "constant". The reference > Patterns > Value-Binding Pattern has the following definition:

Value-binding patterns that bind a matched value to the name of a constant begin with the let keyword; those that bind to the name of variable begin with the var keyword.

I did some spot checks throughout the guide, and I consistently see that "constant" and "variable" are used as non-overlapping terms — in other words, a constant isn't a kind of variable. I wanted to check that specifically in the guide versus the reference because there are some terminology differences. For example, the guide says "a function or method" but the reference uses "function" to refer to both free functions and methods (aka member functions).

I've changed this in source (commit 728ff376) and the fix will go out with the next update.