LogoMist

Expressions

The building blocks of logic, from literals to complex postfix chains.

Expressions in Mist are the fundamental units that evaluate to a value. The syntax follows a clean prefix -> primary -> postfix chain, providing a predictable structure.

Primary Expressions

Primary expressions are the starting point of any logic chain. These include literal values, paths to members, tuples, arrays, and basic statements.

let x = 42;
let y = Math::PI;
let coordinates = (10, 20, 30);

Postfix Operations

Postfix expressions allow you to build on a primary value with field access, calls, indexing, type casting, error propagation, and mutation operators.

let len = list.length();
s.len();
s.to_uppercase();

let task = Task {
    name: "Drafting",
    priority: 1,
};

let first = items[0];
println!("Value: {}", first);

Increment & Decrement

let mut i = 0;
i++;
i--;

Compound Assignments

i += 10;
i -= 5;
i *= 2;
i /= 3;
value &= mask;
flags |= 0x01;

Type Casting

Use as to convert between compatible types:

let x = 42;
let y = x as f64;

Try Operator

Propagate errors with the ? postfix operator:

let content = fs::read_to_string(path)?;

Range Operators

0..10        // exclusive range (0 to 9)
0..=10       // inclusive range (0 to 10)

Arrays

Arrays are initialized with brackets, with an optional repeat notation:

let arr = [1, 2, 3];
let zeros = [0; 10];        // ten zeroes

Prefix Operations

Prefixes modify the primary expression that follows them — dereference, reference, negation, and logical not.

let mut value = 10;

let ref = &value;
let mref = &mut value;
let val = *ref;
let is_false = !true;
let neg = -42;

Binary Operations

let sum = 10 + 20;
let is_equal = (x == y);
let complex = (a + b) * (c / d);

Operator Table

CategoryOperators
Arithmetic+, -, *, /, %
Comparison==, !=, <, >, <=, >=
Logical&&, `
Bitwise<<, >>, &, |, ^
Range.., ..=
Assign=, +=, -=, *=, /=, %=, &=, |=, ^=, <<=, >>=

Key Characteristics

  • Predictable Chaining: The prefix* ~ primary ~ postfix* grammar ensures complex expressions are parsed consistently.
  • Rust-Style References: Expressions use & and &mut to create references, maintaining borrow checker compatibility.
  • Macro Integration: Macros use ! as a postfix operation.
  • Type Casting: as Type provides explicit type conversion at the expression level.
  • Error Propagation: The ? operator enables early returns for Result/Option types.

On this page