Chapter 3. Primitive Data Literals

Table of Contents
String
Character
Number
Yes_no (boolean)
Null

String

PPL supports three kinds of Unicode string literals:

  1. Single quoted string literal

    String literal in PPL

    The single quoted string literal in PPL works like the classical string literal used in many popular programming languages (C, Java, ...)

    The string is delimited by a pair of quotes (") and some characters must be escaped with a backslash (\).

    Examples:

    "Hello"        // Hello
    " "            // <space>
    "\""           // "
    "'"            // '
    "\t1"          // <horizontal tab>1
    "\r\n"         // <carriage return><line feed>
    "Hello\\\nTom" // Hello\<line feed>Tom
    "\u0038\u0039\u002f there" // hi? there
  2. Triple apostrophed string literal

    Triple apostrophed string literal in PPL

    The triple apostrophised string literal is delimited by a pair of three apostrophes ('''). Characters within the string are not escaped and the string can contain new lines.

    Examples:

    '''Hello'''
    
    '''string containing 3 lines
    line 2
    line 3'''
    
    '''Characters like \ and " don't need to be escaped!
    (very useful when defining regular expressions, file paths, SQL statements, etc.'''
  3. Triple quoted string literal

    Triple quoted string literal in PPL

    The triple quoted string literal is delimited by a pair of three quotes ("""). It extends the possibilities of the the triple apostrophed string by also supporting string interpolation. Expressions can be embedded in the string by surrounding them with {{ and }}.

    Example:

    const name = "Einstein"
    const quote = "Try not to become a man of success, but rather try to become a man of value."
    
    const message = """{{name.to_upper_case}} said:
    {{quote}}"""
    
    assert message =v '''EINSTEIN said:
    Try not to become a man of success, but rather try to become a man of value.'''
    

Character

Character literal in PPL

A character literal consists of one Unicode character or one escape character delimited by two apostrophes ('). It works like in Java.

Examples:

'a'       // a
' '       // <space>
'"'       // "
'\''      // '
'\t'      // <horizontal tab>
'\u002f'  // ?

Number

Number literals in PPL

There are two number literals:

  1. Integer number

    An integer literal consists of an optional minus sign (-), followed by one or more digits.

    Examples:

    0
    1
    123
    -2000
    [Note]Note

    PPL distinguishes between signed and unsigned integers, as well as integers that can or cannot be zero. The following graph shows the type inheritance for 32 bits integers:

                 signed_integer_32
                 ^               ^
        zero_negative_32  zero_positive_32
                 ^               ^
          negative_32       positive_32
    					

    Type compatibility is ensured by the compiler. For example, a positive integer is compatible to a signed integer, but the inverse is not true.

  2. Floating point number

    A floating point number consists of an optional minus sign (-), followed by one or more digits, followed by a fraction, optionally followed by a positive or negative exponent. The dot (.) is used as decimal separator. The exponent specifies a power of 10 by which the number is to be multiplied.

    Examples:

    123.45
    -123.45
    0.0
    1.0
    0.1
    1.0e3     // 1000
    1.0e-3    // 0.001
    -0.1e-3   // -0.0001

Yes_no (boolean)

yes/no literal in PPL

A yes_no literal has two possible values: yes and no.

Examples:

yes
no
[Note]Note

Other languages use the term boolean, instead of yes_no, and the possible values are true and false, instead of yes and no.

Null

Null literal in PPL

The null literal consists of the keyword null.

Example:

null