value From Datum(package: Lispex Package, datum: Lispex Datum View, limits: Lispex Host Limits) - > Result<Lispex Value, Lispex Value Error>- Module
- std.
lispex - Receiver
- Not applicable
- Minimum arity
- 3
- Maximum arity
- 3
Declaration and parameters
LinkAvailability
Included by default: no
Import std.lispex from an application package with a verified lock. Packages with [lispex] require --locked. Application profile topaz/ uses evaluator profile lispex/. Application profile topaz/ uses evaluator profile lispex/.
The generated-module resolver gate starts at language mode 5.18. Compatibility of this API with earlier released editions remains Pending. Target deployment conditions are native (native-only), web (web-isolated-workers), web- (web-isolated-workers). Runtime payload follows checker-reached rules. An empty reached-rule set includes no runtime payload. Application quotas are required. Lock-only packages do not receive these application modules.
Source evidence
- compiler/crates/topaz_lispex_product/src/lib.rs at
b48527d0a174· 202 - compiler/crates/topaz_lispex_product/src/lib.rs at
b48527d0a174· 202 - compiler/crates/topaz_resolve/src/lib.rs at
b48527d0a174· 801 - compiler/crates/topaz_cli/src/package/target.rs at
b48527d0a174· 71 - compiler/crates/topaz_value/src/lispex_application.rs at
b48527d0a174· 11 - compiler/crates/topaz_lispex_product/src/lib.rs at
b48527d0a174· 739 - compiler/crates/topaz_lispex_product/src/full_product.rs at
b48527d0a174· 44 - compiler/crates/topaz_lispex_product/src/lib.rs at
b48527d0a174· 634 - compiler/crates/topaz_lispex_product/src/lib.rs at
b48527d0a174· 496 - compiler/crates/topaz_lispex_product/src/full_product.rs at
b48527d0a174· 356
Receiver
Parameter constraints
LispexValue is an immutable validated Datum handle. Its codec identity travels with the value. Guest inputs and successful results use this same representation. Equality follows the selected canonical value contract.
valueFromCanonical accepts an admitted package, immutable bytes and complete finite host limits. Decode exactly one complete canonical Datum under the package codec. Reject malformed bytes, trailing values, unsupported versions and noncanonical representations as InvalidCanonicalValue.
valueFromDatum accepts a LispexDatumView and creates a detached immutable snapshot. Boolean accepts a bool. Number accepts exact BigInt numerator and denominator values and normalizes their rational value. A zero denominator returns InvalidDatum. No inexact floating value is accepted.
Character accepts exactly one Unicode scalar. Empty text, several scalars and invalid scalar representations return InvalidDatum. Symbol and Text preserve their scalar sequences without normalization or case conversion. Empty symbols follow the selected Datum codec contract.
EmptyList is the empty list value. Pair holds two validated values. Vector copies its Array of validated values in order. Bytevector retains exact immutable bytes. Every child must use the same admitted codec contract. A mismatched child returns InvalidDatum before guest entry.
The exposed view has no procedure, callback or host object alternative. A procedure cannot be hidden in Pair or Vector because each child must already be a validated LispexValue. Construction does not follow host reference graphs. Mutating a source Array after conversion cannot change the sealed value.
valueView returns a detached view of the same value. Number exposes the normalized exact numerator and positive denominator. Aggregate views contain sealed child handles. Changing a returned Array changes that view and does not mutate the LispexValue.
Conversions reserve their work, allocation, traversal frames, input and result channels under LispexHostLimits. Host conversion exhaustion returns LimitExceeded with the first axis. A failure returns no prefix or partly valid value. It creates no canonical evaluation outcome or receipt.
canonicalBytes returns the immutable canonical bytes established when the handle was created. It does not decode, evaluate, discover a codec or perform fresh serialization. The handle retains that bounded representation, so reading it starts no new guest or host work account.
Host conversion work is separate from evaluation work. Evaluation still charges canonical input decoding and canonical result or failure encoding under its own limits. Prevalidated bytes cannot bypass those charges.
The same value, codec and explicit conversion limits have the same accepted canonical bytes or deterministic conversion refusal. Exact codec bytes and normalization encodings belong to the admitted versioned Lispex contract. Legacy 1.21 bytes are never relabeled as 2.0 bytes.
Related rule: Exchange exact immutable Datum valuesResult
The declared result type is Result<Lispex.
Effects
Failures
Result and effects
LinkSnapshot a host Datum view into an immutable canonical value.
Why
LinkThe values contract gives this operation one explicit input boundary and preserves the distinct result and failure cases.
Related entries
LinkExchange exact immutable Datum values
LinkExchange exact immutable Datum values
LispexValue is an immutable validated Datum handle. Its codec identity travels with the value. Guest inputs and successful results use this same representation. Equality follows the selected canonical value contract.
valueFromCanonical accepts an admitted package, immutable bytes and complete finite host limits. Decode exactly one complete canonical Datum under the package codec. Reject malformed bytes, trailing values, unsupported versions and noncanonical representations as InvalidCanonicalValue.
valueFromDatum accepts a LispexDatumView and creates a detached immutable snapshot. Boolean accepts a bool. Number accepts exact BigInt numerator and denominator values and normalizes their rational value. A zero denominator returns InvalidDatum. No inexact floating value is accepted.
Character accepts exactly one Unicode scalar. Empty text, several scalars and invalid scalar representations return InvalidDatum. Symbol and Text preserve their scalar sequences without normalization or case conversion. Empty symbols follow the selected Datum codec contract.
EmptyList is the empty list value. Pair holds two validated values. Vector copies its Array of validated values in order. Bytevector retains exact immutable bytes. Every child must use the same admitted codec contract. A mismatched child returns InvalidDatum before guest entry.
The exposed view has no procedure, callback or host object alternative. A procedure cannot be hidden in Pair or Vector because each child must already be a validated LispexValue. Construction does not follow host reference graphs. Mutating a source Array after conversion cannot change the sealed value.
valueView returns a detached view of the same value. Number exposes the normalized exact numerator and positive denominator. Aggregate views contain sealed child handles. Changing a returned Array changes that view and does not mutate the LispexValue.
Conversions reserve their work, allocation, traversal frames, input and result channels under LispexHostLimits. Host conversion exhaustion returns LimitExceeded with the first axis. A failure returns no prefix or partly valid value. It creates no canonical evaluation outcome or receipt.
canonicalBytes returns the immutable canonical bytes established when the handle was created. It does not decode, evaluate, discover a codec or perform fresh serialization. The handle retains that bounded representation, so reading it starts no new guest or host work account.
Host conversion work is separate from evaluation work. Evaluation still charges canonical input decoding and canonical result or failure encoding under its own limits. Prevalidated bytes cannot bypass those charges.
The same value, codec and explicit conversion limits have the same accepted canonical bytes or deterministic conversion refusal. Exact codec bytes and normalization encodings belong to the admitted versioned Lispex contract. Legacy 1.21 bytes are never relabeled as 2.0 bytes.
Why
Canonical bytes serve interchange. Datum views serve typed host construction and inspection. These are different intentions even when they describe the same value. Immutable snapshots keep host mutation from changing a request after it has been identified.
Source evidence
- docs/content-next/en/embedding.json at
f455ac95ab30· 1 - docs/content-next/en/profiles.json at
f455ac95ab30· 1 - docs/content-next/en/values.json at
f455ac95ab30· 1 - docs/content-next/en/resources.json at
f455ac95ab30· 1 -
topaz.stdlib.contract.lispex-valuesatworking-tree - topaz.decision.lispex-v2-value-boundary.1 at
topaz.decisi
Preserve an explicit Boolean input
Linkimport std.bytes { Bytes }import std.ioimport std.testimport std.lispex {LispexPackage,LispexBoundaryReport,LispexLimitPreset,LispexLimits,LispexSource,LispexSourceBundle,PreparedLispexRule,LispexPreparationError,LispexDatumView,LispexValue,LispexValueError,LispexEvaluation,LispexAttemptError,LispexSettlement,applicationPackage,defaultLimits,prepare,valueFromDatum,canonicalBytes,evaluate,}export function main(args: Array<string>, stdin: string) -> Result<int, string> {let packageResult: Result<LispexPackage, LispexBoundaryReport> = applicationPackage()let application: LispexPackage = test.assertOk(packageResult)let preset: LispexLimitPreset = defaultLimits()let source: LispexSource = LispexSource {name: "source.scm",bytes: "(define rule (lambda (input) input))\n".encodeUtf8(),}let bundle: LispexSourceBundle = LispexSourceBundle {entryModule: "source.scm",entryBinding: "rule",sources: [source],}let prepared: Result<PreparedLispexRule, LispexPreparationError> = prepare(application, bundle, preset.preparation)let rule: PreparedLispexRule = test.assertOk(prepared)let converted: Result<LispexValue, LispexValueError> = valueFromDatum(application, LispexDatumView.Boolean(true), preset.host)let input: LispexValue = test.assertOk(converted)let attempt: Result<LispexEvaluation, LispexAttemptError> = evaluate(rule, input, preset.evaluation)let evaluation: LispexEvaluation = test.assertOk(attempt)match (evaluation.settlement) {case Complete(output) => {let expected: Bytes = canonicalBytes(input)let actual: Bytes = canonicalBytes(output)io.writeLine("{actual.toHex() == expected.toHex()}")}case _ => io.writeLine("unexpected outcome")}return Ok(0)}
true
Expected result
Expected result
Execution completes. Exit code 0.
true
Run this source inside the verified Lispex application supplied through TOPAZ_LISPEX_APPLICATION. The example expects the Lispex 2.0 host contract.
Source evidence
- docs/content-next/en/embedding.json at
f455ac95ab30· 1 - docs/content-next/en/profiles.json at
f455ac95ab30· 1 - docs/content-next/en/values.json at
f455ac95ab30· 1 - docs/content-next/en/resources.json at
f455ac95ab30· 1 -
topaz.stdlib.contract.lispex-valuesatworking-tree - topaz.decision.lispex-v2-value-boundary.1 at
topaz.decisi
Round trip exact values and isolate host mutations
Linkimport std.bigint { BigInt }import std.bytes { Bytes }import std.ioimport std.testimport std.lispex {LispexPackage, LispexBoundaryReport, LispexLimitPreset, LispexDatumView,LispexValue, LispexValueError, applicationPackage, defaultLimits,valueFromDatum, valueFromCanonical, valueView, canonicalBytes,}function conversionFailure(error: LispexValueError) -> string {return match (error) {case InvalidCanonicalValue(report) => report.codecase InvalidDatum(report) => report.codecase LimitExceeded(report) => report.code}}export function main(args: Array<string>, stdin: string) -> Result<int, string> {let packageResult: Result<LispexPackage, LispexBoundaryReport> = applicationPackage()let package: LispexPackage = test.assertOk(packageResult)let limits: LispexLimitPreset = defaultLimits()let numeratorResult: Option<BigInt> = BigInt.parse("2", 10)let denominatorResult: Option<BigInt> = BigInt.parse("4", 10)let zeroResult: Option<BigInt> = BigInt.parse("0", 10)let numerator: BigInt = test.assertSome(numeratorResult)let denominator: BigInt = test.assertSome(denominatorResult)let zero: BigInt = test.assertSome(zeroResult)let built: Result<LispexValue, LispexValueError> = valueFromDatum(package, LispexDatumView.Number(numerator, denominator), limits.host)let value: LispexValue = test.assertOk(built)let bytes: Bytes = canonicalBytes(value)let decoded: Result<LispexValue, LispexValueError> = valueFromCanonical(package, bytes, limits.host)let restored: LispexValue = test.assertOk(decoded)io.writeLine("{canonicalBytes(restored).toHex() == bytes.toHex()}")let viewed: Result<LispexDatumView, LispexValueError> = valueView(value, limits.host)let view: LispexDatumView = test.assertOk(viewed)match (view) {case Number(n, d) => io.writeLine("{n.toString(10)}/{d.toString(10)}")case _ => io.writeLine("unexpected view")}let mut items: Array<LispexValue> = [value]let vectorResult: Result<LispexValue, LispexValueError> = valueFromDatum(package, LispexDatumView.Vector(items), limits.host)let vector: LispexValue = test.assertOk(vectorResult)let emptyResult: Result<LispexValue, LispexValueError> = valueFromDatum(package, LispexDatumView.EmptyList(), limits.host)let empty: LispexValue = test.assertOk(emptyResult)items[0] = emptylet vectorViewResult: Result<LispexDatumView, LispexValueError> = valueView(vector, limits.host)let vectorView: LispexDatumView = test.assertOk(vectorViewResult)match (vectorView) {case Vector(snapshot) => io.writeLine("{canonicalBytes(snapshot[0]).toHex() == bytes.toHex()}")case _ => io.writeLine("unexpected vector")}let invalid: Result<LispexValue, LispexValueError> = valueFromDatum(package, LispexDatumView.Number(numerator, zero), limits.host)match (invalid) {case Err(InvalidDatum(report)) => io.writeLine("{report.code != ""}")case _ => io.writeLine("unexpected conversion")}let otherKinds: Array<LispexDatumView> = [LispexDatumView.Character("a"),LispexDatumView.Symbol("rule"),LispexDatumView.Pair(value, empty),LispexDatumView.Bytevector("abc".encodeUtf8()),]for datum in (otherKinds) {let convertedKind: Result<LispexValue, LispexValueError> = valueFromDatum(package, datum, limits.host)let kindValue: LispexValue = test.assertOk(convertedKind)let kindBytes: Bytes = canonicalBytes(kindValue)let decodedKind: Result<LispexValue, LispexValueError> = valueFromCanonical(package, kindBytes, limits.host)let kindCopy: LispexValue = test.assertOk(decodedKind)io.writeLine("{canonicalBytes(kindCopy).toHex() == kindBytes.toHex()}")}return Ok(0)}
true 1/2 true true true true true true
Expected result
Expected result
Execution completes. Exit code 0.
true1/2truetruetruetruetruetrue
Use a verified Lispex application package supplied through TOPAZ_LISPEX_APPLICATION. This example specifies the Lispex 2.0 behavior. The product scope remains the public 5.21.3 observation scope.
Source evidence
- docs/content-next/en/embedding.json at
f455ac95ab30· 1 - docs/content-next/en/profiles.json at
f455ac95ab30· 1 - docs/content-next/en/values.json at
f455ac95ab30· 1 - docs/content-next/en/resources.json at
f455ac95ab30· 1 -
topaz.stdlib.contract.lispex-valuesatworking-tree - topaz.decision.lispex-v2-value-boundary.1 at
topaz.decisi