ludic/examples/events/recurse.ludic
Orkuncakilkaya bf36bc8a8f refactor(runtime,packages,examples): named constants, package enums, idiom sweep
- runtime: HEADLESS_FRAME_PATH, STICK_DEADZONE / STICK_LEFT_X/Y, key and
  byte codes as char literals throughout (`k == 'w'`, `fill(rt_map, ' ', …)`)
- ludic.gameplay/stats: drop the duplicate `stat_field` (it answered "atk"
  for every build stat); Stats.base uses stats_field_name
- ludic.shooter: compare aim modes and fire patterns with AimMode.* and
  WeaponPattern.* instead of raw ints; STICK_RIGHT_X/Y
- ludic.npcai: DecisionMade / brain_set_state use AiState.*
- examples/games/menu.ludic uses Font.load / Ui.* with FONT_PATH and
  BACKDROP named; strings.ludic header says what it prints
- whole tree: `x = x + 1` → `x += 1` (single-term right-hand sides only),
  `0 - x` → `-x`, ASCII codes → char literals; every .ludic and every
  ```ludic fence reformatted with the fixed formatter (whitespace only)

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-05 01:12:26 +03:00

21 lines
728 B
Text

# recurse.ludic — EV6: re-entrant emit is bounded. Ping's listener emits Pong,
# Pong's listener emits Ping — an event cycle that would hang the frame forever.
# The depth bound (EV_DEPTH_CAP) makes the nesting trap as an early return, so the
# program terminates with a bounded count instead of spinning. This is the "no
# runaway event cycle" guarantee.
#
# Running it prints: 16 (the cycle bottoms out at the depth cap, deterministically)
program Recurse {
var n: int = 0
event Ping { }
event Pong { }
@On(Ping) handler A { n += 1; emit Pong() } # each Ping deepens by one Pong
@On(Pong) handler B { emit Ping() } # ...and each Pong by one Ping
entry {
emit Ping()
print(n)
}
}