Alpha: this compiler is under active development and updates will break your projects. Not recommended for real use yet.
Skip to content

If / elif / else ​

ts
ctx.if(s.greaterThan(20), (b) => { b.say("High"); b.say("Very") })
  .elif(s.equal(4), (b) => { b.say("Medium"); b.say("Four") })
  .else((b) => b.say("Low"));
text
main                       function ns:zzzprivate/main/if_0_chain
zzzprivate/main/if_0_chain execute if score ... matches 21.. run return run function .../if_0
                           execute if score ... matches 4 run return run function .../elif_0
                           say Low

return run stops at the first matching branch, so no condition is checked after a body ran. A lone if is one execute if ... run line. 16+ ranges on one score become a binary search.

Diagrams ​

Files from a nested if / elif / elsemainsay Hellofunction …/if_0_chainsay Endmain/if_0_chainif > 20 -> return run function …/if_0if = 4 -> return run function …/elif_0say Lowmain/if_0function …/if_0/if_0_chainsay Highmain/elif_0say Mediumsay Medium 2main/if_0/if_0_chainif = 4 -> return run say Exactly 4say High but not 4return run stops at the first branch that matches.One-line bodies (else, Exactly 4) stay inline.
Compiling a nested ifgenerateFunction.main.IfHandlerIfHandler .nested.dp.filesgenerateFunction(main)IfHandlerIfHandler (nested)dp.filesgenerateFunction(main)IfHandlerIfHandler (nested)dp.filesdispatch(if node)compile branch if_0save if_0/if_0_chain"function …/if_0/if_0_chain"save if_0, elif_0, if_0_chain"function …/if_0_chain"save main
IfElseNode - AST StructureIfElseNodeconditionthenBodyelifs[]elseBody?ExpressionNodeFunctionNodenodes[]ScoreRangeNodeScoreCompareNodeAndNode / OrNode / NotNodeClausesNodeA Detector (slot.has(), Detect.entity() …)ends up here as execute clauses.conditioneach branch body

Released under the MIT License · Credits
These docs were written with AI; the layout and every page have been reviewed by a human.