RiX walkthrough · 6a
Ternaries and cases
Choose values without losing expression flow.
Orientation
The ?? and ?: pair reads as condition, true branch, false branch. Each branch can be an expression or a code block.
Read this chapter with RatCalc open. Predict the result before running an example, then change a single part and run it again. That small loop of prediction, execution, and inspection is the fastest way to make RiX syntax feel like a language rather than a table of symbols.
A worked example
The final line is the displayed value; the earlier lines set up the experiment. Keep the setup visible so you can tell whether a name, a cell, or a collection is being reused when the expression changes.
Read the result
Case containers are useful when several guarded alternatives need to stay together.
Try a computed value
A prepared trial evaluates a candidate once, gives it a temporary name, and checks that name from left to right:
On success, the result is the original candidate. If candidate evaluation, binding, or a check fails, soft ?- returns _. The temporary value binding does not escape the trial.
Prepared trials become ordered alternatives inside a case container. A soft failure advances to the next arm:
Use ?!- for a fact that must hold. Gates can be mixed on the same candidate; the first gate also decides what happens if evaluating the candidate throws:
Here a non-integer is a recoverable failure, while an integer that is not positive is an error. Destructuring patterns work too, and a structural mismatch follows the gate's soft or strict policy:
Assignments use the same expression directly. A soft failure assigns _; a strict failure throws before the assignment commits:
Try a second value of your own. When an advanced feature depends on files, JavaScript, or extension registration, RatCalc explains the concept but does not grant browser permissions implicitly. Use the detail pages and the help panel to connect this experiment to the broader language rules.
Keep going
Return to the overview when you need context, or continue to the next sibling lesson for a focused variation. Collection chapters also end with method help that includes signatures and examples.