Specifying values directly

This section describes how to specify values directly instead of as a result of calculations.

Specifying strings

To specify a string value directly, enclose the text in single or double quotation marks, for example "some text" or 'some text'. The two forms are equivalent. If the text contains the character used for the quoting (either " or ') or backslashes (/), you have to precede that character with a backslash; this is called escaping. You can type any other character, including line breaks, in the text directly. For example:

${"It's \"quoted\" and
this is a backslash: \\"}
 
${'It\'s "quoted" and
this is a backslash: \\'}  

produces this output:

It's "quoted" and
this is a backslash: \
 
It's "quoted" and
this is a backslash: \  

NOTE: Alternately, you can simply type the above text into the template without using ${...}.

The following table shows the list of all supported escape sequences. All other usage of a backlash in string literals is an error and any attempt to use the template will fail.

Escape sequence

Meaning

\"

Quotation mark (u0022)

\'

Apostrophe (a.k.a. apostrophe-quote) (u0027)

\\

Back slash (u005C)

\n

Line feed (u000A)

\r

Carriage return (u000D)

\t

Horizontal tabulation (a.k.a. tab) (u0009)

\b

Backspace (u0008)

\f

Form feed (u000C)

\l

Less-than sign: <

\g

Greater-than sign: >

\a

Ampersand: &

\xCode

Character given with its hexadecimal Unicode code (UCS code)*

*The Code after the \x is 1 to 4 hexadecimal digits. For example this will put a copyright sign into the string: "\xA9 1999-2001", "\x0A9 1999-2001", "\x00A9 1999-2001". When the character directly after the last hexadecimal digit can be interpreted as hexadecimal digit, you must use all 4 digits.

Note that the character sequence ${ (and #{) has special meaning. It is used to insert the value of expressions (typically, the value of variables, as in "Hello ${user}!"). If you want to print ${, you should use raw string literals as explained below. You can also use the sequence \x0024 to replace the $ sign. For example, the following produces the string ${ABC} in the output: "\x0024{ABC}”.

About raw string literals

Raw string literals are a special kind of string literal. In raw string literals, the backslash and ${ have no special meaning, they are considered plain characters. To indicate that a string literal is a raw string literal, put an r directly before the opening quotation mark. For example:

${r"${foo}"}
${r"C:\foo\bar"}  

produces this output:

${foo}
C:\foo\bar  

Specifying numbers

To specify a numerical value directly, type the number without quotation marks. Use the dot as the decimal separator and do not use any grouping separator symbols. You can use - or + to indicate the sign (+ is redundant). RPL does not support scientific notation (so 1E3 is incorrect). In addition, you cannot omit the 0 before the decimal separator (so .5 is incorrect).

Examples of valid number literals are: 0.08, -5.013, 8, 008, 11, +11

Note that numerical literals such as 08, +8, 8.00 and 8 are equivalent as they all symbolize the number eight. Thus, ${08}, ${+8}, ${8.00} and ${8} will all produce the same output.

Specifying booleans

To specify a boolean value, write true or false without quotation marks.

Specifying sequences

To specify a literal sequence, list the sub-variables separated by commas, and enclose the entire list in square brackets ([]). For example:

<#list ["winter", "spring", "summer", "autumn"] as x>
${x}
</#list>  

produces this output:

winter
spring
summer
autumn

The items in the list are expressions, so the following is correct:

[2 + 2, [1, 2, 3, 4], "whatnot"]

In the above example, the first sub-variable is the number 4, the second is another sequence, and the third sub-variable is the string "whatnot".

You can define sequences that store a numerical range with start..end, where start and end are expressions that resolve to numerical values. For example 2..5 (without the square brackets) is the same as [2, 3, 4, 5], but the former is much more efficient as it occupies less memory and is faster. You can define decreasing numerical ranges too, for example, 5..2. Furthermore, you can omit the end, for example 5.., in which case the sequence will contain 5, 6, 7, 8, ...etc. up to the infinity.

WARNING: Using the <#list> directive on infinite sequences can cause an infinite loop that will cause the template execution not to terminate.

Specifying hashes

To specify a hash in a template, list the key/value pairs separated by commas, and enclose the list in curly brackets ({}). The key and value within a key/value pair are separated by a colon. For example:

 {"name":"green mouse", "price":150}. 

Note that both names and values are expressions. However, lookup names must be strings.

Next steps

Retrieving variables

Handling missing values

Learn more

Expressions