Syntax Overview
A tour of Nexus syntax generics, pattern matching, memory semantics, and more.
Comments
Nexus has two comment styles. Single line comments use /* ... . Block comments use /! … !/. This allows us to have the two types of divisions shown later. (As of 1.3 there are no documentation comments.)
comment styles
/* This is a single line comment. It ends automatically at the end of a line.
/! This is a block comment. This will span multiple lines. !/
Printf(" Hello, world!"); /! returns Hello, world!/
Arithmetic Operators
Division in Nexus distinguishes between true division and integer (floor) division, avoiding the common pitfall of silent integer truncation.
| Operator | Meaning | Example | Result |
|---|---|---|---|
/ | True division | 5 / 2 | 2.5 |
// | Integer (floor) division | 5 // 2 | 2 |
% | Modulo (remainder) | 5 % 2 | 1 |
+ | Addition | 3 + 4 | 7 |
- | Subtraction | 9 - 4 | 5 |
* | Multiplication | 3 * 4 | 12 |
++ | Increment | cpt++ | adds 1 |
-- | Decrement | cpt-- | subtracts 1 |
I/O & String Interpolation
Nexus provides two print functions. Printf evaluates interpolation expressions inside { } at runtime. Print outputs the string literally — no interpolation.
printf vs print
Printf(" 5 / 2 = {5/2} \n"); /* 5 / 2 = 2.5 */
Printf(" 5 // 2 = {5//2} \n"); /* 5 // 2 = 2 */
Printf(" 5 % 2 = {5%2} \n"); /* 5 % 2 = 1 */
Print(" 5 / 2 = {5/2}" ); /* 5 / 2 = {5/2} (literal) */
Print(" 5 // 2 = {5//2}"); /* 5 // 2 = {5//2} (literal) */
Note: Anything inside
{ } within a Printf string is a full expression — you can call functions, do math, and access fields there.
Conventions
Conventions in nexus are quite simple
| Object | Convention | Example |
|---|---|---|
| Functions/Classes/Methods | PascalCase | Main(); |
| Variable/Attributes | lowerCamalCase | i32 numExample = 5; |
| Constants | FULL_CAP_SNAKE_CASE | private const i32 NUM_USERS; |
| Static Object | prefixed with g_/G_ | private static g_GetTotalUsers(); |
| Indentation | Use tabs avoid spaces (personnal preference) | |
Note : Some of the object such as classes aren't implemented as of 1.3