R/MRatCalcpowered by RiX

RiX walkthrough 4 c

Deferred execution

Delay and evaluate code deliberately.

Keep code for later

Prerequisites: Blocks and Scope and imports. A deferred value keeps code as a value until something asks to evaluate it. Use an ordinary function when the only goal is to reuse a calculation; deferral is for code that must be inspected or evaluated at a chosen time.

@{; ... } holds a block; .Eval() runs it. The output is 5.

Runnable RiX

Change the addition to multiplication and predict the result. The block is not evaluated merely by binding later.

Choose the evaluation boundary

.Eval can also evaluate a source string. @@later evaluates a deferred value directly in the caller's scope, so caller-visible names and updates require care. Keep ordinary functions and blocks for everyday calculations; use dynamic evaluation only when the scope is intentional.

Runnable RiX

Continue with RiX scripts for reusable programs with explicit capability boundaries.