Computer Programming Literal
A Computer Programming Literal is a computer programming syntax structure that represents a fixed value in source code.
- Context:
- It ranges from being a String Literal to being a Numeric Literal to being a Boolean Literal.
- It can be used to initialize Variables or Constants directly in the Source Code without needing further computation.
- It can (typically) be a part of Static Data within a program.
- It can be distinguished from Variables in that its value does not change at runtime.
- It can (often) be identified in the source code through specific notation or formatting, such as quotation marks for strings or decimal points for floating-point numbers.
- It can include complex types in some programming languages, such as Object Literals in JavaScript or Array Literals.
- It can vary in format and representation across different Programming Languages.
- …
- Example(s):
- Character Literal.
- Numeric Literal, such as: an integer literal, floating point literal.
- Imaginary Literal.
- String Literal,
- Boolean Literal.
- ...
- Conter-Example(s):
- See: Function Literals, Docstring, Source Code, Integer (Computer Science), Floating-Point Number, String (Computer Science), Boolean Datatype, Character (Computing), Enumerated Type, Array Data Structure, Record (Computer Science).
References
2020a
- (Wikipedia, 2020) ⇒ https://en.wikipedia.org/wiki/Literal_(computer_programming) Retrieved:2020-2-23.
- In computer science, a literal is a notation for representing a fixed value in source code. Almost all programming languages have notations for atomic values such as integers, floating-point numbers, and strings, and usually for booleans and characters; some also have notations for elements of enumerated types and compound values such as arrays, records, and objects. An anonymous function is a literal for the function type.
In contrast to literals, variables or constants are symbols that can take on one of a class of fixed values, the constant being constrained not to change. Literals are often used to initialize variables, for example, in the following, 1 is an integer literal and the three letter string in "cat" is a string literal:
<source lang="java">
int a = 1;
string s = "cat";
</source>
In lexical analysis, literals of a given type are generally a token type, with a grammar rule, like "a string of digits” for an integer literal. Some literals are specific keywords, like
true
for the boolean literal "true".In some object-oriented languages (like ECMAScript), objects can also be represented by literals. Methods of this object can be specified in the object literal using function literals. The brace notation below, which is also used for array literals, is typical for object literals:
<source lang="javascript">
{"cat", "dog"}
{name: "cat", length: 57}
</source>
- In computer science, a literal is a notation for representing a fixed value in source code. Almost all programming languages have notations for atomic values such as integers, floating-point numbers, and strings, and usually for booleans and characters; some also have notations for elements of enumerated types and compound values such as arrays, records, and objects. An anonymous function is a literal for the function type.
2020b
- (Python Doc., 2020) ⇒ "Literals". In: Python Documentation Content. Retrieved:2020-2-23.
- QUOTE: Literals are notations for constant values of some built-in types.
2004
- (Van Tassel, 2004) ⇒ Dennie Van Tassel (2004). ["http://www.gavilan.edu/csis/languages/literals.html Literals"]. Retrieved:2020-2-23.
- QUOTE: Literals or constants are the values we write in a conventional form whose value is obvious. In contrast to variables, literals (123, 4.3, "hi") do not change in value. These are also called explicit constants or manifest constants. I have also seen these called pure constants, but I am not sure if that terminology is agreed on. At first glance one may think that all programming languages type their literals the same way. While there are a lot of common conventions in different languages there are some interesting differences.