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.
Integer Literals
Section titled “Integer Literals”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 // decimal1_000 // decimal with separator0b111110100 // binary0x3E8 // hexadecimal uppercase0x3e8 // hexadecimal lowercase0o1750 // octalDefault integer literal type is i32.
Float Literals
Section titled “Float Literals”Float (or floating point numbers) are the same with other languages.
Example:
1.0 // default number1. // same number but shorter3.1415926535897932384626 // big numberDefault float literal type is f64.
Boolean Literals
Section titled “Boolean Literals”Boolean constants are keywords with specified type.
Keywords to use:
true, falseBoolean 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 Char
Section titled “Byte Char”Byte character literal is similar as char, but it returns u8 (unsigned 1 byte integer) type.
Usage:
b'a', b'\n'String
Section titled “String”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 String
Section titled “Raw String”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
