Types
Mux uses strict static typing with NO implicit type conversions. All type conversions must be explicit using conversion methods.
Primitive Types
Type Conversions
Numeric Conversions
String Parsing (Fallible Conversions)
String and char parsing methods return result<T, string> because they can fail:
No Implicit Conversions
The following operations are compile-time errors:
Conversion Methods Reference
| From Type | Method | Returns | Notes |
|---|---|---|---|
int | .to_string() | string | Converts to string representation |
int | .to_float() | float | Converts to floating-point |
int | .to_int() | int | Identity function |
float | .to_string() | string | Converts to string representation |
float | .to_int() | int | Truncates decimal part |
float | .to_float() | float | Identity function |
bool | .to_string() | string | Returns "true" or "false" |
bool | .to_int() | int | Returns 1 or 0 |
bool | .to_float() | float | Returns 1.0 or 0.0 |
char | .to_string() | string | Converts char to string |
char | .to_int() | result<int, string> | Digit value for '0'-'9' only |
string | .to_string() | string | Identity function |
string | .to_int() | result<int, string> | Parses string as integer |
string | .to_float() | result<float, string> | Parses string as float |
Composite Types
Tuples
Tuples are fixed size pairs. A tuple always has exactly two elements.
Tuples also support to_string() and a default constructor:
References
Mux supports references for safe memory access:
Reference Syntax:
- Create reference:
&variableor&expression - Dereference:
*reference(required for both reading and writing) - Pass to functions:
func(&int ref)declares parameter,update(&x)passes reference - References to references: Not supported
See Also
- Variables - Variable declarations and constants
- Collections - Lists, maps, and sets
- Error Handling - Using result and optional