Arrow syntax
Sugar’s arrows declare three different relationships:
| Syntax | Name | Meaning |
|---|---|---|
value -> "Label" | Display arrow | Give a Sugar value or declaration a visible label |
name => value | Mapping arrow | Map a configuration name, match pattern, or random weight to its value or result |
seat var value <- $memory | Bind arrow | Bind Session seat state to hosted Memory |
They are introduced with complete examples in Arrow syntax. They are not interchangeable assignment operators.
Arithmetic
| Expression | Meaning |
|---|---|
x + y | Add numbers, concatenate compatible text, or concatenate two lists |
x - y | Subtract numbers or remove every matching entry in the right list from the left list |
x * y | Multiply |
x / y | Divide |
x ^ y | Raise x to the power y |
x mod y | Remainder after division |
Use parentheses to make evaluation order clear:
(base + bonus) * multiplier
List arithmetic creates a new list without mutating either input:
let combined = common + rare;
let filtered = combined - blocked;
Comparison
| Expression | Meaning |
|---|---|
x == y | Equal |
x != y | Not equal |
x < y | Less than |
x <= y | Less than or equal |
x > y | Greater than |
x >= y | Greater than or equal |
Comparison results are booleans.
Boolean logic
| Expression | Meaning |
|---|---|
x and y | True when both values are true |
x or y | True when at least one value is true |
not x | Invert a boolean condition |
List membership
value in list
value not in list
Example:
mood in ("PLAYFUL", "ROMANTIC")
Ranges
| Expression | Values produced |
|---|---|
1..5 | 1, 2, 3, 4 |
1..=5 | 1, 2, 3, 4, 5 |
Range bounds must be whole numbers and the end cannot be below the start. A range contains at most 100 values.
Ranges are lists, so they work with membership and functions that accept a list:
score in 1..=10
Rand::pick(1..=20)
Property and index access
item.name
item["name"]
rewards[1]
value[key]
List indexes begin at 1. Missing or blocked object properties resolve safely instead of exposing JavaScript prototypes.
Namespace access
:: accesses a function grouped under a Sugar namespace:
Date::now()
Rand::pick(1..=20)
Id::short()
Use :: for a namespace function and . for a value’s property, as in Date::now().weekday.
Assignment
| Statement | Meaning |
|---|---|
x = value | Replace x |
x += value | Add to x |
x -= value | Subtract from x |
x *= value | Multiply x |
x /= value | Divide x |
x++ or ++x | Add 1 |
x-- or --x | Subtract 1 |
Assignments require a variable that can be changed in that type of Sugar program.
Nested assignment is supported:
character.stats.health--;
Conditional value
if condition then value else otherValue
This form returns one of two values and does not use braces. Statement-form decisions use brace bodies instead.
Match patterns
| Syntax | Meaning |
|---|---|
1 => value | Match one literal value |
1 | 2 => value | Match either pattern |
1..5 => value | Match 1 through 4 |
1..=5 => value | Match 1 through 5 |
("A", _) => value | Match an exact two-entry list structure |
_ => value | Match anything not handled earlier |
Inside match, the mapping arrow => separates a pattern from its result. The | pattern operator combines patterns in one arm.
Rand::weighted() also uses =>, with a numeric weight on the left and its possible result on the right.