def / define
def (alias define) creates a lightweight JavaScript-backed command. The command name is the output variable name, and the body receives all call arguments as args.
Syntax
@commandName def 'return args.join("|")'
@result commandName $v1 $v2 literal
Example
@v1 := Hello
@pipeConcat def 'return args.join("|")'
@v2 ?pipeConcat $v1 World!
@v3 ?:= $v1 World!
@v4 !pipeConcat $v1 World!
This example is based on tests/pipelines/basic/implicitConditionalsTest.mjs and runtime behavior validated by tests/pipelines/basic/forceExecutionTest.mjs. pipeConcat becomes a callable command after definition and can be guarded with ? or forced with !.
Step-by-Step Interaction
The line @pipeConcat def ... creates a new command entry named pipeConcat in the command registry, and the runtime keeps that function available for subsequent command calls in the same execution context. The line @v2 ?pipeConcat $v1 World! then invokes that newly declared command in guarded mode, which means execution only proceeds when every direct input is both defined and non-empty. The line @v3 ?:= $v1 World! demonstrates the same guarded execution rule on the built-in assign alias, while @v4 !pipeConcat ... shows forced execution where command evaluation is attempted on every build pass.
Runtime Behavior Notes
The runtime wraps the definition payload into a JavaScript function that receives an args array, and then it stores that function under the output variable name as a callable command symbol. This mechanism is intentionally lightweight and works well for short utility commands. When a workflow needs explicit named parameters, context imports via ~, or richer execution context handling, the runtime provides jsdef as the more expressive command-definition surface.