3 ms·
There’s two definitions of “literal” in widespread use. The first definition is as you say: an expression that has a constant value. The second definition is:
by zarzavat 4y ago
There’s two definitions of “literal” in widespread use.
The first definition is as you say: an expression that has a constant value.
The second definition is: an expression that is the primary syntactic form to construct a type. For example: “array literals” construct arrays, but may contain arbitrary expressions within.
The first definition is more common in low-level languages where there is a place in the compiled executable to put constant data. These languages might call the second form an initializer rather than a literal. But in a dynamic language such as Python the distinction is less important.
- SeanLuke 4y agoLisp uses the first definition. And it's as dynamic as they come. Java also uses the first definition. I suspect a more proper description would be: #1 is the correct definition, formally used for 80 years now. #2 is incorrect, and is being abused by people in JS and Python who should know better.