Literals
Number
Underscores can be used as separators instead of commas to improve readability but aren’t significant otherwise.
Integer
An Int literal starts with a nonzero digit and don’t include a
fractional or exponential part. A negative integer literal is preceded
by the -
character.
10
-250
1_000_000
Integer literals can have the following base representation:
Base | Example |
---|---|
2 |
|
8 |
|
10 |
|
16 |
|
Decimal
A decimal literal includes a fractional part. Internally, these are handled as Doubles.
1.0
0.1
String
A String literal is a sequence of single-quoted string values or
double-quoted interpolated string values from the FQL-supported
character set, and terminated by null
.
Single-quoted Strings can include the "
and #
characters.
Double-quoted Strings can include the '
character.
Interpolated string
Double-quoted Strings support expression interpolation using the
#{<expr>}
character sequence, where <expr> is an FQL expression:
"Alice is #{3 + 2} years old."
"Alice is 5 years old."
See the escaped characters section for a list of escaped characters.
Heredoc string
A heredoc String is a way to write a string that spans multiple lines, enclosing the string with a beginning and ending user-defined token:
<<+TOKEN
A multiline string
with leading
whitespaces
TOKEN
<<-END
A multiline string
with leading
whitespaces
END
The token, on a line by itself, terminates the String.
On rendering, whitespace is removed from form each line, maintaining the same relative indentation for each line.
Heredoc strings support interpolation:
let weather = "overcast with occasional showers"
<<+EOS
Hello.
Today is #{weather}
EOS
<<-END
Hello.
Today is overcast with occasional showers
END
To declare a String with variables but without doing interpolation,
precede the String with a token in the format <<-TOKEN
:
<<-ASIS
str => "Hello #{str}"
ASIS
<<-END
str => "Hello #{str}"
END
You might want to avoid interpolation when defining a Function body, for
example. The #{str}
variable executes in the context of the function
instead of when the string is rendered.
Array
Arrays group items and are represented as a comma-separated list
of literals or expressions enclosed by [ ]
:
["a", 1 + 1, if (true) "true" else "false", null]
[
"a",
2,
"true",
null
]
Array members can be accessed individually using a single
variable. Members are indexed left to right, starting with 0. In the
example, the "a"
member is Array element 0 and the null
member is
array element 3:
let array = ["a", 1 + 1, if (true) "true" else "false", null]
[ array[0], array[3]]
[
"a",
null
]
Anonymous function
An anonymous function is represented using the short-form, JavaScript-like arrow function syntax:
([parameter[, parameter]]) => {[statement [statement … ]] expression [expression … ]}
Or, simplified:
(parameter) => { expression }
If the function has only one parameter, ()
can be omitted around the
parameter.
If the function body has only a single expression, the {}
block
delimiter can be omitted.
Is this article helpful?
Tell Fauna how the article can be improved:
Visit Fauna's forums
or email docs@fauna.com
Thank you for your feedback!