Перейти к содержанию
(Lispex)2.0Спецификация · до выпуска

Поиск по документации

Поиск по английскому тексту спецификации

Введите вопрос, символ, код диагностики или команду.

Содержание

Поиск по спецификации
Лиспекс 2.0 · Обзор · Глава VI.17

Глава VI.17

First rule

Use one rule to select the first item of an input list. Change the input, inspect a failure, and repeat a request.

Непереведённый текст показан на английском языке

Scope

The examples state the Lispex 2.0 outcome. Native, npm, and WASM product plans are not run.

Every example keeps the same first-item definition. The request.json file shows the entry, input, and finite limits in documentation notation. The CLI and interchange chapters specify the concrete product forms.

Rule boundary

Declare first-item under the entry contract. Supply the list as one Datum. This example follows the single result rule.

The application displays that result. The rule needs no printing procedure.

17.1 Pass one input and receive one result

The root module declares first-item as its entry. The request supplies one list datum. For a nonempty list, first-item returns its first element as one result datum.

17.1ред. 2
lispex.rule.v2.first-rule.one-input-one-result

Why

An explicit input makes the rule reusable. Returning one datum gives the calling application one decision value to handle.

Rule program

Read source.scm as the rule source for this chapter. Its module exports first-item and declares it as the entry. The parameter items receives the input datum. The body calls car with that value.

Every fixture contains this same module. The request selects main as its root module.

Return the first item

lispex.example.v2.first-rule.success · ред. 2

source.scm
(module main
  (import)
  (export first-item)
  (entry first-item)
  (define first-item
    (lambda (items)
      (car items)))
)
Запрос и файлы
request.json
{
  "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"
          },
          {
            "kind": "integer",
            "value": "8"
          }
        ]
      }
    }
  ],
  "rootModule": "main",
  "moduleSources": [
    {
      "name": "main",
      "source": "source.scm"
    }
  ]
}
Результат по спецификации
Результат3
Подробности результата
{
  "kind": "value",
  "valueCount": 1,
  "datum": {
    "kind": "integer",
    "value": "3"
  }
}

Результат по спецификации. Запуски продукта ожидают адаптера 2.0.

Вызов продукта

Ожидаемый результат

Input list 3, 5, 8 produces the exact integer 3 as one result datum. Product invocation awaits its 2.0 adapter.

The list contains three elements, but the request supplies one datum. The product plan checks the result 3 and the single result count.

Input and result

The input list has the elements 3, 5, and 8. The complete list is the one input Datum. The result is the exact integer 3.

The expected result describes a canonical outcome. Product commands and displayed output belong to CLI and diagnostics.

Failure

Replace the input with the empty list. Keep the rule source unchanged. The call to car fails because it requires a pair.

The condition catalog identifies this failure as domain.type in phase evaluate. The diagnostic field rule defines its serialized fields. Human message text does not change the canonical outcome.

17.2 Report an empty input as a failure

Passing the empty list to first-item produces a domain failure from car. The failed request returns no result datum.

17.2ред. 2
lispex.rule.v2.first-rule.empty-input

Why

A failure keeps invalid input visible. It prevents the calling application from treating a missing list element as a decision.

Inspect the empty-list failure

lispex.example.v2.first-rule.empty-input · ред. 2

source.scm
(module main
  (import)
  (export first-item)
  (entry first-item)
  (define first-item
    (lambda (items)
      (car items)))
)
Запрос и файлы
request.json
{
  "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": []
      }
    }
  ],
  "rootModule": "main",
  "moduleSources": [
    {
      "name": "main",
      "source": "source.scm"
    }
  ]
}
Результат по спецификации
Условиеdomain.type
Подробности результата
{
  "kind": "language-failure",
  "valueCount": 0,
  "condition": {
    "phase": "evaluate",
    "code": "domain.type",
    "data": {
      "operation": "car",
      "argument": "0",
      "path": [],
      "expected": "pair",
      "actual": "empty-list"
    }
  }
}

Результат по спецификации. Запуски продукта ожидают адаптера 2.0.

Вызов продукта

Ожидаемый результат

The empty list produces a car domain failure and no result datum. Product invocation awaits its 2.0 adapter.

The entry still receives one datum. That datum is the empty list. The product plan checks the car domain failure and absence of a result.

Repair

After the failure, submit the list with elements 7 and 9 as a new request. The result is 7. Submit the original list again and the result is 3.

The product plan uses the same prepared rule for all three requests. Each evaluation uses its own input.

17.3 Use the input of each new request

Each request evaluates first-item with its own input datum. A failed request leaves later requests free to evaluate their supplied inputs.

17.3ред. 2
lispex.rule.v2.first-rule.independent-input

Why

A caller can correct or replace an input without repairing hidden session state. The result then follows from the new request.

Use a new input after a failure

lispex.example.v2.first-rule.next-input · ред. 2

