ludic migrate state packages <every example program> packages/ludic.lab/example/plate.ludic 1804 vars into 126 states, 64 into lets; 23498 edits in 460 files Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
26 lines
902 B
Text
26 lines
902 B
Text
# answer.ludic — one listener per kind: each answers only for its own and returns early for
|
|
# every other. A `return` ends that listener, never the dispatch, so the listener for kind 2
|
|
# still hears the event after the one for kind 1 has returned.
|
|
#
|
|
# Running it prints: 10 20 0
|
|
program Answer {
|
|
event cancellable Ask { kind: int }
|
|
state AnswerState {
|
|
answer: int = 0
|
|
}
|
|
|
|
@On(Ask) handler One(answer_st: mut AnswerState) { if kind != 1 { return }; answer_st.answer = 10; cancel }
|
|
@On(Ask) handler Two(answer_st: mut AnswerState) { if kind != 2 { return }; answer_st.answer = 20; cancel }
|
|
|
|
function ask(answer_st: mut AnswerState, k: int) -> int {
|
|
answer_st.answer = 0
|
|
if emit Ask(kind: k) != 0 { return answer_st.answer }
|
|
return 0
|
|
}
|
|
|
|
entry (answer_st: mut AnswerState) {
|
|
print(ask(answer_st, 1))
|
|
print(ask(answer_st, 2))
|
|
print(ask(answer_st, 3))
|
|
}
|
|
}
|