Appearance
15. Guard Model
when is a universal execution guard.
It is a structured guard, not a full arbitrary boolean expression language.
Current direction:
- a single-condition guard may use inline form
- multi-condition guards use block form with
allorany checkis the predicate clause used inside block-form guards- inline
whenand block-formcheckuse the same predicate set
15.1 Inline Form
Inline form:
text
when <left-operand as required by predicate> <predicate> [right-operand as required by predicate]Rules:
- inline
whenbegins with the predicate's required left operand - the left operand must be an explicit KAL reference for
exists,empty,not_empty,is,is_not,contains,>,>=,<, and<= - the left operand for
inmay be a scalar literal, a string literal, or a readable KAL reference - inline
whencontains exactly one predicate clause - operand presence is determined by predicate arity
- inline
whendoes not support composition - inline
whendoes not support nesting - inline
whendoes not support wrapper negation &&,||, and!are not part of the currentwhensurface
Examples:
kdl
when inputs.enabled is #true
when inputs.count >= 1
when inputs.name not_empty15.2 Block Form
A when block contains one root condition group.
A condition group is either all or any.
An all or any group may contain:
checkpredicate clauses- nested
allgroups - nested
anygroups
Block form uses:
text
when
all
any
checkExample:
kdl
when {
all {
check inputs.enabled is #true
any {
check inputs.env is "prod"
check inputs.env is "staging"
}
}
}Group-level not is not part of the current draft.
15.3 Predicate Set
Current predicate set:
text
is
is_not
exists
empty
not_empty
contains
in
>
>=
<
<=Predicate forms:
| Predicate | Form |
|---|---|
exists | <reference> exists |
empty | <reference> empty |
not_empty | <reference> not_empty |
is | <reference> is <value> |
is_not | <reference> is_not <value> |
contains | <container> contains <item> |
in | <item> in <container> |
> / >= / < / <= | <reference> <predicate> <value> |
Rules:
exists,empty, andnot_emptydo not take a value operandis,is_not,contains,in,>,>=,<, and<=require a value operand- a predicate value operand may be a scalar literal, a string literal, or a readable KAL reference
- predicate value operands must not be function calls, general expressions, operator invocations, or inline object/array literals
- forms such as
when inputs.name exists #truefail validation
Direction:
isandis_notare equality predicates==and!=are not part of the currentwhensurfacecontainsis read as<container> contains <item>inis read as<item> in <container>