On this page
Varc expressions
Varc expresses values with literals, names, calls/indexing, operators, aggregates, conditional forms and supported pipelines. The shared expression rules define meaning and proof obligations; this chapter defines source grouping and every expression family.
Operator precedence
From tightest to loosest:
| Level | Forms | Restrictions |
|---|---|---|
| Postfix | .member, (...), [...], ::Attribute(...) |
Extend the resolved prefix |
| Exponentiation | ** |
Cannot be chained; prefix on the left needs explicit parentheses |
| Prefix | - + ! abs * |
* dereferences; repeated prefixes group inward |
| Qualification | as Type |
Supplies expected type; not a C numeric cast |
| Multiplication | * / % %% |
Left to right |
| Addition | + - ++ |
Left to right |
| Shift | << >> |
Left to right; an arithmetic operand is parenthesised |
| Default | ?? |
An optional's value or the default; right to left |
| Pipe | |> |
Left to right; parenthesize before comparisons |
| Relation/bitwise | == != < <= > >= in !in or & | ^ |
Comparisons cannot chain; do not mix bitwise and comparison or different bitwise operators unparenthesized |
| Logical | && || |
Repeat one kind; parentheses required to mix |
The relation/bitwise row deliberately avoids inheriting C's or Rust's disagreement about x & 1 == 0. Write (x & 1) == 0. Write a || (b && c), not a || b && c. Use a < b && b < c rather than a < b < c.
-x ** 2 is diagnosed as unclear. Choose -(x ** 2) or (-x) ** 2 explicitly. For multiple powers, write a ** (b ** c) or (a ** b) ** c. Exponentiation is not a right-associative shorthand.
&& and || short-circuit. &, | and ^ operate through their supported Boolean/modular operations and are not short-circuit substitutes. Signed arithmetic cannot wrap silently. Division of integers truncates toward zero; % is remainder and %% modulus. Thus (-7) % 3 is −1 and (-7) %% 3 is 2.
Names, attributes and nominal conversions
A selected name is Package.Operation or value.field. The declared library spelling remains visible, for example Ada.Text_IO.Put_Line.
Attributes use :::
Natural::Last
values::Length
matrix::Length(2)
Integer::Image(count)
Shape::Class
These are expression/type fragments with suitable context. The complete attribute catalog defines valid prefixes and argument counts. :: is not a universal static-method namespace. For the result's attribute inside an appropriate contract, forms such as result::Length follow the same attribute spelling.
T(value) is a conversion when T resolves to a type. It can introduce range checks. value as T is qualification: it selects the value's expected type without being an unchecked representation conversion. In particular, (x: 1, y: 2) as Point can resolve a record aggregate's type. new T is allocation, not the same conversion.
Calls and indexing
clamp(value, low: 0, high: 100)
values[i]
matrix[i, j]
values[low...high]
Calls use parentheses and index/slice operations use brackets. The bracket check rejects using values(i) as indexing or f[x] as an ordinary call, with a targeted diagnostic. The type and visibility of the resolved prefix still determine valid arguments.
A call may have no arguments: reset(). Parameterless function values are also accepted through their resolved no-argument form. Use parentheses in ordinary Varc code to make the call explicit.
Named actuals use name: value. Positional actuals precede named actuals, and any omitted actual must have a declared default. Use & for actuals corresponding to out or inout:
increment(&count);
find(key, found: &found, position: &position);
An & mark on an in actual is an error; omitting it for a mutable formal is also an error. It is not permission to pass an expression that cannot be written, create arbitrary aliases, or take an unrestricted pointer.
A text, a list, a map and a set take Rust's names for their operations (s.to_upper(), xs.push(x), m.contains_key(k)), and a list, a map or a text is indexed with brackets from 0 or by key: see printing, texts and collections. p.0 is a tuple's first item. $"..." is an interpolated string.
A method-style call such as point.move(dx) selects the supported operation of the receiver type, including operations declared in impl. Method notation does not change contracts or the need for declared parameter modes.
Ranges and membership
low...high and low..=high both include the upper bound. low..<high excludes it. All three forms include the lower bound. Empty ranges have no iterations. A bounded low..high produces B0105. In an array type such as [Positive..]Integer, the suffix .. leaves the bounds to be supplied when declaring the array.
value in 0...100
value !in 0..=100
value in Small | Special
Membership choices are values, ranges or suitable subtype names. The type of the operand and choices must agree. With an array or a container as its only choice, x in xs asks whether x is one of its elements, and x !in xs whether it is not. A negative bound is an ordinary expression, not a Python index counted from the end.
Aggregates, updates and extension values
Arrays use brackets:
[1, 2, 3]
[others: 0]
[]
[for i in 1..=n => i * i]
These are context-dependent expressions. Empty brackets require a known supported aggregate type. An iterated value can filter with when before =>. The grammar also accepts named/index associations and boxes for supported defaults.
Records use parentheses with named components:
(x: 1, y: 2)
(base with x: 10)
(parent with new extra: 1)
()
The second is a delta update; the third is a tagged extension aggregate. () is a null record aggregate, not a Python empty tuple. A comma-separated positional aggregate and a parenthesized single expression are distinguished by their actual contents. Supply an expected type or qualify with as Type when inference cannot decide.
An aggregate creates a value under copying/ownership rules. A record update is not a mutation expression that silently changes base in place.
Conditional, match and declare expressions
if value < low { low } else if value > high { high } else { value }
match state { Idle | Done => 0, Busy => 1 }
{ let twice: Integer = value * 2; twice + 1 }
These are value fragments. Conditional branches and match arms must yield compatible values. A Boolean implication-style conditional may omit its else under the shared rules; ordinary value choice should supply one.
Match choices use |, ranges and _/others in the appropriate wildcard role. Expression arms yield expressions; statement match arms use braced bodies. There is no fallthrough.
An arm can add a guard, if condition, as in Rust: the arm is taken when the value is among its choices and the guard holds, and the arms are tried in order.
match n { 0...9 if n % 2 == 1 => Odd, 0...9 => Small, _ => Large }
A match with guards ends with an unguarded _ arm, or its unguarded arms cover every value between them (B0108 when no arm is unguarded, B2011 when they leave values out); each unguarded arm then first tries the guarded arms before it whose choices it shares. The value matched is a name (a statement match may match any value).
An arm of a data enum's match names its variant and the fields it reads: Circle { radius } binds radius, Rect { width: w, .. } binds w and ignores the rest, and Empty or Circle { .. } reads none. The names stand for the matched value's fields, which an expression match takes as a name. A declare expression has typed let/ref items followed by a final expression. Declarations require semicolons; the final value does not. This is narrower than a general statement block used as a value: arbitrary assignments/loops are not silently expressions.
Quantification and raises
forall i in a::Range => a[i] >= 0
exists x in values => x == key
The iterator introduces its bound name and can have supported reverse/filter details. These are logical value forms, distinct from general closures. An empty-domain forall is true; an empty-domain exists is false. Supported-source/proof/runtime limits still apply.
A raise expression is throw Exception_Name, optionally with Message, in an expression position where propagation is legal. It does not make failed proof obligations ordinary recoverable values.
Allocation, dereferencing and target names
new Node allocates the designated subtype. new Node(value: 7, next: null) supplies an initial record value through the supported aggregate form. A constrained allocation can use a bracket constraint. null denotes a null access value, and *pointer explicitly dereferences. Record-field selection can use the supported implicit dereference path.
Allocation yields ownership, with null/accessibility and cleanup requirements. It is not a shared garbage-collected reference.
@ in an assignment expression names the target value. Compound assignment uses this semantics so the target is represented once. x += y; is a statement; it does not yield an expression result usable in another calculation.
Pipelines, lambdas and the pipe
Inline x => expression lambdas are accepted only in the supported pipeline stage/consumer positions. They are not general first-class functions or callback values.
scores.filter(x => x >= mark).map(x => x + 1).sum()
scores |> filter(x => x >= mark) |> map(x => x + 1) |> sum()
value |> clamp(0, 100)
value |> clamp(0, _, 100)
In an ordinary piped call, the left value becomes the first argument unless a single _ marks another actual position. More than one placeholder is rejected. Pipe steps group left to right. Parenthesize when comparing the resulting value: (scores |> filter(x => x > 0) |> sum()) > limit.
A stage chain requires a consumer, and ordinary calls cannot interrupt unconsumed stages. A chain begins with a stage, zip or enumerate; reduce a whole array with scores::Reduce(operator+, 0).
Full stage/consumer/source vocabulary and optional-result restrictions are in advanced statements and pipelines.