Read the shape of a program
A runnable source file declares top-level functions, including a parameterless main. A function body is a brace-delimited block of statements and an optional final expression. A semicolon ends a let declaration, return statement or expression statement. A final expression without one supplies the block’s value.
Read names, literals and comments
Choose a name such as sensor_count. Start with a letter or underscore and use letters, digits or underscores after it. Names are case-sensitive. The lexer reads 10, 0b1010, 0o12 and 0xA as the same integer. Use underscores to group long numbers and e for a decimal exponent. A line comment begins with //. A block comment begins with /* and ends with */. Block comments may nest.
Value types
Use explicit scalar types for native function parameters and results. Vector elements are numeric. A unit-valued block completes without returning a useful value.
| Type | Example | Use |
|---|---|---|
| i64 | -12, 0, 42 | Checked integer arithmetic, counts and indices |
| f64 | 2.5, 1e-2 | Measurements, division with fractions and vector elements |
| bool | true, false | Conditions and logical combinations |
| str | "Blyx" | Text, labels and messages. The native subset also recognizes String. |
| vector | [2.0, 3.0] | An immutable sequence of numeric elements |
| unit (or omit the return annotation) | fn show() { println!(1); } | A function called for its effect |
Operator order
The rows are ordered from tightest binding to loosest among the operators used by the released interpreter here. Parentheses override the default order. Keep comparisons separate and join their boolean results with && or ||.
| Operators | Meaning | Example |
|---|---|---|
| ! and unary - | Boolean negation and numeric negation | !ready, -x |
| * / % | Multiply, divide, remainder | 7 / 2 yields 3 |
| + - | Add, subtract | 2 + 3 * 4 yields 14 |
| < <= > >= | Order comparisons | t >= 30.0 |
| == != | Equality and inequality | count != 0 |
| && | Short-circuit logical AND | ready && valid |
| || | Short-circuit logical OR | low || high |
| = += -= *= /= %= | Assign to a mutable binding | count += 1 |
Declarations and control flow
let binds, let mut permits updates and fn introduces a function. if selects a branch, while checks before each pass, and loop repeats unconditionally. break leaves the nearest loop, continue begins its next iteration, and return exits the current function. Nested braces introduce a scope.
Literal and boundary behavior
The signed integer range is −9,223,372,036,854,775,808 through 9,223,372,036,854,775,807. Integer overflow and division by zero fail in the interpreter. f64 has finite precision and follows IEEE floating-point arithmetic. Many decimal fractions have only approximate binary representations. For native examples, use decimal literals consistently when a fractional result matters.
Text and escape sequences
Write strings in double quotes. Inside a string, \n starts a new line, \t inserts a tab, \" inserts a quote, and \\ inserts a backslash. Strings may contain Unicode text. Use several print! calls to combine text with values. The interpreter also reads a single-quoted character as one character of text. Use double-quoted text in code you plan to build natively.
Use a branch as a value
The classify function below uses if and else to produce a result. Both branch blocks end in string expressions and have the same result type. show returns unit and exists to print the result. The explicit -> unit annotation may be omitted there. Function parameters and any native return values use the types in the table above.
Try the program
Expected output
true 1005 25 label even
Practice
Change the classifier call to use the integer eleven in hexadecimal. Predict the final line and check whether the other lines change.
Hint
In hexadecimal, the digits after 9 are A, B, C, D, E and F. Eleven divided by two leaves a remainder of one.
Worked solution
0xB is eleven. classify chooses the odd branch, and the earlier calculations still use the original literals.
Find
classify(10)Replace with
classify(0xB)Output after the change
true 1005 25 label odd