Primitive Types

The built-in primitive types in Nox are Int, Float, Bool, and String. Sometimes also called Primitives, or Scalars.

Int

The whole numbers. Can be negative.

Examples:

0
1
2
3
42
-13
9000000

To improve readability of large numbers, you can optionally use an underscore character as a thousand separator.

86_400      // seconds in a day
31_536_000  // seconds in a year

💡 Unlike other languages NaN (not-a-number) or positive/negative infinity aren't part of the Int type in Nox.

Since Nox compiles to JavaScript, there is a practical limit to the number of integers that can be represented: 25312^{53}-1 (defined herearrow-up-right).

Float

Floats are natural numbers with a decimal point and an arbitrary precision that is defined by the target low-level language Nox compiles to.

Float can use thousands separators, too:

Bool

A boolean represents either truth or falsehood.

Examples:

circle-info

A Bool isn't really a special built-in type in Nox, but just a pre-defined Enum Type that the language knows about. We'll cover Enum Types soon.

Str

Good old string literals. Strings in Nox are always Unicode strings. Nox doesn't have a Char type. A string can be either single-quoted (= the default idiomatic style), double-quoted, or backtick-quoted (for multi-line strings), or double-backtick quoted (for verbatim strings).

Single-quoted and double-quoted strings aren't fundamentally different.

Escaping

To escape characters, you can use a backslash:

However, it's considered idiomatic to favor another quoting style if that reduces the number of necessary escapes:

circle-info

Nox's built-in noxfmttool will automatically format string literals in the most idiomatic style, following these rules.

Multi-line strings

Multi-line string literals are strings that span multiple lines. To use them, use either a backtick-quoted or double-backtick quoted string literal. The difference between these is in how Nox handles white space in them.

With backtick-quoted strings, Nox will trim white space from the beginning and end of the string, as well as "unindent" the string's contents.

So in this example, this string literal is the same as 'The poet waits quietly\nto paint the unsaid\n\n –Atticus'. The benefit of this trimming and unindenting is that it doesn't matter at what indentation level the string literal occurs in the source code: it's contents will remain the same.

If this is undesirable, and you want to use a multi-line string literal that retains the white space exactly, use double backticks:

In this case, the string literal will be equivalent to '\n The poet waits quietly\n to paint the unsaid\n\n –Atticus\n'.

Template strings

All string literals in Nox also automatically allow for templating, using { and } to inline expressions.

These template strings are syntactic sugar for the following:

Last updated