Skip to content

13. Bindings

EBNF
bindings = bindings_none | bindings_partial | bindings_complete .
bindings_none = "with" "none" ";" .
bindings_partial = "with" "partial" ":" binding+ .
bindings_complete = "with" ":" binding+ .
binding = role_reference ":" expression .

Bindings precast one or more roles of a targeted construct—that is, they supply role values in advance rather than relying on the runtime’s casting process. Bindings appear in reactions, action searches, and sifting expressions.

There are three binding modes: complete, partial, and none.

Complete bindings are introduced by with followed by a colon and one or more binding entries. Complete bindings indicate that all roles of the targeted construct are being precast:

queue action confront:
with:
@confronter: @victim
@confronted: @attacker

Partial bindings are introduced by with partial followed by a colon and one or more binding entries. Partial bindings indicate that only some roles are precast; the remaining roles will be cast normally by the runtime:

queue action retaliate:
with partial:
@avenger: @target

None bindings are specified as with none; and indicate that no roles are precast. All roles will be cast by the runtime:

queue action wander:
with none;

This form is useful when the author wants to explicitly declare that no bindings are being passed, which may be required in some syntactic contexts.

A binding entry maps a role reference to an expression. The role reference names the role to precast, and the expression supplies the value:

@attacker: @insulter
@weapon: $@chosen_weapon
@location: ~getLocation()
EBNF
bindings_sugared = bindings_sugared_none
| bindings_sugared_partial
| bindings_sugared_complete .
bindings_sugared_none = "<" "none" ">" .
bindings_sugared_partial = "<" "partial" bindings_sugared_actual_bindings ">" .
bindings_sugared_complete = "<" bindings_sugared_actual_bindings ">" .
bindings_sugared_actual_bindings = binding { "," binding }
| positional_binding { "," positional_binding } .
positional_binding = expression .

Sugared bindings are a compact inline syntax for bindings, enclosed in angle brackets. They appear in trope fits. There are three forms, mirroring the standard binding modes:

// Complete sugared bindings
<@hero: @person, @villain: @enemy> fits trope rivalry
// Partial sugared bindings
<partial @hero: @person> fits trope rivalry
// None sugared bindings
<none> fits trope rivalry

Sugared bindings also support positional bindings, where expressions are matched to roles by position rather than by name:

<@person, @enemy> fits trope rivalry

In positional bindings, the expressions are bound to the targeted construct’s roles in the order they are defined. Positional and named bindings MUST NOT be mixed within a single sugared-bindings expression.