Literals are concrete values specified explicitly in the code. Except for array literals, they are fixed and cannot change during script execution. Array literals are more complex and discussed in section * ().
|
A number literal is a sequence of digits, with an optional decimal point, and an optional decimal exponent. The digits must not be separated by white space or thousands separators:
|
print 0 → 0
print 3.1415927→ 3.1415927
print 6.02214199e+23→ 6.022142E+23
print 1E-3→ 0.001
|
Integer numbers can also be written in hexadecimal notation, by prefixing them with 0x:
|
print 0xff → 255
print 0x1000→ 4096
|
|
A string literal is a sequence of characters between single or double quotes.
|
print 'Hello, world!' → Hello, world!
print "That's nice"→ That's nice
|
In order to produce all characters, the backslash \ serves as escape for the following character. For instance, if the quote used to delimit the string literal occurs inside the string, it must be escaped. Likewise, the backslash itself must be escaped, as is often seen in path names:
|
print "A quote: \"To be, or not to be...\"" → A quote: "To be, or not to be..."
print 'That\'s nice'→ That's nice
print "c:\\system\\apps"→ c:\system\apps
|
There are a few characters which have a special meaning when escaped:
| \f | form feed (ASCII 12) |
| \n | new line or line feed (ASCII 10) |
| \r | carriage return (ASCII 13) |
| \t | horizontal tab (ASCII 9) |
| \u | hexadecimal UNICODE® (UTF-16) follows |
|
print "Line1\nLine2" → Line1
print "Item1\tItem2"Line2 → Item1 Item2
print "g\u00e9nial"→ génial
|
The maximum length of a string literal is 256 characters.
|
Not surprisingly, there are just two boolean literals: true and false.
|
A function literal is a reference to a (already declared) function. Section * () explains function references.
|
The null literal denotes a "special" value which is different from all other values.
|