source.scm
(module main
  (import)
  (export first-item)
  (entry first-item)
  (define first-item
    (lambda (items)
      (car items)))
)
Запрос и файлы
request.json
{
  "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": []
      }
    },
    {
      "input": {
        "kind": "list",
        "items": [
          {
            "kind": "integer",
            "value": "7"
          },
          {
            "kind": "integer",
            "value": "9"
          }
        ]
      }
    },
    {
      "input": {
        "kind": "list",
        "items": [
          {
            "kind": "integer",
            "value": "3"
          },
          {
            "kind": "integer",
            "value": "5"
          },
          {
            "kind": "integer",
            "value": "8"
          }
        ]
      }
    }
  ],
  "execution": "Evaluate three separate requests using the same prepared rule.",
  "rootModule": "main",
  "moduleSources": [
    {
      "name": "main",
      "source": "source.scm"
    }
  ]
}
Результат по спецификации
Условиеdomain.type
Подробности результата
{
  "kind": "language-failure",
  "valueCount": 0,
  "condition": {
    "phase": "evaluate",
    "code": "domain.type",
    "data": {
      "operation": "car",
      "argument": "0",
      "path": [],
      "expected": "pair",
      "actual": "empty-list"
    }
  }
}
Результат7
Подробности результата
{
  "kind": "value",
  "valueCount": 1,
  "datum": {
    "kind": "integer",
    "value": "7"
  }
}
Результат3
Подробности результата
{
  "kind": "value",
  "valueCount": 1,
  "datum": {
    "kind": "integer",
    "value": "3"
  }
}

Результат по спецификации. Запуски продукта ожидают адаптера 2.0.

Вызов продукта

Ожидаемый результат

The empty input fails. The next input list 7, 9 returns 7. Restoring input list 3, 5, 8 returns 3. Product invocation awaits its 2.0 adapter.

Keep the source unchanged. Submit each input as a new request. The product plan checks that a failure does not replace or contaminate later inputs.

Replay

Use replay to repeat first-item. Keep the complete semantic request and compare canonical outcomes.

Retain source and artifact identities and execution and signature evidence using the definitions there.

The same replay procedure applies to the empty-input failure.

17.4 Repeat the complete request

Apply the exact-replay rule to first-item. Repeating the success request returns the same Datum. Repeating the empty-input request produces the same domain failure.

17.4ред. 2
lispex.rule.v2.first-rule.exact-replay

Why

A recorded decision can be checked only when the program, input, semantics, and limits stay fixed. Separating the outcome from execution evidence makes that comparison precise.

Replay a successful request

lispex.example.v2.first-rule.replay-success · ред. 2

source.scm
(module main
  (import)
  (export first-item)
  (entry first-item)
  (define first-item
    (lambda (items)
      (car items)))
)
Запрос и файлы
request.json
{
  "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"
          },
          {
            "kind": "integer",
            "value": "8"
          }
        ]
      }
    },
    {
      "input": {
        "kind": "list",
        "items": [
          {
            "kind": "integer",
            "value": "3"
          },
          {
            "kind": "integer",
            "value": "5"
          },
          {
            "kind": "integer",
            "value": "8"
          }
        ]
      }
    }
  ],
  "comparison": "Repeat the complete semantic request with the same canonical program, input, semantics, resource model, and limits.",
  "rootModule": "main",
  "moduleSources": [
    {
      "name": "main",
      "source": "source.scm"
    }
  ]
}
Результат по спецификации
Результат3
Подробности результата
{
  "kind": "value",
  "valueCount": 1,
  "datum": {
    "kind": "integer",
    "value": "3"
  }
}
Результат3
Подробности результата
{
  "kind": "value",
  "valueCount": 1,
  "datum": {
    "kind": "integer",
    "value": "3"
  }
}

Результат по спецификации. Запуски продукта ожидают адаптера 2.0.

Подробности семантики
{
  "comparison": {
    "canonicalOutcomeEqual": true
  }
}
Вызов продукта

Ожидаемый результат

Both executions return the exact integer 3. Their canonical outcomes are equal. Product invocation awaits its 2.0 adapter.

Retain the complete request and the first outcome. The product plan repeats that request and compares the canonical outcomes.

Replay a failing request

lispex.example.v2.first-rule.replay-failure · ред. 2

source.scm
(module main
  (import)
  (export first-item)
  (entry first-item)
  (define first-item
    (lambda (items)
      (car items)))
)
Запрос и файлы
request.json
{
  "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": []
      }
    },
    {
      "input": {
        "kind": "list",
        "items": []
      }
    }
  ],
  "comparison": "Repeat the same failing semantic request and compare its canonical outcomes.",
  "rootModule": "main",
  "moduleSources": [
    {
      "name": "main",
      "source": "source.scm"
    }
  ]
}
Результат по спецификации
Условиеdomain.type
Подробности результата
{
  "kind": "language-failure",
  "valueCount": 0,
  "condition": {
    "phase": "evaluate",
    "code": "domain.type",
    "data": {
      "operation": "car",
      "argument": "0",
      "path": [],
      "expected": "pair",
      "actual": "empty-list"
    }
  }
}
Условиеdomain.type
Подробности результата
{
  "kind": "language-failure",
  "valueCount": 0,
  "condition": {
    "phase": "evaluate",
    "code": "domain.type",
    "data": {
      "operation": "car",
      "argument": "0",
      "path": [],
      "expected": "pair",
      "actual": "empty-list"
    }
  }
}

Результат по спецификации. Запуски продукта ожидают адаптера 2.0.

Подробности семантики
{
  "comparison": {
    "canonicalOutcomeEqual": true
  }
}
Вызов продукта

Ожидаемый результат

Both executions produce the same car domain failure. Neither returns a datum, and their canonical outcomes are equal. Product invocation awaits its 2.0 adapter.

Retain the empty-input request as well. The product plan checks that the same failure repeats. The diagnostic catalog determines its concrete code and representation.

Related chapters

Sandbox contract

Procedures

Standard library

Identity, receipt, replay

CLI and diagnostics