Skip to content

Constant Literals

A constant literal is compile-time data you set in your code.
Zeen supports 8 types of literals: integer, float, boolean, char, byte-char, str, raw-str, array.

There are 4 numerical systems supported by the compiler: decimal, hexadecimal, binary, octal.
Besides that language allows you to use _ separator for big numbers (idea taken from Rust).

Example:

/* 6 WAYS TO WRITE "1000" */
1000 // decimal
1_000 // decimal with separator
0b111110100 // binary
0x3E8 // hexadecimal uppercase
0x3e8 // hexadecimal lowercase
0o1750 // octal

Default integer literal type is i32.

Float (or floating point numbers) are the same with other languages.

Example:

1.0 // default number
1. // same number but shorter
3.1415926535897932384626 // big number

Default float literal type is f64.

Boolean constants are keywords with specified type.
Keywords to use:

true, false

Boolean literal type is bool.

A char is essentially an unsigned 1-byte integer that contains symbol representation inside.
To define char use single quote:

'a', '\n'

Character literal type is char.

Byte character literal is similar as char, but it returns u8 (unsigned 1 byte integer) type.
Usage:

b'a', b'\n'

Strings in Zeen may seem familiar like in C programming language.
Core mechanics are similar: string literal ends with ‘\0’ terminator.

To define string use double quotes:

"Hello, World!"
"Привет, Мир!"
"Xin Chào, Thế Giới!"

String literals use array type [N + 1]char (N chars + 1 for null terminator) and convert implicitly to []const char.

Raw strings are just another way to bake your string in source code and tell compiler where to stop.
It starts with r#" and ends with "#, that allows user to use any other symbols in this literal.

r#"
String literal,
still string,
we can even use "double quotes"
ends only now
"#

An array is a basic collection of ordered data in memory with a compile-time known size.
To define array use brackets:

[1, 2, 3, 4]

The array type is [N]T (example above is [4]i32)

Fast init with repeated value:

[0; 1024]

Type of example above is [1024]i32