Literals
Identifiers
In addition to letters, numbers, identifiers can also include any of the
following: +-*/<>=?. Identifiers may begin with an exclamation mark (!)
and/or a tilde (~) to indicate shadowing and mutability, respectively. If an
identifier uses both, the ! comes first.
The following are all valid identifiers:
name another-name x 2-tuple ≥ / ++ is-odd?
Note: Since the hyphen (-) can be part of an identifier, an expression like
x-y will be treated as a single identifier. Subtraction is written as x - y
instead.
Numbers
Basic numbers are straightforward:
123 123.456 -1.0 6.02E23
Veila also supports using commas as digit separators (which can be arbitrarily placed among the digits, except at the beginning or end):
123,456 123,456.789
12,34.5 – same as 1,234.5 or 1234.5
The formatter will format number literals to use digit separators to group three digits at a time.
Binary and hexadecimal numbers are written with prefixes:
B#0110,1100 H#2F6ACC
Number literals are inferred to have integer and float as their types (both
64 bits) unless otherwise specified.
Characters
Individual characters begin with a backslash:
\a \1 \\ \. \🈶
Special characters are spelled out:
\space \tab \newline \null
Characters have the type character.
Strings
String literals are wrapped in double quotation marks. Veila canonically uses
curved quotation marks (“ ”). but for ease of typing, the compiler also
accepts straight quotation marks (" ").
“This is a string.”
"This is a string."
String literals have the type string.
String interpolation
Single quotation marks are used to interpolate Veila expressions in strings. Similar to the double quotation marks, curved quotation marks are canonically used.
“The value of 1 + 2 is ‘1 + 2’.”
"The value of 1 + 2 is '1 + 2'."
– The value of 1 + 2 is 3.
Inner quotation marks
For the purpose of escaping quotation marks in strings, strings are considered nestable, which means that an opening quotation mark will escape a matching closing quotation mark:
“This is a “quote”.”
– This is a “quote”.
The opening quotation mark can be escaped to prevent this:
“This is a quotation mark: \“”
– This is a quotation mark: “
Similarly, the closing quotation mark can also be escaped to be prevented from matching an opening quotation mark:
“This is a quote: “This is a quotation mark: \”””
– This is a quote: “This is a quotation mark: ””
On the other hand, in the case of straight quotes, every straight quotation mark in the string will need to be escaped:
"This is a \"quote\"."
The formatter will convert the outer straight quotation marks into curved
quotation marks, escaping or unescaping characters as needed. Thus, the
abovementioned string will become “This is a "quote".” after formatting.
Booleans
The two Boolean values are #true and #false, which have the type Boolean.
Since they are literal values, they are written as keywords to prevent them from
being shadowed.
Unit
The sole value of the unit type value is #unit.
Tuples
Tuples are used to hold multiple values in a single data structure. They are denoted by braces and can be nested:
{1, “hello”}
{#true, {“nested”, 2}}
While the empty tuple is used by some languages to denote the unit type, it is not allowed in Veila.
Tuples of the form {a, b, c} have the type {a-type, b-type, c-type}. The
examples above have the types {integer, string} and
{Boolean, {string, integer}}, respectively.
Functions
Functions begin with a #, followed by a parenthesized list of arguments,
followed by the function body:
# (x, y) x + y
If a function expects no arguments, the parentheses can be removed:
# “This is a thunk.”
Functions have the type
#(parameter-1-type, parameter-2-type, … → return-type). The
functions page has a detailed description of the
different ways of declaring functions in Veila.