Skip to content
On this page

Fundamentals: Literals

Ara supports the following literals:

  • bool
  • int
  • float
  • string
  • null

Boolean literals

A boolean literal is either true or false.

$a = true;
$b = false;

Integer literals

An integer literal is a sequence of digits.

$a = 1234; // decimal number
$b = -123; // a negative number
$c = 0123; // octal number
$d = 0x1A; // hexadecimal number
$e = 0b11111111; // binary number

An integer literal may contain _ separators between digits, which are ignored by the compiler.

$a = 1_000_000; // same as 1000000

Floating-point literals

A floating-point literal is a sequence of digits, optionally followed by a decimal point, and optionally followed by an exponent.

$a = 1.234;
$b = 1.2e3;
$c = 7E-10;

A floating-point literal may contain _ separators between digits, which are ignored by the compiler.

$a = 1_000_000.000_001; // same as 1000000.000001

String literals

Single Quotes

A string literal enclosed in single quotes is a sequence of characters surrounded by single quotes.

$a = 'Hello, World!';

Double Quotes

A string literal enclosed in double quotes is a sequence of characters surrounded by double quotes.

INFO

The literal can contain any source character except double-quote " and backslash \, which can only be represented by their corresponding escape sequence, \" and \\.

$a = "Hello, World!";

certain characters can also be expressed as escape sequences. An escape sequence represents a single-character encoding. For example:

$a = "First line \nSecond line";

The following escape sequences are supported:

Escape SequenceDescriptionUnicode Character
\0The null characterU+0000
\\A backslashU+005C
\"A double quoteU+0022
\nA newline (line feed)U+000A
\rA carriage returnU+000D
\tA tabU+0009
\vA vertical tabU+000B
\eAn escapeU+001B
\fA form feedU+000C
\oooThe byte whose value is ooo (octal)
\xHHThe byte whose value is HH (hexadecimal)U+00HH
\u{HHHH}The Unicode code point whose value is HHHH (hexadecimal)U+HHHH

Null literal

The null literal is the only value of the null type.

$a = null;

Licensed under either of the MIT License or the Apache License (Version 2.0), at your option.