Lispex 2.0 specification · not released · Tested product not run · Examples not run

<a id="lispex.page.v2.conditions"></a>

# Conditions

Handle domain failures with lexical guards. Preserve structured conditions and terminal resource failures.

Canonical: /v2.0/en/docs/language/conditions

Document revision: 2.0-draft-1. Content locale: en. Translation: current.

- language: `lispex`
- languageVersion: `2.0`

<a id="lispex.section.v2.conditions.scope"></a>

## Scope

A rule can recover from a domain failure with a lexical guard. A terminal failure ends the request.

This chapter defines conditions and guards. [Resources](/v2.0/en/docs/language/resources) defines resource events. [CLI and diagnostics](/v2.0/en/docs/diagnostics/) defines diagnostic presentation.

<a id="lispex.section.v2.conditions.condition-data"></a>

## Condition codes and data

A condition contains a stable phase, code, and typed data. A guard reads those fields through the [condition accessors](/v2.0/en/docs/language/conditions#lispex.rule.v2.conditions.condition-catalog). Presentation follows [CLI and diagnostics](/v2.0/en/docs/diagnostics/).

A raised occurrence carries its own canonical program site. The [canonical-outcome rule](/v2.0/en/docs/profiles/receipt-and-replay#lispex.rule.v2.receipt-and-replay.canonical-outcome) reports that site. [Source maps](/v2.0/en/docs/tools/meaning-graph#lispex.section.v2.meaning-graph.source-maps) connect it to source text. A Condition value carries neither source coordinates nor a program site.

<a id="lispex.rule.v2.conditions.canonical-condition"></a>

### Expose stable condition data

A condition exposes a stable phase, code, and canonical typed data. Its raised occurrence supplies the canonical failure site. Presentation choices preserve those fields.

**Why**

Rules need to branch on the same failure across products and locales. Source paths and message wording would make that decision depend on presentation.

<a id="lispex.claim.v2.conditions.canonical-condition"></a>

Claim: `lispex.claim.v2.conditions.canonical-condition` · interaction · coverage partial · verification not-run

- language: `lispex`
- languageVersion: `2.0`

```json
{
  "predicate": {
    "kind": "condition-observation",
    "fixed": "same-semantic-failure",
    "varied": [
      "message-locale",
      "source-map",
      "host-stack"
    ]
  },
  "result": {
    "kind": "structured-condition",
    "invariant": [
      "stable-phase",
      "stable-code",
      "canonical-data"
    ],
    "guestPresentationFields": false,
    "occurrenceInvariant": [
      "canonical-site"
    ]
  },
  "pendingCases": [
    "Compare every condition family across products, supported engines, and architectures under the closed typed catalog."
  ]
}
```

<a id="lispex.example.v2.conditions.condition-presentation"></a>

### Keep a condition through presentation changes

Mode: illustrative. Stage: semantic-request. Verification: not-run.

- language: `lispex`
- languageVersion: `2.0`

File: `source.scm`

```lispex
(module main
  (import)
  (export rule)
  (entry rule)
  (define rule
    (lambda (input)
      (car input)))
)
```

File: `request.json`

```lispex
{
  "notation": "documentation-request",
  "source": "source.scm",
  "semantics": {
    "language": "Lispex 2.0",
    "standardLibrary": "one fixed library identity",
    "unicode": "one fixed Unicode semantics version",
    "resourceModel": "one fixed finite resource model"
  },
  "limits": {
    "prepare": "finite values sufficient to prepare this source",
    "evaluate": "finite values sufficient for the stated finite calculation"
  },
  "requests": [
    {
      "input": {
        "kind": "empty-list"
      }
    },
    {
      "input": {
        "kind": "empty-list"
      }
    }
  ],
  "executionContexts": [
    {
      "messageLocale": "en",
      "sourceLabel": "first.scm"
    },
    {
      "messageLocale": "ko",
      "sourceLabel": "renamed.scm"
    }
  ],
  "comparison": "Keep the canonical program and semantic request fixed while changing diagnostic presentation.",
  "rootModule": "main",
  "moduleSources": [
    {
      "name": "main",
      "source": "source.scm"
    }
  ]
}
```

Fixture inputs and environment:

```json
{
  "entry": "source.scm",
  "argv": [],
  "stdin": "",
  "cwd": ".",
  "environment": [],
  "wrapper": null,
  "packageRef": null,
  "lockRef": null,
  "generatedBindingRefs": {
    "knowledgeState": "not-applicable",
    "values": []
  }
}
```

#### Expected result

```json
{
  "status": "unspecified",
  "reason": "Both evaluations report the same car domain condition and canonical failure site. Neither returns a datum. Product invocation awaits its 2.0 adapter."
}
```

The request uses documentation notation. The diagnostic catalog fixes condition codes. Product execution awaits its 2.0 adapter.

<a id="lispex.rule.v2.conditions.condition-catalog"></a>

### Construct and inspect typed conditions

A Condition is an immutable internal value. Every code in this catalog has phase `evaluate`. The [diagnostic catalog](/v2.0/en/docs/diagnostics#lispex.rule.v2.cli-and-diagnostics.diagnostics.catalog) uses the same codes and field meanings.

A field record is a proper association list of dotted pairs. Each pair has a string key as its car and a field value as its cdr. Keys are unique. The constructor sorts them by unsigned UTF-8 bytes. This representation uses ordinary Datum values.

| Form | Meaning |
| --- | --- |
| `(make-condition code fields)` | Validate the closed schema and return a Condition. Construction does not raise that Condition. |
| `(condition? value)` | Return `#t` for a Condition and `#f` for every other value. |
| `(condition-phase condition)` | Return the string `evaluate`. |
| `(condition-code condition)` | Return the exact code string. |
| `(condition-data condition)` | Return the canonical immutable field record. |
| `(raise condition)` | Raise that Condition at the current canonical program site. |

The constructor uses the exact fields below. Each field is required. No additional field is accepted. Construction validates the data. It does not perform the operation named by a field.

| Code | Semantic fields | Meaning |
| --- | --- | --- |
| `runtime.not-callable` | `actual` uses `TypeTag` | The evaluated operator is not a procedure. |
| `runtime.arity` | `minimum` uses `Nat`, `maximum` uses `NatOrFalse`, `actual` uses `Nat` | The call has an unsupported argument count. A false maximum means no upper arity bound. |
| `runtime.value-count` | `expected` uses `Nat`, `actual` uses `Nat` | A context receives the wrong number of internal values. |
| `domain.type` | `operation` uses `Operation`, `argument` uses `Nat`, `path` uses `DataPath`, `expected` uses `TypeRequirement`, `actual` uses `TypeTag` | An argument component fails the required type. The path starts at that argument. |
| `domain.range` | `operation` uses `Operation`, `argument` uses `Nat`, `reason` uses `RangeReason` | An argument has an accepted type but violates a value constraint. |
| `domain.index` | `operation` uses `Operation`, `argument` uses `Nat`, `index` uses `Integer`, `length` uses `Nat` | The index is below zero or at least the sequence length. |
| `domain.equality` | `operation` uses `EqualityOperation`, `operand` uses `Operand`, `path` uses `DataPath`, `actual` uses `TypeTag` | An operand contains a value outside the comparison domain. The path identifies its first invalid component. |
| `domain.division-by-zero` | `operation` uses `Operation`, `argument` uses `Nat` | The operation requires division by exact zero. Its [library catalog row](/v2.0/en/docs/library/#lispex.rule.v2.standard-library.procedure-catalog) identifies the argument. |
| `domain.numeric` | `operation` uses `Operation`, `argument` uses `Nat`, `reason` uses `NumericReason` | An exact numeric operation fails the stated numeric requirement. |
| `domain.condition` | `reason` uses `ConditionReason`, `field` uses `StringOrFalse` | Condition construction rejects a code or field record. A false field names the whole input. |
| `domain.application` | `tag` uses `String`, `data` uses `Datum` | The program supplies its own tag and portable data. |

For unequal list lengths, identify the first list argument whose length differs from the first list. Check list arguments in argument order. Invalid slice ordering identifies the ending bound argument. Invalid UTF-8 identifies the bytevector argument. The owning library Rule determines when each value constraint fails.

Argument and entry positions start at zero. Counts and indices are exact integers. They never depend on host word size.

| Type | Semantic domain |
| --- | --- |
| `Nat` | An exact nonnegative integer |
| `Integer` | Any exact integer |
| `NatOrFalse` | `Nat` or `#f` |
| `String` | A raw Unicode string |
| `StringOrFalse` | `String` or `#f` |
| `Operation` | A string. An automatically raised condition uses the exact public procedure binding name. A constructed condition preserves its supplied string. |
| `EqualityOperation` | The string `eq?`, `eqv?`, or `equal?` |
| `Operand` | The exact integer `0` or `1` |
| `Datum` | Portable data from the [Datum definition](/v2.0/en/docs/language/values#lispex.section.v2.values.datum) |
| `DataPath` | A proper list of the segments below. An empty list selects the whole argument or operand. |

| Path segment | Selected component |
| --- | --- |
| `(car)` | Pair car |
| `(cdr)` | Pair cdr |
| `(index n)` | Vector element at the exact nonnegative index `n` |
| `(key s)` | Host record field with the exact string key `s` |

Path tags are symbols. A key segment describes a host record mapping. It does not introduce a guest record value kind.

| Enum | Exact string members |
| --- | --- |
| `TypeTag` | `boolean`, `integer`, `rational`, `character`, `symbol`, `empty-list`, `pair`, `string`, `vector`, `bytevector`, `procedure`, `condition` |
| `TypeRequirement` | Every `TypeTag`, `number`, `proper-list`, `scalar`, `datum`, `nonnegative-integer`, `positive-integer`, `rounding-mode` |
| `RangeReason` | `negative-count`, `invalid-scalar`, `invalid-byte`, `invalid-radix`, `invalid-scale`, `unequal-lengths`, `invalid-slice-order`, `invalid-utf8` |
| `NumericReason` | `nonintegral-exponent`, `nonpositive-base`, `invalid-rounding-mode`, `rounding-required` |
| `ConditionReason` | `unknown-code`, `terminal-code`, `payload-shape`, `key-type`, `duplicate-field`, `missing-field`, `extra-field`, `field-type` |

After ordinary call evaluation and arity checks, construction follows the order below. The first failed check ends construction.

| Order | Check | Failure |
| --- | --- | --- |
| 1 | The code is a string | `domain.type` for argument `0` with expected type `string` |
| 2 | The code belongs to this catalog | `domain.condition` with `unknown-code` or `terminal-code` and false `field` |
| 3 | The outer field list is proper | `domain.condition` with `payload-shape` and false `field` |
| 4 | Visit each entry in list order. Check its pair shape, string key, and key uniqueness before advancing. | A nonpair uses `payload-shape`. A nonstring key uses `key-type`. Both use false `field`. A repeated key uses `duplicate-field` and that key. |
| 5 | Every required key is present. Scan required keys in canonical order. | `domain.condition` with `missing-field` and the first missing key |
| 6 | Every supplied key belongs to the schema. Scan supplied keys in canonical order. | `domain.condition` with `extra-field` and the first unknown key |
| 7 | Every value has its declared type. Scan keys in canonical order. | `domain.condition` with `field-type` and the first invalid field key |

Enum values must match exactly. Paths have the exact segment shapes above. Portable data validation follows the [Datum traversal order](/v2.0/en/docs/language/values#lispex.rule.v2.values.equality-validation-order). Field values cannot contain a procedure or another Condition.

Each typed accessor and `raise` accepts one Condition. A different argument raises `domain.type` with expected type `condition`. `condition?` accepts any one internal value.

A Condition contains no source path, message, stack, or failure site. It is not a Datum. Data copied from its accessors remains ordinary portable data. Equality applied to a Condition follows the existing comparison domain rules.

A raised occurrence carries the Condition and its canonical program site. An unmatched guard propagates that same occurrence. Explicit `raise` creates an occurrence at its own site even when it uses a captured Condition.

Preparation, resource, admission, qualification, evidence, operational, and internal diagnostics have no guest Condition constructor. Boundary decoding and result validation also run outside an active guest guard. Their known codes cause `terminal-code` when passed to `make-condition`.

Construction, inspection, and raising use the ordinary [resource accounts](/v2.0/en/docs/language/resources). Payload limits use the named [resource model limits](/v2.0/en/docs/language/resources#lispex.pending.v2.resources.model-numbers). A failed reservation ends evaluation without truncating fields or running guest recovery.

**Why**

A closed code catalog gives every product the same recoverable failures. Typed fields make recovery independent of message text and host details. Ordinary association lists keep condition data inside the existing portable value model. A separate raised occurrence preserves useful failure locations without exposing source identity to guest code.

<a id="lispex.claim.v2.conditions.condition-catalog"></a>

Claim: `lispex.claim.v2.conditions.condition-catalog` · interaction · coverage partial · verification not-run

- language: `lispex`
- languageVersion: `2.0`

```json
{
  "predicate": {
    "kind": "condition-construction-and-inspection",
    "phase": "evaluate",
    "schemas": {
      "runtime.not-callable": {
        "actual": "TypeTag"
      },
      "runtime.arity": {
        "minimum": "Nat",
        "maximum": "NatOrFalse",
        "actual": "Nat"
      },
      "runtime.value-count": {
        "expected": "Nat",
        "actual": "Nat"
      },
      "domain.type": {
        "operation": "Operation",
        "argument": "Nat",
        "path": "DataPath",
        "expected": "TypeRequirement",
        "actual": "TypeTag"
      },
      "domain.range": {
        "operation": "Operation",
        "argument": "Nat",
        "reason": "RangeReason"
      },
      "domain.index": {
        "operation": "Operation",
        "argument": "Nat",
        "index": "Integer",
        "length": "Nat"
      },
      "domain.equality": {
        "operation": "EqualityOperation",
        "operand": "Operand",
        "path": "DataPath",
        "actual": "TypeTag"
      },
      "domain.division-by-zero": {
        "operation": "Operation",
        "argument": "Nat"
      },
      "domain.numeric": {
        "operation": "Operation",
        "argument": "Nat",
        "reason": "NumericReason"
      },
      "domain.condition": {
        "reason": "ConditionReason",
        "field": "StringOrFalse"
      },
      "domain.application": {
        "tag": "String",
        "data": "Datum"
      }
    },
    "constructor": "make-condition",
    "accessors": [
      "condition?",
      "condition-phase",
      "condition-code",
      "condition-data"
    ],
    "enums": {
      "TypeTag": [
        "boolean",
        "integer",
        "rational",
        "character",
        "symbol",
        "empty-list",
        "pair",
        "string",
        "vector",
        "bytevector",
        "procedure",
        "condition"
      ],
      "TypeRequirement": [
        "boolean",
        "integer",
        "rational",
        "character",
        "symbol",
        "empty-list",
        "pair",
        "string",
        "vector",
        "bytevector",
        "procedure",
        "condition",
        "number",
        "proper-list",
        "scalar",
        "datum",
        "nonnegative-integer",
        "positive-integer",
        "rounding-mode"
      ],
      "EqualityOperation": [
        "eq?",
        "eqv?",
        "equal?"
      ],
      "Operand": [
        "0",
        "1"
      ],
      "RangeReason": [
        "negative-count",
        "invalid-scalar",
        "invalid-byte",
        "invalid-radix",
        "invalid-scale",
        "unequal-lengths",
        "invalid-slice-order",
        "invalid-utf8"
      ],
      "NumericReason": [
        "nonintegral-exponent",
        "nonpositive-base",
        "invalid-rounding-mode",
        "rounding-required"
      ],
      "ConditionReason": [
        "unknown-code",
        "terminal-code",
        "payload-shape",
        "key-type",
        "duplicate-field",
        "missing-field",
        "extra-field",
        "field-type"
      ]
    }
  },
  "result": {
    "kind": "closed-immutable-condition",
    "fields": [
      "phase",
      "code",
      "data"
    ],
    "fieldRepresentation": "canonical-string-keyed-association-list",
    "siteInCondition": false,
    "presentationFields": false,
    "portableCondition": false,
    "constructorOrder": [
      "arity",
      "code-type",
      "code-membership",
      "proper-field-list",
      "entry-key-and-duplicate",
      "canonical-key-order",
      "missing-fields",
      "extra-fields",
      "field-types"
    ],
    "explicitRaiseSite": "current-raise-site",
    "unmatchedGuardSite": "original-occurrence-site"
  },
  "pendingCases": [
    "Run each condition code and constructor rejection on every product. Cover all enum values, nested paths, and finite payload resource boundaries."
  ]
}
```

<a id="lispex.example.v2.conditions.condition-runtime-families"></a>

### Report call and value count failures

Mode: illustrative. Stage: semantic-request. Verification: not-run.

- language: `lispex`
- languageVersion: `2.0`

File: `source.scm`

```lispex
(module main
  (import)
  (export rule)
  (entry rule)
  (define rule
    (lambda (input)
      (if (= input 0)
          (0 1)
          (if (= input 1)
              ((lambda (a b) a) 1)
              (+ (values 1 2) 3)))))
)
```

File: `request.json`

```lispex
{
  "notation": "documentation-request",
  "source": "source.scm",
  "semantics": {
    "language": "Lispex 2.0",
    "standardLibrary": "one fixed library identity",
    "unicode": "one fixed Unicode semantics version",
    "resourceModel": "one fixed finite resource model"
  },
  "limits": {
    "prepare": "finite values sufficient to prepare each source",
    "evaluate": "finite values sufficient for each stated calculation and complete condition encoding"
  },
  "requests": [
    {
      "input": {
        "kind": "integer",
        "value": "0"
      }
    },
    {
      "input": {
        "kind": "integer",
        "value": "1"
      }
    },
    {
      "input": {
        "kind": "integer",
        "value": "2"
      }
    }
  ],
  "rootModule": "main",
  "moduleSources": [
    {
      "name": "main",
      "source": "source.scm"
    }
  ]
}
```

Fixture inputs and environment:

```json
{
  "entry": "source.scm",
  "argv": [],
  "stdin": "",
  "cwd": ".",
  "environment": [],
  "wrapper": null,
  "packageRef": null,
  "lockRef": null,
  "generatedBindingRefs": {
    "knowledgeState": "not-applicable",
    "values": []
  }
}
```

#### Expected result

```json
{
  "status": "unspecified",
  "reason": "The requests identify a nonprocedure operator, a wrong argument count, and a wrong internal value count. Product execution awaits its 2.0 adapter."
}
```

The request uses documentation notation. Diagnostic fields use their typed representation. This example fixes no result or receipt bytes. Product execution remains not-run.

<a id="lispex.example.v2.conditions.condition-domain-payloads"></a>

### Construct domain fields and unbounded arity

Mode: illustrative. Stage: semantic-request. Verification: not-run.

- language: `lispex`
- languageVersion: `2.0`

File: `source.scm`

```lispex
(module main
  (import)
  (export rule)
  (entry rule)
  (define rule
    (lambda (input)
      (let ((condition (make-condition (car input) (cdr input))))
        (list (condition-phase condition)
              (condition-code condition)
              (condition-data condition)))))
)
```

File: `request.json`

```lispex
{
  "notation": "documentation-request",
  "source": "source.scm",
  "semantics": {
    "language": "Lispex 2.0",
    "standardLibrary": "one fixed library identity",
    "unicode": "one fixed Unicode semantics version",
    "resourceModel": "one fixed finite resource model"
  },
  "limits": {
    "prepare": "finite values sufficient to prepare each source",
    "evaluate": "finite values sufficient for each stated calculation and complete condition encoding"
  },
  "requests": [
    {
      "input": {
        "kind": "pair",
        "car": {
          "kind": "string",
          "value": "domain.type"
        },
        "cdr": {
          "kind": "list",
          "items": [
            {
              "kind": "pair",
              "car": {
                "kind": "string",
                "value": "path"
              },
              "cdr": {
                "kind": "empty-list"
              }
            },
            {
              "kind": "pair",
              "car": {
                "kind": "string",
                "value": "operation"
              },
              "cdr": {
                "kind": "string",
                "value": "car"
              }
            },
            {
              "kind": "pair",
              "car": {
                "kind": "string",
                "value": "expected"
              },
              "cdr": {
                "kind": "string",
                "value": "pair"
              }
            },
            {
              "kind": "pair",
              "car": {
                "kind": "string",
                "value": "argument"
              },
              "cdr": {
                "kind": "integer",
                "value": "0"
              }
            },
            {
              "kind": "pair",
              "car": {
                "kind": "string",
                "value": "actual"
              },
              "cdr": {
                "kind": "string",
                "value": "empty-list"
              }
            }
          ]
        }
      }
    },
    {
      "input": {
        "kind": "pair",
        "car": {
          "kind": "string",
          "value": "domain.range"
        },
        "cdr": {
          "kind": "list",
          "items": [
            {
              "kind": "pair",
              "car": {
                "kind": "string",
                "value": "reason"
              },
              "cdr": {
                "kind": "string",
                "value": "negative-count"
              }
            },
            {
              "kind": "pair",
              "car": {
                "kind": "string",
                "value": "operation"
              },
              "cdr": {
                "kind": "string",
                "value": "make-vector"
              }
            },
            {
              "kind": "pair",
              "car": {
                "kind": "string",
                "value": "argument"
              },
              "cdr": {
                "kind": "integer",
                "value": "0"
              }
            }
          ]
        }
      }
    },
    {
      "input": {
        "kind": "pair",
        "car": {
          "kind": "string",
          "value": "domain.index"
        },
        "cdr": {
          "kind": "list",
          "items": [
            {
              "kind": "pair",
              "car": {
                "kind": "string",
                "value": "operation"
              },
              "cdr": {
                "kind": "string",
                "value": "vector-ref"
              }
            },
            {
              "kind": "pair",
              "car": {
                "kind": "string",
                "value": "length"
              },
              "cdr": {
                "kind": "integer",
                "value": "3"
              }
            },
            {
              "kind": "pair",
              "car": {
                "kind": "string",
                "value": "index"
              },
              "cdr": {
                "kind": "integer",
                "value": "-1"
              }
            },
            {
              "kind": "pair",
              "car": {
                "kind": "string",
                "value": "argument"
              },
              "cdr": {
                "kind": "integer",
                "value": "1"
              }
            }
          ]
        }
      }
    },
    {
      "input": {
        "kind": "pair",
        "car": {
          "kind": "string",
          "value": "runtime.arity"
        },
        "cdr": {
          "kind": "list",
          "items": [
            {
              "kind": "pair",
              "car": {
                "kind": "string",
                "value": "minimum"
              },
              "cdr": {
                "kind": "integer",
                "value": "1"
              }
            },
            {
              "kind": "pair",
              "car": {
                "kind": "string",
                "value": "maximum"
              },
              "cdr": {
                "kind": "boolean",
                "value": false
              }
            },
            {
              "kind": "pair",
              "car": {
                "kind": "string",
                "value": "actual"
              },
              "cdr": {
                "kind": "integer",
                "value": "0"
              }
            }
          ]
        }
      }
    }
  ],
  "rootModule": "main",
  "moduleSources": [
    {
      "name": "main",
      "source": "source.scm"
    }
  ]
}
```

Fixture inputs and environment:

```json
{
  "entry": "source.scm",
  "argv": [],
  "stdin": "",
  "cwd": ".",
  "environment": [],
  "wrapper": null,
  "packageRef": null,
  "lockRef": null,
  "generatedBindingRefs": {
    "knowledgeState": "not-applicable",
    "values": []
  }
}
```

#### Expected result

```json
{
  "status": "unspecified",
  "reason": "The constructor preserves each typed field and returns keys in canonical order. A false maximum denotes an arity without an upper bound. Product execution awaits its 2.0 adapter."
}
```

The request uses documentation notation. Diagnostic fields use their typed representation. This example fixes no result or receipt bytes. Product execution remains not-run.

<a id="lispex.example.v2.conditions.condition-equality-paths"></a>

### Locate invalid equality operands

Mode: illustrative. Stage: semantic-request. Verification: not-run.

- language: `lispex`
- languageVersion: `2.0`

File: `source.scm`

```lispex
(module main
  (import)
  (export rule)
  (entry rule)
  (define rule
    (lambda (input)
      (if (= input 0)
          (eq? (vector 1) #f)
          (if (= input 1)
              (eqv? #f "text")
              (equal? (list 1 (lambda () 0)) '(1 2))))))
)
```

File: `request.json`

```lispex
{
  "notation": "documentation-request",
  "source": "source.scm",
  "semantics": {
    "language": "Lispex 2.0",
    "standardLibrary": "one fixed library identity",
    "unicode": "one fixed Unicode semantics version",
    "resourceModel": "one fixed finite resource model"
  },
  "limits": {
    "prepare": "finite values sufficient to prepare each source",
    "evaluate": "finite values sufficient for each stated calculation and complete condition encoding"
  },
  "requests": [
    {
      "input": {
        "kind": "integer",
        "value": "0"
      }
    },
    {
      "input": {
        "kind": "integer",
        "value": "1"
      }
    },
    {
      "input": {
        "kind": "integer",
        "value": "2"
      }
    }
  ],
  "rootModule": "main",
  "moduleSources": [
    {
      "name": "main",
      "source": "source.scm"
    }
  ]
}
```

Fixture inputs and environment:

```json
{
  "entry": "source.scm",
  "argv": [],
  "stdin": "",
  "cwd": ".",
  "environment": [],
  "wrapper": null,
  "packageRef": null,
  "lockRef": null,
  "generatedBindingRefs": {
    "knowledgeState": "not-applicable",
    "values": []
  }
}
```

#### Expected result

```json
{
  "status": "unspecified",
  "reason": "Scalar comparison rejects aggregate operands. Structural comparison identifies the nested procedure in the left list. Product execution awaits its 2.0 adapter."
}
```

The request uses documentation notation. Diagnostic fields use their typed representation. This example fixes no result or receipt bytes. Product execution remains not-run.

<a id="lispex.example.v2.conditions.condition-numeric-families"></a>

### Keep exact numeric failure fields

Mode: illustrative. Stage: semantic-request. Verification: not-run.

- language: `lispex`
- languageVersion: `2.0`

File: `source.scm`

```lispex
(module main
  (import)
  (export rule)
  (entry rule)
  (define rule
    (lambda (input)
      (let ((condition (make-condition (car input) (cdr input))))
        (list (condition-phase condition)
              (condition-code condition)
              (condition-data condition)))))
)
```

File: `request.json`

```lispex
{
  "notation": "documentation-request",
  "source": "source.scm",
  "semantics": {
    "language": "Lispex 2.0",
    "standardLibrary": "one fixed library identity",
    "unicode": "one fixed Unicode semantics version",
    "resourceModel": "one fixed finite resource model"
  },
  "limits": {
    "prepare": "finite values sufficient to prepare each source",
    "evaluate": "finite values sufficient for each stated calculation and complete condition encoding"
  },
  "requests": [
    {
      "input": {
        "kind": "pair",
        "car": {
          "kind": "string",
          "value": "domain.division-by-zero"
        },
        "cdr": {
          "kind": "list",
          "items": [
            {
              "kind": "pair",
              "car": {
                "kind": "string",
                "value": "operation"
              },
              "cdr": {
                "kind": "string",
                "value": "/"
              }
            },
            {
              "kind": "pair",
              "car": {
                "kind": "string",
                "value": "argument"
              },
              "cdr": {
                "kind": "integer",
                "value": "1"
              }
            }
          ]
        }
      }
    },
    {
      "input": {
        "kind": "pair",
        "car": {
          "kind": "string",
          "value": "domain.numeric"
        },
        "cdr": {
          "kind": "list",
          "items": [
            {
              "kind": "pair",
              "car": {
                "kind": "string",
                "value": "reason"
              },
              "cdr": {
                "kind": "string",
                "value": "nonintegral-exponent"
              }
            },
            {
              "kind": "pair",
              "car": {
                "kind": "string",
                "value": "operation"
              },
              "cdr": {
                "kind": "string",
                "value": "expt"
              }
            },
            {
              "kind": "pair",
              "car": {
                "kind": "string",
                "value": "argument"
              },
              "cdr": {
                "kind": "integer",
                "value": "1"
              }
            }
          ]
        }
      }
    }
  ],
  "rootModule": "main",
  "moduleSources": [
    {
      "name": "main",
      "source": "source.scm"
    }
  ]
}
```

Fixture inputs and environment:

```json
{
  "entry": "source.scm",
  "argv": [],
  "stdin": "",
  "cwd": ".",
  "environment": [],
  "wrapper": null,
  "packageRef": null,
  "lockRef": null,
  "generatedBindingRefs": {
    "knowledgeState": "not-applicable",
    "values": []
  }
}
```

#### Expected result

```json
{
  "status": "unspecified",
  "reason": "Numeric condition construction preserves the exact operation, argument position, and reason. It performs no numeric operation. Product execution awaits its 2.0 adapter."
}
```

The request uses documentation notation. Diagnostic fields use their typed representation. This example fixes no result or receipt bytes. Product execution remains not-run.

<a id="lispex.example.v2.conditions.condition-accessors"></a>

### Inspect an application condition

Mode: illustrative. Stage: semantic-request. Verification: not-run.

- language: `lispex`
- languageVersion: `2.0`

File: `source.scm`

```lispex
(module main
  (import)
  (export rule)
  (entry rule)
  (define rule
    (lambda (input)
      (let ((condition (make-condition "domain.application" input)))
        (list (condition? condition)
              (condition? input)
              (condition-phase condition)
              (condition-code condition)
              (condition-data condition)))))
)
```

File: `request.json`

```lispex
{
  "notation": "documentation-request",
  "source": "source.scm",
  "semantics": {
    "language": "Lispex 2.0",
    "standardLibrary": "one fixed library identity",
    "unicode": "one fixed Unicode semantics version",
    "resourceModel": "one fixed finite resource model"
  },
  "limits": {
    "prepare": "finite values sufficient to prepare each source",
    "evaluate": "finite values sufficient for each stated calculation and complete condition encoding"
  },
  "requests": [
    {
      "input": {
        "kind": "list",
        "items": [
          {
            "kind": "pair",
            "car": {
              "kind": "string",
              "value": "tag"
            },
            "cdr": {
              "kind": "string",
              "value": "invalid-input"
            }
          },
          {
            "kind": "pair",
            "car": {
              "kind": "string",
              "value": "data"
            },
            "cdr": {
              "kind": "list",
              "items": [
                {
                  "kind": "integer",
                  "value": "7"
                },
                {
                  "kind": "string",
                  "value": "field"
                }
              ]
            }
          }
        ]
      }
    }
  ],
  "rootModule": "main",
  "moduleSources": [
    {
      "name": "main",
      "source": "source.scm"
    }
  ]
}
```

Fixture inputs and environment:

```json
{
  "entry": "source.scm",
  "argv": [],
  "stdin": "",
  "cwd": ".",
  "environment": [],
  "wrapper": null,
  "packageRef": null,
  "lockRef": null,
  "generatedBindingRefs": {
    "knowledgeState": "not-applicable",
    "values": []
  }
}
```

#### Expected result

```json
{
  "status": "unspecified",
  "reason": "The accessors return a fixed phase, a code string, and canonical portable fields. The original association list remains ordinary data. Product execution awaits its 2.0 adapter."
}
```

The request uses documentation notation. Diagnostic fields use their typed representation. This example fixes no result or receipt bytes. Product execution remains not-run.

<a id="lispex.example.v2.conditions.condition-constructor-rejections"></a>

### Reject malformed condition construction

Mode: illustrative. Stage: semantic-request. Verification: not-run.

- language: `lispex`
- languageVersion: `2.0`

File: `source.scm`

```lispex
(module main
  (import)
  (export rule)
  (entry rule)
  (define rule
    (lambda (input)
      (make-condition (car input) (cdr input))))
)
```

File: `request.json`

```lispex
{
  "notation": "documentation-request",
  "source": "source.scm",
  "semantics": {
    "language": "Lispex 2.0",
    "standardLibrary": "one fixed library identity",
    "unicode": "one fixed Unicode semantics version",
    "resourceModel": "one fixed finite resource model"
  },
  "limits": {
    "prepare": "finite values sufficient to prepare each source",
    "evaluate": "finite values sufficient for each stated calculation and complete condition encoding"
  },
  "requests": [
    {
      "input": {
        "kind": "pair",
        "car": {
          "kind": "string",
          "value": "domain.unknown"
        },
        "cdr": {
          "kind": "empty-list"
        }
      }
    },
    {
      "input": {
        "kind": "pair",
        "car": {
          "kind": "string",
          "value": "value.boundary"
        },
        "cdr": {
          "kind": "empty-list"
        }
      }
    },
    {
      "input": {
        "kind": "pair",
        "car": {
          "kind": "string",
          "value": "runtime.not-callable"
        },
        "cdr": {
          "kind": "integer",
          "value": "7"
        }
      }
    },
    {
      "input": {
        "kind": "pair",
        "car": {
          "kind": "string",
          "value": "runtime.not-callable"
        },
        "cdr": {
          "kind": "list",
          "items": [
            {
              "kind": "integer",
              "value": "7"
            }
          ]
        }
      }
    },
    {
      "input": {
        "kind": "pair",
        "car": {
          "kind": "string",
          "value": "runtime.not-callable"
        },
        "cdr": {
          "kind": "list",
          "items": [
            {
              "kind": "pair",
              "car": {
                "kind": "symbol",
                "value": "actual"
              },
              "cdr": {
                "kind": "string",
                "value": "integer"
              }
            }
          ]
        }
      }
    },
    {
      "input": {
        "kind": "pair",
        "car": {
          "kind": "string",
          "value": "runtime.not-callable"
        },
        "cdr": {
          "kind": "list",
          "items": [
            {
              "kind": "pair",
              "car": {
                "kind": "string",
                "value": "actual"
              },
              "cdr": {
                "kind": "string",
                "value": "integer"
              }
            },
            {
              "kind": "pair",
              "car": {
                "kind": "string",
                "value": "actual"
              },
              "cdr": {
                "kind": "string",
                "value": "pair"
              }
            }
          ]
        }
      }
    },
    {
      "input": {
        "kind": "pair",
        "car": {
          "kind": "string",
          "value": "runtime.not-callable"
        },
        "cdr": {
          "kind": "empty-list"
        }
      }
    },
    {
      "input": {
        "kind": "pair",
        "car": {
          "kind": "string",
          "value": "runtime.not-callable"
        },
        "cdr": {
          "kind": "list",
          "items": [
            {
              "kind": "pair",
              "car": {
                "kind": "string",
                "value": "unused"
              },
              "cdr": {
                "kind": "integer",
                "value": "0"
              }
            },
            {
              "kind": "pair",
              "car": {
                "kind": "string",
                "value": "actual"
              },
              "cdr": {
                "kind": "string",
                "value": "integer"
              }
            }
          ]
        }
      }
    },
    {
      "input": {
        "kind": "pair",
        "car": {
          "kind": "string",
          "value": "runtime.not-callable"
        },
        "cdr": {
          "kind": "list",
          "items": [
            {
              "kind": "pair",
              "car": {
                "kind": "string",
                "value": "actual"
              },
              "cdr": {
                "kind": "integer",
                "value": "7"
              }
            }
          ]
        }
      }
    }
  ],
  "rootModule": "main",
  "moduleSources": [
    {
      "name": "main",
      "source": "source.scm"
    }
  ]
}
```

Fixture inputs and environment:

```json
{
  "entry": "source.scm",
  "argv": [],
  "stdin": "",
  "cwd": ".",
  "environment": [],
  "wrapper": null,
  "packageRef": null,
  "lockRef": null,
  "generatedBindingRefs": {
    "knowledgeState": "not-applicable",
    "values": []
  }
}
```

#### Expected result

```json
{
  "status": "unspecified",
  "reason": "Unknown and terminal codes are rejected. Malformed lists, keys, repeated fields, missing fields, extra fields, and mistyped fields are separate failures. Product execution awaits its 2.0 adapter."
}
```

The request uses documentation notation. Diagnostic fields use their typed representation. This example fixes no result or receipt bytes. Product execution remains not-run.

<a id="lispex.example.v2.conditions.condition-raise-sites"></a>

### Separate a condition from its raised site

Mode: illustrative. Stage: semantic-request. Verification: not-run.

- language: `lispex`
- languageVersion: `2.0`

File: `source.scm`

```lispex
(module main
  (import)
  (export rule)
  (entry rule)
  (define rule
    (lambda (input)
      (guard (condition (#f 0))
        (car input))))
)
```

File: `explicit-raise.scm`

```lispex
(module main
  (import)
  (export rule)
  (entry rule)
  (define rule
    (lambda (input)
      (guard (condition (else (raise condition)))
        (car input))))
)
```

File: `request.json`

```lispex
{
  "notation": "documentation-request",
  "source": "source.scm",
  "semantics": {
    "language": "Lispex 2.0",
    "standardLibrary": "one fixed library identity",
    "unicode": "one fixed Unicode semantics version",
    "resourceModel": "one fixed finite resource model"
  },
  "limits": {
    "prepare": "finite values sufficient to prepare each source",
    "evaluate": "finite values sufficient for each stated calculation and complete condition encoding"
  },
  "requests": [
    {
      "source": "source.scm",
      "input": {
        "kind": "empty-list"
      },
      "rootModule": "main",
      "moduleSources": [
        {
          "name": "main",
          "source": "source.scm"
        }
      ]
    },
    {
      "source": "explicit-raise.scm",
      "input": {
        "kind": "empty-list"
      },
      "rootModule": "main",
      "moduleSources": [
        {
          "name": "main",
          "source": "explicit-raise.scm"
        }
      ]
    }
  ],
  "siteNotation": {
    "original-car": "the car call in source.scm",
    "explicit-raise": "the raise call in explicit-raise.scm"
  },
  "rootModule": "main",
  "moduleSources": [
    {
      "name": "main",
      "source": "source.scm"
    }
  ]
}
```

Fixture inputs and environment:

```json
{
  "entry": "source.scm",
  "argv": [],
  "stdin": "",
  "cwd": ".",
  "environment": [],
  "wrapper": null,
  "packageRef": null,
  "lockRef": null,
  "generatedBindingRefs": {
    "knowledgeState": "not-applicable",
    "values": []
  }
}
```

#### Expected result

```json
{
  "status": "unspecified",
  "reason": "An unmatched guard preserves the car failure site. Explicit raise reports its own site with the same condition fields. Product execution awaits its 2.0 adapter."
}
```

The request uses documentation notation. Diagnostic fields use their typed representation. This example fixes no result or receipt bytes. Product execution remains not-run.

<a id="lispex.example.v2.conditions.condition-accessor-types"></a>

### Reject noncondition accessor and raise arguments

Mode: illustrative. Stage: semantic-request. Verification: not-run.

- language: `lispex`
- languageVersion: `2.0`

File: `source.scm`

```lispex
(module main
  (import)
  (export rule)
  (entry rule)
  (define rule
    (lambda (input)
      (if (= input 0)
          (condition-code 7)
          (if (= input 1)
              (raise 7)
              (make-condition 7 '())))))
)
```

File: `request.json`

```lispex
{
  "notation": "documentation-request",
  "source": "source.scm",
  "semantics": {
    "language": "Lispex 2.0",
    "standardLibrary": "one fixed library identity",
    "unicode": "one fixed Unicode semantics version",
    "resourceModel": "one fixed finite resource model"
  },
  "limits": {
    "prepare": "finite values sufficient to prepare each source",
    "evaluate": "finite values sufficient for each stated calculation and complete condition encoding"
  },
  "requests": [
    {
      "input": {
        "kind": "integer",
        "value": "0"
      }
    },
    {
      "input": {
        "kind": "integer",
        "value": "1"
      }
    },
    {
      "input": {
        "kind": "integer",
        "value": "2"
      }
    }
  ],
  "rootModule": "main",
  "moduleSources": [
    {
      "name": "main",
      "source": "source.scm"
    }
  ]
}
```

Fixture inputs and environment:

```json
{
  "entry": "source.scm",
  "argv": [],
  "stdin": "",
  "cwd": ".",
  "environment": [],
  "wrapper": null,
  "packageRef": null,
  "lockRef": null,
  "generatedBindingRefs": {
    "knowledgeState": "not-applicable",
    "values": []
  }
}
```

#### Expected result

```json
{
  "status": "unspecified",
  "reason": "The accessor and raise reject an integer in place of a Condition. Construction rejects an integer in place of a code string. Product execution awaits its 2.0 adapter."
}
```

The request uses documentation notation. Diagnostic fields use their typed representation. This example fixes no result or receipt bytes. Product execution remains not-run.

<a id="lispex.example.v2.conditions.condition-result-boundary"></a>

### Reject a Condition at the result boundary

Mode: illustrative. Stage: semantic-request. Verification: not-run.

- language: `lispex`
- languageVersion: `2.0`

File: `source.scm`

```lispex
(module main
  (import)
  (export rule)
  (entry rule)
  (define rule
    (lambda (input)
      (guard (condition (else 0))
        (make-condition "domain.application" input))))
)
```

File: `request.json`

```lispex
{
  "notation": "documentation-request",
  "source": "source.scm",
  "semantics": {
    "language": "Lispex 2.0",
    "standardLibrary": "one fixed library identity",
    "unicode": "one fixed Unicode semantics version",
    "resourceModel": "one fixed finite resource model"
  },
  "limits": {
    "prepare": "finite values sufficient to prepare each source",
    "evaluate": "finite values sufficient for each stated calculation and complete condition encoding"
  },
  "requests": [
    {
      "input": {
        "kind": "list",
        "items": [
          {
            "kind": "pair",
            "car": {
              "kind": "string",
              "value": "tag"
            },
            "cdr": {
              "kind": "string",
              "value": "invalid-input"
            }
          },
          {
            "kind": "pair",
            "car": {
              "kind": "string",
              "value": "data"
            },
            "cdr": {
              "kind": "list",
              "items": [
                {
                  "kind": "integer",
                  "value": "7"
                },
                {
                  "kind": "string",
                  "value": "field"
                }
              ]
            }
          }
        ]
      }
    }
  ],
  "rootModule": "main",
  "moduleSources": [
    {
      "name": "main",
      "source": "source.scm"
    }
  ]
}
```

Fixture inputs and environment:

```json
{
  "entry": "source.scm",
  "argv": [],
  "stdin": "",
  "cwd": ".",
  "environment": [],
  "wrapper": null,
  "packageRef": null,
  "lockRef": null,
  "generatedBindingRefs": {
    "knowledgeState": "not-applicable",
    "values": []
  }
}
```

#### Expected result

```json
{
  "status": "unspecified",
  "reason": "The guard completes with a Condition value. Entry result validation rejects it outside guest recovery. Product execution awaits its 2.0 adapter."
}
```

The Condition value is internal. The field data remains portable. Result validation runs after the guard has completed. Product execution remains not-run.

<a id="lispex.section.v2.conditions.guard-grammar"></a>

## Guard syntax

<a id="lispex.grammar.v2.conditions.guard"></a>

### EBNF · source · complete · transcribed

- language: `lispex`
- languageVersion: `2.0`

```ebnf
guard = "(" "guard" "(" identifier clause* ")" body ")"
body = definition* expression+
clause = "(" test expression+ ")"
       | "(" test ")"
       | "(" test "=>" recipient ")"
       | "(" "else" expression+ ")"
test = expression
recipient = expression
```

Imported productions: known; identifier, definition, expression.

Omitted productions: known; .

Identifiers follow [Source and normalization](/v2.0/en/docs/language/source). Definitions and expressions follow [Evaluation](/v2.0/en/docs/language/evaluation). Recursive body definitions follow the lambda initializer restriction.



<a id="lispex.section.v2.conditions.lexical-guard"></a>

## Lexical guard

A lexical guard protects evaluation of its body, including calls made while that body runs. Its condition name is a lexical binding for its clauses. A matching clause computes the replacement value. Evaluation does not resume at the failed operation.

Structured raise propagates a condition. It cannot create a continuation or install a dynamic handler.

<a id="lispex.rule.v2.conditions.lexical-guard"></a>

### Recover from an ordinary condition

A lexical guard may catch a runtime or domain condition from its body. It abandons the failed body and returns the selected clause result. That result preserves its internal value count. The result reaches the guard expression's continuation. A body failure preserves the enclosing call's pending return. The [tail-position rule](/v2.0/en/docs/language/evaluation#lispex.rule.v2.evaluation.tail-calls) governs the protected body and selected handler clause.

**Why**

A rule can handle expected input failures without reentering a failed operation or changing the execution boundary.

The enclosing continuation remains available after a body failure.

<a id="lispex.claim.v2.conditions.lexical-guard"></a>

Claim: `lispex.claim.v2.conditions.lexical-guard` · interaction · coverage partial · verification not-run

- language: `lispex`
- languageVersion: `2.0`

```json
{
  "predicate": {
    "kind": "guard-body-evaluation",
    "failures": [
      "runtime",
      "domain"
    ]
  },
  "result": {
    "kind": "abortive-recovery",
    "replacement": "selected-clause-value-packet",
    "resumesFailureSite": false
  },
  "pendingCases": [
    "Exercise nested calls, tail positions, multiple internal values, and every catchable condition family on all supported products and engines."
  ]
}
```

<a id="lispex.example.v2.conditions.guard-recovery"></a>

### Recover from an empty pair input

Mode: illustrative. Stage: semantic-request. Verification: not-run.

- language: `lispex`
- languageVersion: `2.0`

File: `source.scm`

```lispex
(module main
  (import)
  (export rule)
  (entry rule)
  (define rule
    (lambda (input)
      (guard (condition
               (else 0))
        (car input))))
)
```

File: `request.json`

```lispex
{
  "notation": "documentation-request",
  "source": "source.scm",
  "semantics": {
    "language": "Lispex 2.0",
    "standardLibrary": "one fixed library identity",
    "unicode": "one fixed Unicode semantics version",
    "resourceModel": "one fixed finite resource model"
  },
  "limits": {
    "prepare": "finite values sufficient to prepare this source",
    "evaluate": "finite values sufficient for the stated finite calculation"
  },
  "requests": [
    {
      "input": {
        "kind": "empty-list"
      }
    }
  ],
  "rootModule": "main",
  "moduleSources": [
    {
      "name": "main",
      "source": "source.scm"
    }
  ]
}
```

Fixture inputs and environment:

```json
{
  "entry": "source.scm",
  "argv": [],
  "stdin": "",
  "cwd": ".",
  "environment": [],
  "wrapper": null,
  "packageRef": null,
  "lockRef": null,
  "generatedBindingRefs": {
    "knowledgeState": "not-applicable",
    "values": []
  }
}
```

#### Expected result

```json
{
  "status": "unspecified",
  "reason": "The car domain condition selects the guard clause. The rule returns the exact integer 0. Product invocation awaits its 2.0 adapter."
}
```

The request uses documentation notation. The diagnostic catalog fixes condition codes. Product execution awaits its 2.0 adapter.

<a id="lispex.example.v2.conditions.guard-success"></a>

### Return the successful body value

Mode: illustrative. Stage: semantic-request. Verification: not-run.

- language: `lispex`
- languageVersion: `2.0`

File: `source.scm`

```lispex
(module main
  (import)
  (export rule)
  (entry rule)
  (define rule
    (lambda (input)
      (guard (condition
               (else 0))
        (car input))))
)
```

File: `request.json`

```lispex
{
  "notation": "documentation-request",
  "source": "source.scm",
  "semantics": {
    "language": "Lispex 2.0",
    "standardLibrary": "one fixed library identity",
    "unicode": "one fixed Unicode semantics version",
    "resourceModel": "one fixed finite resource model"
  },
  "limits": {
    "prepare": "finite values sufficient to prepare this source",
    "evaluate": "finite values sufficient for the stated finite calculation"
  },
  "requests": [
    {
      "input": {
        "kind": "list",
        "items": [
          {
            "kind": "integer",
            "value": "3"
          },
          {
            "kind": "integer",
            "value": "5"
          }
        ]
      }
    }
  ],
  "rootModule": "main",
  "moduleSources": [
    {
      "name": "main",
      "source": "source.scm"
    }
  ]
}
```

Fixture inputs and environment:

```json
{
  "entry": "source.scm",
  "argv": [],
  "stdin": "",
  "cwd": ".",
  "environment": [],
  "wrapper": null,
  "packageRef": null,
  "lockRef": null,
  "generatedBindingRefs": {
    "knowledgeState": "not-applicable",
    "values": []
  }
}
```

#### Expected result

```json
{
  "status": "unspecified",
  "reason": "The successful car call returns 3. The recovery clause is not evaluated. Product invocation awaits its 2.0 adapter."
}
```

The request uses documentation notation. The diagnostic catalog fixes condition codes. Product execution awaits its 2.0 adapter.

<a id="lispex.rule.v2.conditions.structured-raise"></a>

### Propagate a structured condition

Structured raise signals a Condition with its stable phase, code, and data. It records the site of that explicit raise. It never resumes the operation that produced an earlier occurrence.

**Why**

Explicit propagation preserves a failure that the current rule cannot handle. A resumable signal would add control behavior outside the adopted surface.

<a id="lispex.claim.v2.conditions.structured-raise"></a>

Claim: `lispex.claim.v2.conditions.structured-raise` · interaction · coverage partial · verification not-run

- language: `lispex`
- languageVersion: `2.0`

```json
{
  "predicate": {
    "kind": "structured-raise",
    "argument": "condition"
  },
  "result": {
    "kind": "condition-propagation",
    "preserves": [
      "code",
      "canonical-data"
    ],
    "continuable": false,
    "raisedSite": "current-explicit-raise-site"
  },
  "pendingCases": [
    "Settle condition construction and accessor forms, then test explicit raise, invalid payloads, nested propagation, and resource boundaries on every product."
  ]
}
```

<a id="lispex.example.v2.conditions.raise-condition"></a>

### Propagate the caught condition

Mode: illustrative. Stage: semantic-request. Verification: not-run.

- language: `lispex`
- languageVersion: `2.0`

File: `source.scm`

```lispex
(module main
  (import)
  (export rule)
  (entry rule)
  (define rule
    (lambda (input)
      (guard (condition
               (else (raise condition)))
        (car input))))
)
```

File: `request.json`

```lispex
{
  "notation": "documentation-request",
  "source": "source.scm",
  "semantics": {
    "language": "Lispex 2.0",
    "standardLibrary": "one fixed library identity",
    "unicode": "one fixed Unicode semantics version",
    "resourceModel": "one fixed finite resource model"
  },
  "limits": {
    "prepare": "finite values sufficient to prepare this source",
    "evaluate": "finite values sufficient for the stated finite calculation"
  },
  "requests": [
    {
      "input": {
        "kind": "empty-list"
      }
    }
  ],
  "siteNotation": {
    "raise-site": "the explicit raise call in the recovery clause"
  },
  "rootModule": "main",
  "moduleSources": [
    {
      "name": "main",
      "source": "source.scm"
    }
  ]
}
```

Fixture inputs and environment:

```json
{
  "entry": "source.scm",
  "argv": [],
  "stdin": "",
  "cwd": ".",
  "environment": [],
  "wrapper": null,
  "packageRef": null,
  "lockRef": null,
  "generatedBindingRefs": {
    "knowledgeState": "not-applicable",
    "values": []
  }
}
```

#### Expected result

```json
{
  "status": "unspecified",
  "reason": "The raised condition preserves the car domain code and data. The rule returns no datum. Product invocation awaits its 2.0 adapter."
}
```

The request uses documentation notation. The diagnostic catalog fixes condition codes. Product execution awaits its 2.0 adapter.

<a id="lispex.rule.v2.conditions.guard-grammar"></a>

### Write a complete lexical guard

A guard uses the [guard grammar](/v2.0/en/docs/language/conditions#lispex.grammar.v2.conditions.guard). A body follows the ordinary definition and expression rules.

The condition name is bound only in the clauses. Body definitions are visible only inside the body. Clauses use the surrounding lexical scope.

| Part | Required behavior |
| --- | --- |
| Protected body | Evaluate in source order with the guard active. Pass a normal result through unchanged. |
| Test | Evaluate once. Require exactly one value. Only `#f` is false. |
| Test and body | Evaluate the selected expressions in source order. Return the final result packet. |
| Test alone | Return the true test value. |
| Test and recipient | After a true test, evaluate the recipient once. Require exactly one procedure value. Call it with the test value. |
| Default clause | Use `else` once at most. Place it last. Its expression sequence must be nonempty. |
| Empty clause list | Propagate the original raised occurrence outward. |
| Normal or selected result | Preserve zero, one, or many internal values for the enclosing context. |

A clause beginning with `else` is the default clause. In every other clause, `=>` in the second position marks a recipient. These markers do not depend on bindings.

Clause tests, recipients, and bodies run with the handling guard inactive. A new failure reaches an outer guard. An unmatched condition preserves its original occurrence and failure site. A terminal failure ends guest evaluation.

An arrow call uses the ordinary procedure checks. A test or recipient with a wrong value count raises the ordinary value count condition. Later clauses do not run after a match or a failure.

Preparation rejects malformed guards in source order. Each rejection has phase `normalize` and code `syntax.form`. Its fields are fixed below.

| Malformed part | `form` | `reason` |
| --- | --- | --- |
| Missing or nonidentifier condition name | `guard` | `guard-variable` |
| Empty body or definition after an expression | `guard` | `guard-body` |
| Empty clause or improper clause list | `guard` | `clause-shape` |
| Default clause before another clause | `guard` | `else-position` |
| Default clause without an expression | `guard` | `else-body` |
| Arrow clause without exactly one recipient expression | `guard` | `arrow-shape` |

The [adopted propagation rule](/v2.0/en/docs/language/conditions#lispex.rule.v2.conditions.guard-propagation) fixes clause order and outward recovery. Body and handler tail positions follow the [tail-position rule](/v2.0/en/docs/language/evaluation#lispex.rule.v2.evaluation.tail-calls). [Procedure rules](/v2.0/en/docs/language/procedures) govern internal values and calls.

**Why**

Familiar conditional clauses express recovery without resumable control. Explicit evaluation order gives every product the same first failure. An inactive handling guard prevents recovery from catching itself. Internal value packets remain usable inside ordinary procedure composition.

Active protection and handler execution have different control lifetimes.

<a id="lispex.claim.v2.conditions.guard-grammar"></a>

Claim: `lispex.claim.v2.conditions.guard-grammar` · interaction · coverage partial · verification not-run

- language: `lispex`
- languageVersion: `2.0`

```json
{
  "predicate": {
    "kind": "guard-form",
    "clauses": [
      "test-body",
      "test-only",
      "test-recipient",
      "else-body"
    ],
    "body": "ordinary-body",
    "clauseOrder": "source-order"
  },
  "result": {
    "kind": "lexical-abortive-recovery",
    "conditionScope": "clauses-only",
    "testValueCount": 1,
    "recipientValueCount": 1,
    "falseValue": false,
    "testEvaluationCount": 1,
    "emptyClauses": "propagate-original-occurrence",
    "elsePosition": "last",
    "handlingGuardActive": false,
    "selectedResult": "complete-internal-value-packet",
    "malformedForm": {
      "phase": "normalize",
      "code": "syntax.form"
    }
  },
  "pendingCases": [
    "Run every clause form and malformed form on native, npm, and wasm products. Cover tail positions and each finite resource boundary."
  ]
}
```

<a id="lispex.example.v2.conditions.guard-clause-forms"></a>

### Select each clause form

Mode: illustrative. Stage: semantic-request. Verification: not-run.

- language: `lispex`
- languageVersion: `2.0`

File: `source.scm`

```lispex
(module main
  (import)
  (export rule)
  (entry rule)
  (define rule
    (lambda (input)
      (guard (condition
               ((= input 0) 3 7)
               ((if (= input 1) 11 #f))
               ((if (= input 2) 13 #f) => (lambda (value) (+ value 1)))
               (else 17))
        (car '()))))
)
```

File: `request.json`

```lispex
{
  "notation": "documentation-request",
  "source": "source.scm",
  "semantics": {
    "language": "Lispex 2.0",
    "standardLibrary": "one fixed library identity",
    "unicode": "one fixed Unicode semantics version",
    "resourceModel": "one fixed finite resource model"
  },
  "limits": {
    "prepare": "finite values sufficient to prepare each valid source",
    "evaluate": "finite values sufficient for each stated calculation and its result encoding"
  },
  "requests": [
    {
      "input": {
        "kind": "integer",
        "value": "0"
      }
    },
    {
      "input": {
        "kind": "integer",
        "value": "1"
      }
    },
    {
      "input": {
        "kind": "integer",
        "value": "2"
      }
    },
    {
      "input": {
        "kind": "integer",
        "value": "3"
      }
    }
  ],
  "rootModule": "main",
  "moduleSources": [
    {
      "name": "main",
      "source": "source.scm"
    }
  ]
}
```

Fixture inputs and environment:

```json
{
  "entry": "source.scm",
  "argv": [],
  "stdin": "",
  "cwd": ".",
  "environment": [],
  "wrapper": null,
  "packageRef": null,
  "lockRef": null,
  "generatedBindingRefs": {
    "knowledgeState": "not-applicable",
    "values": []
  }
}
```

#### Expected result

```json
{
  "status": "unspecified",
  "reason": "The four requests return 7, 11, 14, and 17. A test-only clause returns its test value. The arrow recipient receives 13. Product invocation awaits its 2.0 adapter."
}
```

The fixture states the language expectation. Its request uses documentation notation. Product execution remains not-run.

<a id="lispex.example.v2.conditions.guard-scope-and-values"></a>

### Preserve lexical scope and internal values

Mode: illustrative. Stage: semantic-request. Verification: not-run.

- language: `lispex`
- languageVersion: `2.0`

File: `source.scm`

```lispex
(module main
  (import)
  (export rule)
  (entry rule)
  (define rule
    (lambda (input)
      (let ((condition 7))
        (call-with-values
          (lambda ()
            (guard (condition
                     ((= input 1) (values 2 3))
                     (else (values)))
              (define normal (lambda () (values condition 5)))
              (if (= input 0) (normal) (car '()))))
          (lambda results results)))))
)
```

File: `request.json`

```lispex
{
  "notation": "documentation-request",
  "source": "source.scm",
  "semantics": {
    "language": "Lispex 2.0",
    "standardLibrary": "one fixed library identity",
    "unicode": "one fixed Unicode semantics version",
    "resourceModel": "one fixed finite resource model"
  },
  "limits": {
    "prepare": "finite values sufficient to prepare each valid source",
    "evaluate": "finite values sufficient for each stated calculation and its result encoding"
  },
  "requests": [
    {
      "input": {
        "kind": "integer",
        "value": "0"
      }
    },
    {
      "input": {
        "kind": "integer",
        "value": "1"
      }
    },
    {
      "input": {
        "kind": "integer",
        "value": "2"
      }
    }
  ],
  "rootModule": "main",
  "moduleSources": [
    {
      "name": "main",
      "source": "source.scm"
    }
  ]
}
```

Fixture inputs and environment:

```json
{
  "entry": "source.scm",
  "argv": [],
  "stdin": "",
  "cwd": ".",
  "environment": [],
  "wrapper": null,
  "packageRef": null,
  "lockRef": null,
  "generatedBindingRefs": {
    "knowledgeState": "not-applicable",
    "values": []
  }
}
```

#### Expected result

```json
{
  "status": "unspecified",
  "reason": "The consumer returns the lists of 7 and 5, of 2 and 3, and the empty list. The protected body sees the outer condition binding. Product invocation awaits its 2.0 adapter."
}
```

The fixture states the language expectation. Its request uses documentation notation. Product execution remains not-run.

<a id="lispex.example.v2.conditions.guard-empty-clauses"></a>

### Propagate through an empty clause list

Mode: illustrative. Stage: semantic-request. Verification: not-run.

- language: `lispex`
- languageVersion: `2.0`

File: `source.scm`

```lispex
(module main
  (import)
  (export rule)
  (entry rule)
  (define rule
    (lambda (input)
      (guard (outer (else 9))
        (guard (inner)
          (car input)))))
)
```

File: `request.json`

```lispex
{
  "notation": "documentation-request",
  "source": "source.scm",
  "semantics": {
    "language": "Lispex 2.0",
    "standardLibrary": "one fixed library identity",
    "unicode": "one fixed Unicode semantics version",
    "resourceModel": "one fixed finite resource model"
  },
  "limits": {
    "prepare": "finite values sufficient to prepare each valid source",
    "evaluate": "finite values sufficient for each stated calculation and its result encoding"
  },
  "requests": [
    {
      "input": {
        "kind": "empty-list"
      }
    }
  ],
  "rootModule": "main",
  "moduleSources": [
    {
      "name": "main",
      "source": "source.scm"
    }
  ]
}
```

Fixture inputs and environment:

```json
{
  "entry": "source.scm",
  "argv": [],
  "stdin": "",
  "cwd": ".",
  "environment": [],
  "wrapper": null,
  "packageRef": null,
  "lockRef": null,
  "generatedBindingRefs": {
    "knowledgeState": "not-applicable",
    "values": []
  }
}
```

#### Expected result

```json
{
  "status": "unspecified",
  "reason": "The empty inner clause list passes the original failure outward. The outer guard returns 9. Product invocation awaits its 2.0 adapter."
}
```

The fixture states the language expectation. Its request uses documentation notation. Product execution remains not-run.

<a id="lispex.example.v2.conditions.guard-inactive-handling"></a>

### Keep tests and recovery outside their guard

Mode: illustrative. Stage: semantic-request. Verification: not-run.

- language: `lispex`
- languageVersion: `2.0`

File: `source.scm`

```lispex
(module main
  (import)
  (export rule)
  (entry rule)
  (define rule
    (lambda (input)
      (guard (outer (else 19))
        (guard (inner
                 ((if (= input 0) (car '()) #f) 11)
                 ((= input 1) => (car '()))
                 (else (car '())))
          (car '())))))
)
```

File: `request.json`

```lispex
{
  "notation": "documentation-request",
  "source": "source.scm",
  "semantics": {
    "language": "Lispex 2.0",
    "standardLibrary": "one fixed library identity",
    "unicode": "one fixed Unicode semantics version",
    "resourceModel": "one fixed finite resource model"
  },
  "limits": {
    "prepare": "finite values sufficient to prepare each valid source",
    "evaluate": "finite values sufficient for each stated calculation and its result encoding"
  },
  "requests": [
    {
      "input": {
        "kind": "integer",
        "value": "0"
      }
    },
    {
      "input": {
        "kind": "integer",
        "value": "1"
      }
    },
    {
      "input": {
        "kind": "integer",
        "value": "2"
      }
    }
  ],
  "rootModule": "main",
  "moduleSources": [
    {
      "name": "main",
      "source": "source.scm"
    }
  ]
}
```

Fixture inputs and environment:

```json
{
  "entry": "source.scm",
  "argv": [],
  "stdin": "",
  "cwd": ".",
  "environment": [],
  "wrapper": null,
  "packageRef": null,
  "lockRef": null,
  "generatedBindingRefs": {
    "knowledgeState": "not-applicable",
    "values": []
  }
}
```

#### Expected result

```json
{
  "status": "unspecified",
  "reason": "A failing test, recipient expression, or recovery body reaches the outer guard. Each request returns 19. Product invocation awaits its 2.0 adapter."
}
```

The fixture states the language expectation. Its request uses documentation notation. Product execution remains not-run.

<a id="lispex.example.v2.conditions.guard-single-test-value"></a>

### Require one test and recipient value

Mode: illustrative. Stage: semantic-request. Verification: not-run.

- language: `lispex`
- languageVersion: `2.0`

File: `source.scm`

```lispex
(module main
  (import)
  (export rule)
  (entry rule)
  (define rule
    (lambda (input)
      (guard (outer (else 23))
        (guard (inner
                 ((if (= input 0) (values) #f) 1)
                 ((if (= input 1) (values 1 2) #f) 2)
                 ((= input 2) => (values))
                 ((= input 3) => (lambda () 3))
                 ((= input 4) => 0)
                 (else 29))
          (car '())))))
)
```

File: `request.json`

```lispex
{
  "notation": "documentation-request",
  "source": "source.scm",
  "semantics": {
    "language": "Lispex 2.0",
    "standardLibrary": "one fixed library identity",
    "unicode": "one fixed Unicode semantics version",
    "resourceModel": "one fixed finite resource model"
  },
  "limits": {
    "prepare": "finite values sufficient to prepare each valid source",
    "evaluate": "finite values sufficient for each stated calculation and its result encoding"
  },
  "requests": [
    {
      "input": {
        "kind": "integer",
        "value": "0"
      }
    },
    {
      "input": {
        "kind": "integer",
        "value": "1"
      }
    },
    {
      "input": {
        "kind": "integer",
        "value": "2"
      }
    },
    {
      "input": {
        "kind": "integer",
        "value": "3"
      }
    },
    {
      "input": {
        "kind": "integer",
        "value": "4"
      }
    }
  ],
  "rootModule": "main",
  "moduleSources": [
    {
      "name": "main",
      "source": "source.scm"
    }
  ]
}
```

Fixture inputs and environment:

```json
{
  "entry": "source.scm",
  "argv": [],
  "stdin": "",
  "cwd": ".",
  "environment": [],
  "wrapper": null,
  "packageRef": null,
  "lockRef": null,
  "generatedBindingRefs": {
    "knowledgeState": "not-applicable",
    "values": []
  }
}
```

#### Expected result

```json
{
  "status": "unspecified",
  "reason": "Invalid test counts, recipient counts, recipient arity, and recipient type reach the outer guard. Every request returns 23. Product invocation awaits its 2.0 adapter."
}
```

The fixture states the language expectation. Its request uses documentation notation. Product execution remains not-run.

<a id="lispex.example.v2.conditions.guard-invalid-forms"></a>

### Reject malformed guards before entry

Mode: illustrative. Stage: semantic-request. Verification: not-run.

- language: `lispex`
- languageVersion: `2.0`

File: `source.scm`

```lispex
(module main
  (import)
  (export rule)
  (entry rule)
  (define rule (lambda (input) (guard (condition (else 0) (#t 1)) input)))
)
```

File: `else-body.scm`

```lispex
(module main
  (import)
  (export rule)
  (entry rule)
  (define rule (lambda (input) (guard (condition (else)) input)))
)
```

File: `arrow-shape.scm`

```lispex
(module main
  (import)
  (export rule)
  (entry rule)
  (define rule (lambda (input) (guard (condition (#t =>)) input)))
)
```

File: `guard-variable.scm`

```lispex
(module main
  (import)
  (export rule)
  (entry rule)
  (define rule (lambda (input) (guard (0 (else 1)) input)))
)
```

File: `guard-body.scm`

```lispex
(module main
  (import)
  (export rule)
  (entry rule)
  (define rule (lambda (input) (guard (condition (else 1)))))
)
```

File: `clause-shape.scm`

```lispex
(module main
  (import)
  (export rule)
  (entry rule)
  (define rule (lambda (input) (guard (condition ()) input)))
)
```

File: `request.json`

```lispex
{
  "notation": "documentation-request",
  "source": "source.scm",
  "semantics": {
    "language": "Lispex 2.0",
    "standardLibrary": "one fixed library identity",
    "unicode": "one fixed Unicode semantics version",
    "resourceModel": "one fixed finite resource model"
  },
  "limits": {
    "prepare": "finite values sufficient to prepare each valid source",
    "evaluate": "finite values sufficient for each stated calculation and its result encoding"
  },
  "requests": [
    {
      "source": "source.scm",
      "input": {
        "kind": "integer",
        "value": "0"
      },
      "rootModule": "main",
      "moduleSources": [
        {
          "name": "main",
          "source": "source.scm"
        }
      ]
    },
    {
      "source": "else-body.scm",
      "input": {
        "kind": "integer",
        "value": "0"
      },
      "rootModule": "main",
      "moduleSources": [
        {
          "name": "main",
          "source": "else-body.scm"
        }
      ]
    },
    {
      "source": "arrow-shape.scm",
      "input": {
        "kind": "integer",
        "value": "0"
      },
      "rootModule": "main",
      "moduleSources": [
        {
          "name": "main",
          "source": "arrow-shape.scm"
        }
      ]
    },
    {
      "source": "guard-variable.scm",
      "input": {
        "kind": "integer",
        "value": "0"
      },
      "rootModule": "main",
      "moduleSources": [
        {
          "name": "main",
          "source": "guard-variable.scm"
        }
      ]
    },
    {
      "source": "guard-body.scm",
      "input": {
        "kind": "integer",
        "value": "0"
      },
      "rootModule": "main",
      "moduleSources": [
        {
          "name": "main",
          "source": "guard-body.scm"
        }
      ]
    },
    {
      "source": "clause-shape.scm",
      "input": {
        "kind": "integer",
        "value": "0"
      },
      "rootModule": "main",
      "moduleSources": [
        {
          "name": "main",
          "source": "clause-shape.scm"
        }
      ]
    }
  ],
  "rootModule": "main",
  "moduleSources": [
    {
      "name": "main",
      "source": "source.scm"
    }
  ]
}
```

Fixture inputs and environment:

```json
{
  "entry": "source.scm",
  "argv": [],
  "stdin": "",
  "cwd": ".",
  "environment": [],
  "wrapper": null,
  "packageRef": null,
  "lockRef": null,
  "generatedBindingRefs": {
    "knowledgeState": "not-applicable",
    "values": []
  }
}
```

#### Expected result

```json
{
  "status": "unspecified",
  "reason": "Each malformed guard fails normalization before entry. Its diagnostic identifies the first malformed guard part. Product invocation awaits its 2.0 adapter."
}
```

The fixture states the language expectation. Its request uses documentation notation. Product execution remains not-run.

<a id="lispex.rule.v2.conditions.guard-propagation"></a>

### Evaluate recovery outside the handling guard

Guard clauses are tested in source order. The first matching clause supplies the replacement result. An unmatched condition propagates outward. The handling guard is inactive while clause tests, recipients, and bodies run. The [guard event schedule](/v2.0/en/docs/language/resources#lispex.rule.v2.resources.event-catalog) fixes failure unwinding. Selected clause tail positions follow the [tail-position rule](/v2.0/en/docs/language/evaluation#lispex.rule.v2.evaluation.tail-calls).

**Why**

A failing recovery clause must not repeatedly catch its own failure. Ordered clauses and outward propagation give nested recovery one deterministic path.

Guard clauses follow a fixed order and propagate unmatched conditions outward.

Discarding failed calls must preserve the enclosing call's pending return.

<a id="lispex.claim.v2.conditions.guard-propagation"></a>

Claim: `lispex.claim.v2.conditions.guard-propagation` · interaction · coverage partial · verification not-run

- language: `lispex`
- languageVersion: `2.0`

```json
{
  "predicate": {
    "kind": "guard-clause-evaluation",
    "order": "source-order"
  },
  "result": {
    "kind": "outward-recovery",
    "selected": "first-matching-clause",
    "unmatched": "propagate-original-condition",
    "handlingGuardActive": false
  },
  "pendingCases": [
    "Test failures in clause predicates and bodies, unmatched nested guards, tail calls, and resource stops under the adopted clause propagation order."
  ]
}
```

<a id="lispex.example.v2.conditions.guard-clause-order"></a>

### Choose the first matching clause

Mode: illustrative. Stage: semantic-request. Verification: not-run.

- language: `lispex`
- languageVersion: `2.0`

File: `source.scm`

```lispex
(module main
  (import)
  (export rule)
  (entry rule)
  (define rule
    (lambda (input)
      (guard (condition
               (#t 7)
               (else (car '())))
        (car input))))
)
```

File: `request.json`

```lispex
{
  "notation": "documentation-request",
  "source": "source.scm",
  "semantics": {
    "language": "Lispex 2.0",
    "standardLibrary": "one fixed library identity",
    "unicode": "one fixed Unicode semantics version",
    "resourceModel": "one fixed finite resource model"
  },
  "limits": {
    "prepare": "finite values sufficient to prepare this source",
    "evaluate": "finite values sufficient for the stated finite calculation"
  },
  "requests": [
    {
      "input": {
        "kind": "empty-list"
      }
    }
  ],
  "rootModule": "main",
  "moduleSources": [
    {
      "name": "main",
      "source": "source.scm"
    }
  ]
}
```

Fixture inputs and environment:

```json
{
  "entry": "source.scm",
  "argv": [],
  "stdin": "",
  "cwd": ".",
  "environment": [],
  "wrapper": null,
  "packageRef": null,
  "lockRef": null,
  "generatedBindingRefs": {
    "knowledgeState": "not-applicable",
    "values": []
  }
}
```

#### Expected result

```json
{
  "status": "unspecified",
  "reason": "The first clause matches and returns 7. The later failing clause is not evaluated. Product invocation awaits its 2.0 adapter."
}
```

The request uses documentation notation. The diagnostic catalog fixes condition codes. Product execution awaits its 2.0 adapter.

<a id="lispex.example.v2.conditions.guard-unmatched"></a>

### Pass an unmatched condition outward

Mode: illustrative. Stage: semantic-request. Verification: not-run.

- language: `lispex`
- languageVersion: `2.0`

File: `source.scm`

```lispex
(module main
  (import)
  (export rule)
  (entry rule)
  (define rule
    (lambda (input)
      (guard (outer (else 7))
        (guard (inner (#f 9))
          (car input)))))
)
```

File: `request.json`

```lispex
{
  "notation": "documentation-request",
  "source": "source.scm",
  "semantics": {
    "language": "Lispex 2.0",
    "standardLibrary": "one fixed library identity",
    "unicode": "one fixed Unicode semantics version",
    "resourceModel": "one fixed finite resource model"
  },
  "limits": {
    "prepare": "finite values sufficient to prepare this source",
    "evaluate": "finite values sufficient for the stated finite calculation"
  },
  "requests": [
    {
      "input": {
        "kind": "empty-list"
      }
    }
  ],
  "rootModule": "main",
  "moduleSources": [
    {
      "name": "main",
      "source": "source.scm"
    }
  ]
}
```

Fixture inputs and environment:

```json
{
  "entry": "source.scm",
  "argv": [],
  "stdin": "",
  "cwd": ".",
  "environment": [],
  "wrapper": null,
  "packageRef": null,
  "lockRef": null,
  "generatedBindingRefs": {
    "knowledgeState": "not-applicable",
    "values": []
  }
}
```

#### Expected result

```json
{
  "status": "unspecified",
  "reason": "The inner guard has no matching clause. The outer guard receives the original condition and returns 7. Product invocation awaits its 2.0 adapter."
}
```

The request uses documentation notation. The diagnostic catalog fixes condition codes. Product execution awaits its 2.0 adapter.

<a id="lispex.example.v2.conditions.guard-recovery-failure"></a>

### Handle a recovery failure in the outer guard

Mode: illustrative. Stage: semantic-request. Verification: not-run.

- language: `lispex`
- languageVersion: `2.0`

File: `source.scm`

```lispex
(module main
  (import)
  (export rule)
  (entry rule)
  (define rule
    (lambda (input)
      (guard (outer (else 8))
        (guard (inner (else (/ 1 0)))
          (car input)))))
)
```

File: `request.json`

```lispex
{
  "notation": "documentation-request",
  "source": "source.scm",
  "semantics": {
    "language": "Lispex 2.0",
    "standardLibrary": "one fixed library identity",
    "unicode": "one fixed Unicode semantics version",
    "resourceModel": "one fixed finite resource model"
  },
  "limits": {
    "prepare": "finite values sufficient to prepare this source",
    "evaluate": "finite values sufficient for the stated finite calculation"
  },
  "requests": [
    {
      "input": {
        "kind": "empty-list"
      }
    }
  ],
  "rootModule": "main",
  "moduleSources": [
    {
      "name": "main",
      "source": "source.scm"
    }
  ]
}
```

Fixture inputs and environment:

```json
{
  "entry": "source.scm",
  "argv": [],
  "stdin": "",
  "cwd": ".",
  "environment": [],
  "wrapper": null,
  "packageRef": null,
  "lockRef": null,
  "generatedBindingRefs": {
    "knowledgeState": "not-applicable",
    "values": []
  }
}
```

#### Expected result

```json
{
  "status": "unspecified",
  "reason": "Division fails in the inner recovery clause. The outer guard handles that new condition and returns 8. Product invocation awaits its 2.0 adapter."
}
```

The request uses documentation notation. The diagnostic catalog fixes condition codes. Product execution awaits its 2.0 adapter.

<a id="lispex.section.v2.conditions.terminal-failures"></a>

## Terminal failures

A terminal failure returns control to the calling application. Guest guards cannot intercept preparation, admission, resource, operational, or internal failures.

Resource exhaustion preserves the first resource cause. The evaluator runs no guest recovery or cleanup after that stop. A host interruption and an engine defect stay distinct from a deterministic language failure.

<a id="lispex.rule.v2.conditions.terminal-boundary"></a>

### Keep terminal failures outside guards

Preparation, admission, resource, operational, and internal failures end the request outside guest recovery. A resource stop preserves its first cause.

**Why**

Recovery code must not spend resources after exhaustion or turn a rejected request into an admitted execution.

<a id="lispex.claim.v2.conditions.terminal-boundary"></a>

Claim: `lispex.claim.v2.conditions.terminal-boundary` · interaction · coverage partial · verification not-run

- language: `lispex`
- languageVersion: `2.0`

```json
{
  "predicate": {
    "kind": "terminal-failure",
    "categories": [
      "prepare",
      "admission",
      "resource",
      "operational",
      "internal"
    ]
  },
  "result": {
    "kind": "request-termination",
    "caughtByGuest": false,
    "guestCleanup": false,
    "replacesFirstResourceCause": false
  },
  "pendingCases": [
    "Exercise each terminal category in nested guards with resource limits immediately below, at, and above each relevant event.",
    "Inject host interruptions and engine defects through product test support and preserve their distinct reporting classes."
  ]
}
```

<a id="lispex.example.v2.conditions.guard-resource-stop"></a>

### End an unending guarded calculation

Mode: illustrative. Stage: semantic-request. Verification: not-run.

- language: `lispex`
- languageVersion: `2.0`

File: `source.scm`

```lispex
(module main
  (import)
  (export rule)
  (entry rule)
  (define rule
    (lambda (input)
      (guard (condition
               (else 99))
        (let loop ()
          (loop)))))
)
```

File: `request.json`

```lispex
{
  "notation": "documentation-request",
  "source": "source.scm",
  "semantics": {
    "language": "Lispex 2.0",
    "standardLibrary": "one fixed library identity",
    "unicode": "one fixed Unicode semantics version",
    "resourceModel": "one fixed finite resource model"
  },
  "limits": {
    "prepare": "finite values sufficient to prepare this source",
    "evaluate": "finite work limit with all other limits sufficient through the first work stop"
  },
  "requests": [
    {
      "input": {
        "kind": "integer",
        "value": "0"
      }
    }
  ],
  "rootModule": "main",
  "moduleSources": [
    {
      "name": "main",
      "source": "source.scm"
    }
  ]
}
```

Fixture inputs and environment:

```json
{
  "entry": "source.scm",
  "argv": [],
  "stdin": "",
  "cwd": ".",
  "environment": [],
  "wrapper": null,
  "packageRef": null,
  "lockRef": null,
  "generatedBindingRefs": {
    "knowledgeState": "not-applicable",
    "values": []
  }
}
```

#### Expected result

```json
{
  "status": "unspecified",
  "reason": "Finite work is exhausted. The resource stop remains terminal and the guard never returns 99. Product invocation awaits its 2.0 adapter."
}
```

The request uses documentation notation. The [failure mapping](/v2.0/en/docs/diagnostics#lispex.rule.v2.cli-and-diagnostics.diagnostics.source-prepare-mapping) defines its diagnostic identity selector. The failed reservation determines the typed fields. Product execution awaits its 2.0 adapter.

<a id="lispex.example.v2.conditions.guard-admission"></a>

### Reject invalid host input before the guard

Mode: illustrative. Stage: semantic-request. Verification: not-run.

- language: `lispex`
- languageVersion: `2.0`

File: `source.scm`

```lispex
(module main
  (import)
  (export rule)
  (entry rule)
  (define rule
    (lambda (input)
      (guard (condition (else 99)) input)))
)
```

File: `request.json`

```lispex
{
  "notation": "documentation-request",
  "source": "source.scm",
  "semantics": {
    "language": "Lispex 2.0",
    "standardLibrary": "one fixed library identity",
    "unicode": "one fixed Unicode semantics version",
    "resourceModel": "one fixed finite resource model"
  },
  "limits": {
    "prepare": "finite values sufficient to prepare this source",
    "evaluate": "finite values sufficient for the stated finite calculation"
  },
  "requests": [
    {
      "input": {
        "fixtureValue": "host callback from hostSetup"
      }
    }
  ],
  "hostSetup": {
    "inputKind": "host-callback",
    "callbackResult": {
      "kind": "integer",
      "value": "42"
    }
  },
  "rootModule": "main",
  "moduleSources": [
    {
      "name": "main",
      "source": "source.scm"
    }
  ]
}
```

Fixture inputs and environment:

```json
{
  "entry": "source.scm",
  "argv": [],
  "stdin": "",
  "cwd": ".",
  "environment": [],
  "wrapper": null,
  "packageRef": null,
  "lockRef": null,
  "generatedBindingRefs": {
    "knowledgeState": "not-applicable",
    "values": []
  }
}
```

#### Expected result

```json
{
  "status": "unspecified",
  "reason": "A host callback is rejected at the data boundary before guest evaluation. The guard cannot recover. Product invocation awaits its 2.0 adapter."
}
```

The request uses documentation notation. The diagnostic catalog fixes condition codes. Product execution awaits its 2.0 adapter.

<a id="lispex.example.v2.conditions.guard-prepare"></a>

### Reject a removed operation before evaluation

Mode: illustrative. Stage: semantic-request. Verification: not-run.

- language: `lispex`
- languageVersion: `2.0`

File: `source.scm`

```lispex
(module main
  (import)
  (export rule)
  (entry rule)
  (define rule
    (lambda (input)
      (guard (condition (else 99))
        (call/cc (lambda (exit) (exit 1))))))
)
```

File: `request.json`

```lispex
{
  "notation": "documentation-request",
  "source": "source.scm",
  "semantics": {
    "language": "Lispex 2.0",
    "standardLibrary": "one fixed library identity",
    "unicode": "one fixed Unicode semantics version",
    "resourceModel": "one fixed finite resource model"
  },
  "limits": {
    "prepare": "finite values sufficient to prepare this source",
    "evaluate": "finite values sufficient for the stated finite calculation"
  },
  "requests": [
    {
      "input": {
        "kind": "integer",
        "value": "0"
      }
    }
  ],
  "preparationCheck": "Reject the removed call/cc operation before guest evaluation.",
  "rootModule": "main",
  "moduleSources": [
    {
      "name": "main",
      "source": "source.scm"
    }
  ]
}
```

Fixture inputs and environment:

```json
{
  "entry": "source.scm",
  "argv": [],
  "stdin": "",
  "cwd": ".",
  "environment": [],
  "wrapper": null,
  "packageRef": null,
  "lockRef": null,
  "generatedBindingRefs": {
    "knowledgeState": "not-applicable",
    "values": []
  }
}
```

#### Expected result

```json
{
  "status": "unspecified",
  "reason": "Preparation rejects call/cc. The body and recovery clause never run. Product invocation awaits its 2.0 adapter."
}
```

The request uses documentation notation. The diagnostic catalog fixes condition codes. Product execution awaits its 2.0 adapter.

<a id="lispex.rule.v2.conditions.removed-control"></a>

### Reject dynamic condition control

Programs cannot use procedural handlers, continuable raise, call/cc, or dynamic-wind. Preparation rejects these removed control operations. The diagnostic uses phase `resolve` and code `library.reference`. Its `reason` is `removed-operation`. Its `name` identifies the removed operation. The [failure mapping](/v2.0/en/docs/diagnostics#lispex.rule.v2.cli-and-diagnostics.diagnostics.source-prepare-mapping) applies the diagnostic catalog.

**Why**

Lexical guards and structured propagation provide the adopted recovery surface without resumable control objects or guest cleanup after a stop.

<a id="lispex.claim.v2.conditions.removed-control"></a>

Claim: `lispex.claim.v2.conditions.removed-control` · interaction · coverage partial · verification not-run

- language: `lispex`
- languageVersion: `2.0`

```json
{
  "predicate": {
    "kind": "removed-control-use",
    "operations": [
      "with-exception-handler",
      "raise-continuable",
      "call/cc",
      "dynamic-wind"
    ]
  },
  "result": {
    "kind": "prepare-failure",
    "guestControlEntered": false
  },
  "pendingCases": [
    "Check direct references, aliases, nested forms, imports, and artifact admission for each removed operation on all products and engines."
  ]
}
```

<a id="lispex.example.v2.conditions.procedural-handler"></a>

### Reject a procedural handler

Mode: illustrative. Stage: semantic-request. Verification: not-run.

- language: `lispex`
- languageVersion: `2.0`

File: `source.scm`

```lispex
(module main
  (import)
  (export rule)
  (entry rule)
  (define rule
    (lambda (input)
      (with-exception-handler
        (lambda (condition) 0)
        (lambda () (car input)))))
)
```

File: `request.json`

```lispex
{
  "notation": "documentation-request",
  "source": "source.scm",
  "semantics": {
    "language": "Lispex 2.0",
    "standardLibrary": "one fixed library identity",
    "unicode": "one fixed Unicode semantics version",
    "resourceModel": "one fixed finite resource model"
  },
  "limits": {
    "prepare": "finite values sufficient to prepare this source",
    "evaluate": "finite values sufficient for the stated finite calculation"
  },
  "requests": [
    {
      "input": {
        "kind": "integer",
        "value": "0"
      }
    }
  ],
  "rootModule": "main",
  "moduleSources": [
    {
      "name": "main",
      "source": "source.scm"
    }
  ]
}
```

Fixture inputs and environment:

```json
{
  "entry": "source.scm",
  "argv": [],
  "stdin": "",
  "cwd": ".",
  "environment": [],
  "wrapper": null,
  "packageRef": null,
  "lockRef": null,
  "generatedBindingRefs": {
    "knowledgeState": "not-applicable",
    "values": []
  }
}
```

#### Expected result

```json
{
  "status": "unspecified",
  "reason": "Preparation rejects the procedural handler. No handler or guest body is entered. Product invocation awaits its 2.0 adapter."
}
```

The request uses documentation notation. The diagnostic catalog fixes condition codes. Product execution awaits its 2.0 adapter.

<a id="lispex.example.v2.conditions.continuable-raise"></a>

### Reject a continuable signal

Mode: illustrative. Stage: semantic-request. Verification: not-run.

- language: `lispex`
- languageVersion: `2.0`

File: `source.scm`

```lispex
(module main
  (import)
  (export rule)
  (entry rule)
  (define rule
    (lambda (input)
      (raise-continuable input)))
)
```

File: `request.json`

```lispex
{
  "notation": "documentation-request",
  "source": "source.scm",
  "semantics": {
    "language": "Lispex 2.0",
    "standardLibrary": "one fixed library identity",
    "unicode": "one fixed Unicode semantics version",
    "resourceModel": "one fixed finite resource model"
  },
  "limits": {
    "prepare": "finite values sufficient to prepare this source",
    "evaluate": "finite values sufficient for the stated finite calculation"
  },
  "requests": [
    {
      "input": {
        "kind": "integer",
        "value": "0"
      }
    }
  ],
  "rootModule": "main",
  "moduleSources": [
    {
      "name": "main",
      "source": "source.scm"
    }
  ]
}
```

Fixture inputs and environment:

```json
{
  "entry": "source.scm",
  "argv": [],
  "stdin": "",
  "cwd": ".",
  "environment": [],
  "wrapper": null,
  "packageRef": null,
  "lockRef": null,
  "generatedBindingRefs": {
    "knowledgeState": "not-applicable",
    "values": []
  }
}
```

#### Expected result

```json
{
  "status": "unspecified",
  "reason": "Preparation rejects continuable raise. No resumable condition is created. Product invocation awaits its 2.0 adapter."
}
```

The request uses documentation notation. The diagnostic catalog fixes condition codes. Product execution awaits its 2.0 adapter.

<a id="lispex.example.v2.conditions.wind-cleanup"></a>

### Reject dynamic cleanup

Mode: illustrative. Stage: semantic-request. Verification: not-run.

- language: `lispex`
- languageVersion: `2.0`

File: `source.scm`

```lispex
(module main
  (import)
  (export rule)
  (entry rule)
  (define rule
    (lambda (input)
      (dynamic-wind
        (lambda () 1)
        (lambda () input)
        (lambda () 2))))
)
```

File: `request.json`

```lispex
{
  "notation": "documentation-request",
  "source": "source.scm",
  "semantics": {
    "language": "Lispex 2.0",
    "standardLibrary": "one fixed library identity",
    "unicode": "one fixed Unicode semantics version",
    "resourceModel": "one fixed finite resource model"
  },
  "limits": {
    "prepare": "finite values sufficient to prepare this source",
    "evaluate": "finite values sufficient for the stated finite calculation"
  },
  "requests": [
    {
      "input": {
        "kind": "integer",
        "value": "0"
      }
    }
  ],
  "rootModule": "main",
  "moduleSources": [
    {
      "name": "main",
      "source": "source.scm"
    }
  ]
}
```

Fixture inputs and environment:

```json
{
  "entry": "source.scm",
  "argv": [],
  "stdin": "",
  "cwd": ".",
  "environment": [],
  "wrapper": null,
  "packageRef": null,
  "lockRef": null,
  "generatedBindingRefs": {
    "knowledgeState": "not-applicable",
    "values": []
  }
}
```

#### Expected result

```json
{
  "status": "unspecified",
  "reason": "Preparation rejects dynamic-wind. None of the three procedures runs. Product invocation awaits its 2.0 adapter."
}
```

The request uses documentation notation. The diagnostic catalog fixes condition codes. Product execution awaits its 2.0 adapter.

<a id="lispex.section.v2.conditions.failure-order"></a>

## Failure order

The [evaluation rules](/v2.0/en/docs/language/evaluation) order the operator, arguments, and call checks. The [resource rules](/v2.0/en/docs/language/resources) order reservations at their semantic sites. A guard sees the first catchable condition reached by those events.

Later arguments do not run after an earlier argument fails. A guard may select a recovery clause. A terminal resource stop preserves its first cause.

<a id="lispex.rule.v2.conditions.first-failure"></a>

### Report the first ordered failure

A lexical guard receives the first catchable condition reached under [evaluation order](/v2.0/en/docs/language/evaluation#lispex.rule.v2.evaluation.application-order) and [resource event order](/v2.0/en/docs/language/resources#lispex.rule.v2.resources.event-order). The [event-preservation rule](/v2.0/en/docs/language/resources#lispex.rule.v2.resources.preserve-events) applies when optimizing that path.

**Why**

Pure expressions can fail in different ways. Reordering them would change which condition a guard receives and which failure the caller observes.

<a id="lispex.claim.v2.conditions.first-failure"></a>

Claim: `lispex.claim.v2.conditions.first-failure` · interaction · coverage partial · verification not-run

- language: `lispex`
- languageVersion: `2.0`

```json
{
  "predicate": {
    "kind": "competing-failures",
    "ordering": "normative-semantic-events"
  },
  "result": {
    "kind": "first-failure-preservation",
    "preserved": [
      "condition",
      "resource-axis",
      "canonical-site"
    ],
    "catchableRecovery": true
  },
  "pendingCases": [
    "Compare operator, argument, arity, domain, and resource failures at adjacent semantic events on optimized and unoptimized paths."
  ]
}
```

<a id="lispex.example.v2.conditions.first-argument-failure"></a>

### Keep the left argument failure first

Mode: illustrative. Stage: semantic-request. Verification: not-run.

- language: `lispex`
- languageVersion: `2.0`

File: `source.scm`

```lispex
(module main
  (import)
  (export rule)
  (entry rule)
  (define rule
    (lambda (input)
      (list (car '()) (/ 1 0))))
)
```

File: `request.json`

```lispex
{
  "notation": "documentation-request",
  "source": "source.scm",
  "semantics": {
    "language": "Lispex 2.0",
    "standardLibrary": "one fixed library identity",
    "unicode": "one fixed Unicode semantics version",
    "resourceModel": "one fixed finite resource model"
  },
  "limits": {
    "prepare": "finite values sufficient to prepare this source",
    "evaluate": "finite values sufficient through the first domain failure and its encoding"
  },
  "requests": [
    {
      "input": {
        "kind": "integer",
        "value": "0"
      }
    },
    {
      "input": {
        "kind": "integer",
        "value": "0"
      }
    }
  ],
  "executionContexts": [
    "unoptimized engine path",
    "optimized engine path"
  ],
  "siteNotation": {
    "left-car": "the car call in the first list argument"
  },
  "rootModule": "main",
  "moduleSources": [
    {
      "name": "main",
      "source": "source.scm"
    }
  ]
}
```

Fixture inputs and environment:

```json
{
  "entry": "source.scm",
  "argv": [],
  "stdin": "",
  "cwd": ".",
  "environment": [],
  "wrapper": null,
  "packageRef": null,
  "lockRef": null,
  "generatedBindingRefs": {
    "knowledgeState": "not-applicable",
    "values": []
  }
}
```

#### Expected result

```json
{
  "status": "unspecified",
  "reason": "Both paths report the car domain failure in the left argument. The division is never evaluated. Product invocation awaits its 2.0 adapter."
}
```

The fixture label selects the first car call.
[Canonical sites](/v2.0/en/docs/tools/meaning-graph#lispex.rule.v2.meaning-graph.canonical-sites) define its encoded location.
Products never serialize the fixture label.
Product execution remains not-run.

<a id="lispex.section.v2.conditions.related"></a>

## Related chapters

[Evaluation and bindings](/v2.0/en/docs/language/evaluation)

[Resources](/v2.0/en/docs/language/resources)

[Diagnostics](/v2.0/en/docs/diagnostics)

<a id="lispex.pending.v2.resources.model-numbers"></a>

### Pending · Resource model numbers

The 2.0 tariff coefficients, logical allocation units, bit-size accounting, detailed frame accounting, finite defaults, representation limits, and physical memory envelopes remain open. This includes preparation, calls, values, exact arithmetic, equality, text, record conversion, and canonical encoding.

Profile host budget coefficients and defaults remain separate from language preparation and evaluation budgets. Trace capacity, reservation sizes, and host memory requirements retain their separate reporting scope. Each budget retains its own identity and accounting boundary.

Implementation and attack tests must support these choices. [Resource event declarations](/v2.0/en/docs/language/resources#lispex.rule.v2.resources.event-catalog) and [native kernel membership](/v2.0/en/docs/library#lispex.pending.v2.standard-library.kernel-and-cost-model) remain separate contracts.

<a id="lispex.pending.v2.standard-library.kernel-and-cost-model"></a>

### Pending · Native kernel membership

The final native kernel list and count remain open. Implementation and product attack tests must support these choices. [Tariff coefficients, allocation units, finite defaults, and physical envelopes](/v2.0/en/docs/language/resources#lispex.pending.v2.resources.model-numbers) are tracked once with the resource numbers.

## Related

[Evaluation and bindings](/v2.0/en/docs/language/evaluation)

[Resources](/v2.0/en/docs/language/resources)

[Diagnostics](/v2.0/en/docs/diagnostics)
