ReferenceReference

Operators

Reference Sugar arithmetic, comparison, boolean, membership, access, and assignment operators.

Arrow syntax

Sugar’s arrows declare three different relationships:

SyntaxNameMeaning
value -> "Label"Display arrowGive a Sugar value or declaration a visible label
name => valueMapping arrowMap a configuration name, match pattern, or random weight to its value or result
seat var value <- $memoryBind arrowBind Session seat state to hosted Memory

They are introduced with complete examples in Arrow syntax. They are not interchangeable assignment operators.

Arithmetic

ExpressionMeaning
x + yAdd numbers, concatenate compatible text, or concatenate two lists
x - ySubtract numbers or remove every matching entry in the right list from the left list
x * yMultiply
x / yDivide
x ^ yRaise x to the power y
x mod yRemainder 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

ExpressionMeaning
x == yEqual
x != yNot equal
x < yLess than
x <= yLess than or equal
x > yGreater than
x >= yGreater than or equal

Comparison results are booleans.

Boolean logic

ExpressionMeaning
x and yTrue when both values are true
x or yTrue when at least one value is true
not xInvert a boolean condition

List membership

value in list
value not in list

Example:

mood in ("PLAYFUL", "ROMANTIC")

Ranges

ExpressionValues produced
1..51, 2, 3, 4
1..=51, 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

StatementMeaning
x = valueReplace x
x += valueAdd to x
x -= valueSubtract from x
x *= valueMultiply x
x /= valueDivide x
x++ or ++xAdd 1
x-- or --xSubtract 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

SyntaxMeaning
1 => valueMatch one literal value
1 | 2 => valueMatch either pattern
1..5 => valueMatch 1 through 4
1..=5 => valueMatch 1 through 5
("A", _) => valueMatch an exact two-entry list structure
_ => valueMatch 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.