Learn SugarBeginner

Arrow syntax

Learn the three Sugar arrows, their names, and the distinct relationship each one declares.

Sugar has three arrow tokens:

ArrowNameRelationship
->Display arrowGives a value or declaration a human-facing label
=>Mapping arrowMaps a name, pattern, or weight on the left to a value or result on the right
<-Bind arrowConnects Session seat state to hosted Memory

They look related, but they are not interchangeable. Each arrow has one direction and one job.

Display arrow ->

The display arrow keeps a Sugar value or name on the left and gives it text to display on the right:

var difficulty -> "Challenge level": number = 5 with {
  input: true,
};

The variable is still named difficulty in code. A person sees Challenge level in the input instead.

The same arrow gives a choice value a different visible label:

var amount: choice = 20 with {
  input: true,
  choices: (
    10 -> "A little",
    20 -> "A drink",
    35 -> "A lot",
  ),
};

Choosing A drink stores the number 20, not the label. The left side is the Sugar identity or value; the right side is what people see.

Later declarations reuse that rule:

action inspect -> "Inspect the relic" {
  text "The relic hums in your hands.";
}

embed status -> "Relic status" {}

session moonlightRelay -> "Moonlight Relay" {}

The later lessons teach those declarations in full. In every case, -> supplies displayed text without changing the Sugar name or value on its left.

Mapping arrow =>

The mapping arrow pairs an entry on the left with its value on the right. Sugar uses it for compact configuration:

var difficulty: number = 5 with input => true, min => 1, max => 10;

Here, input maps to true, min maps to 1, and max maps to 10. This is equivalent to the block form:

var difficulty: number = 5 with {
  input: true,
  min: 1,
  max: 10,
};

Block entries use :. Compact inline entries use => and commas. The mapping arrow does not change a variable; assignments use = or an assignment operator instead.

Match expressions also use the mapping arrow because every pattern maps to a result:

match roll {
  1 => "Critical miss",
  20 => "Perfect roll",
  _ => "Regular roll",
}

The Match expressions lesson teaches patterns and arms later. The arrow keeps the same meaning: the left side selects an entry, and the right side supplies its result.

Weighted random choices use the same relationship:

Rand::weighted(3 => "COMMON", 1 => "RARE")

Here, each number maps its relative weight to a possible result. The Random choices and dice lesson explains how those weights affect the probability.

Bind arrow <-

The bind arrow belongs to Sessions. It connects a seat variable on the left to a hosted memory variable on the right:

seat var health <- $health;

The seat begins with its host Item’s $health. Changes to health during Session actions are saved back to that hosted Memory. This is a persistent connection, not a one-time assignment.

Sessions appear much later in the guide, after Apps and hosted variables. You do not need the rest of Session syntax yet; remember that <- means bind this seat state to that hosted Memory.

Read arrows by their role

value -> "Displayed label"
property => configuredValue
seatState <- $hostedMemory

Use the arrow’s name when explaining code: display arrow, mapping arrow, or bind arrow. Saying only “the arrow” hides which relationship the code declares.