JSON-shaped dynamic value literal for open object-shaped data.
Syntax: valor
Category
conversion
Related
Examples
examples/corpus/conversio/valor-boxing.fab (canonical · conversio)
T ↦ valor boxing for scalar, byte, collection, genus, and tensor carriers.
# conversio — typed values to valor boxing
#
# WHY: `T ↦ valor` boxes typed values into the canonical dynamic carrier.
# `octeti` composes as a list of numeric byte values; it must not lossy-decode
# bytes as text.
genus Punctum {
numerus x
numerus y
}
incipit {
fixum numerus n ← 42
fixum valor scalar ← n ↦ valor
nota scalar
fixum octeti bytes ← |de ad|
fixum valor boxedBytes ← bytes ↦ valor
nota boxedBytes
fixum lista<numerus> xs ← [1, 2]
fixum valor boxedList ← xs ↦ valor
nota boxedList
fixum tabula<textus, numerus> scores ← { "alpha": 10 }
fixum valor boxedMap ← scores ↦ valor
nota boxedMap
fixum Punctum pt ← Punctum { x = 3, y = 4 }
fixum valor boxedGenus ← pt ↦ valor
nota boxedGenus
fixum tensor<numerus, [2]> grid ← [5, 6] ↦ tensor<numerus, [2]>
fixum valor boxedTensor ← grid ↦ valor
nota boxedTensor
}Expected output:
Numerus(42)
Lista([Numerus(222), Numerus(173)])
Lista([Numerus(1), Numerus(2)])
Tabula({"alpha": Numerus(10)})
Tabula({"x": Numerus(3), "y": Numerus(4)})
Lista([Numerus(5), Numerus(6)])
examples/corpus/conversio/valor-genus.fab (canonical · conversio)
valor ↦ genus extraction with missing-field defaults and mandatory-field failure via ⇥ recovery.
# conversio — valor to genus extraction
#
# WHY: `valor ↦ genus` deserializes JSON objects into typed records. Missing
# defaultable fields zero-initialize; missing mandatory fields fail at runtime
# (recoverable via `⇥`). Extra JSON keys are ignored.
genus Persona {
textus nomen
numerus aetas sponte
textus regio = "Roma"
instans born
}
incipit {
fixum valor payload ← {
"nomen": "Marcus",
"born": "1979-05-27T07:32:00Z",
"extra": "ignored"
} ↦ valor
fixum Persona good ← payload ↦ Persona
adfirma good.nomen ≡ "Marcus"
adfirma good.aetas ≡ nihil
adfirma good.regio ≡ "Roma"
fixum valor stale ← { "nomen": "Livia" } ↦ valor
fixum Persona recovered ← stale ↦ Persona ⇥ good
adfirma recovered.nomen ≡ "Marcus"
fixum valor boxed ← recovered ↦ valor
fixum Persona roundtrip ← boxed ↦ Persona
adfirma roundtrip.nomen ≡ "Marcus"
adfirma roundtrip.regio ≡ "Roma"
nota roundtrip.nomen
nota roundtrip.regio
nota roundtrip.born ↦ textus
}Expected output:
Marcus
Roma
1979-05-27T07:32:00Z
examples/corpus/conversio/valor-scalaria.fab (canonical · conversio)
Scalar valor ↦ T extraction via FromValor (variant match, fractus widen, textus|instans wire).
# conversio — scalar valor extraction
#
# WHY: `valor ↦ T` is the default runtime extraction for dynamic JSON carriers.
# Scalar arms match `Valor` variants; `valor ↦ fractus` widens `Numerus` losslessly;
# `valor ↦ textus` accepts `Textus` and `Instans` wire strings. Typed datetime
# provenance stays on `valor ↦ instans` (see conversio/instans.fab). `⇥`
# recovers on variant mismatch.
incipit {
fixum valor asInt ← 42
fixum numerus count ← asInt ↦ numerus
adfirma count ≡ 42
fixum valor asFloat ← 3.5
fixum fractus ratio ← asFloat ↦ fractus
adfirma ratio ≡ 3.5
fixum valor intForFloat ← 7
fixum fractus widened ← intForFloat ↦ fractus
adfirma widened ≡ 7.0
fixum valor asBool ← verum
fixum bivalens flag ← asBool ↦ bivalens
adfirma flag ≡ verum
fixum valor asText ← "salve"
fixum textus greeting ← asText ↦ textus
adfirma greeting ≡ "salve"
fixum valor asWire ← "1979-05-27T07:32:00Z"
fixum textus wire ← asWire ↦ textus
adfirma wire ≡ "1979-05-27T07:32:00Z"
fixum valor asAscii ← 'yes'
fixum ascii token ← asAscii ↦ ascii
adfirma token ≡ 'yes'
fixum valor bad ← "not-a-number"
fixum numerus recovered ← bad ↦ numerus ⇥ 0
adfirma recovered ≡ 0
nota count
nota ratio
nota widened
nota flag
nota greeting
nota wire
nota token
nota recovered
}Expected output:
42
3.5
7.0
verum
salve
1979-05-27T07:32:00Z
yes
0
examples/corpus/conversio/valor-tensor.fab (canonical · conversio)
Compose valor ↔ tensor roundtrip via lista bridges (no dedicated valor↔tensor arms).
# conversio — valor ↔ tensor compose roundtrip
#
# WHY: `valor ↔ tensor` has no dedicated codegen arms. Extraction materializes
# `lista<T>` first; construction uses shipped `lista ↦ tensor` (`structa`) and
# flatten via `tensor ↦ lista` (`.planata()`), then `lista ↦ valor` boxing.
incipit {
fixum valor arr ← [1, 2, 3, 4]
fixum lista<numerus> xs ← arr ↦ lista<numerus>
adfirma xs.longitudo() ≡ 4
fixum tensor<numerus, [4]> grid ← xs ↦ tensor<numerus, [4]>
fixum lista<numerus> flat ← grid ↦ lista<numerus>
adfirma flat.longitudo() ≡ 4
fixum valor roundtrip ← flat ↦ valor
nota roundtrip
fixum valor obj ← { "alpha": 10, "beta": 20 } ↦ valor
fixum tabula<textus, numerus> scores ← obj ↦ tabula<textus, numerus>
nota scores.accipe("alpha") vel 0
}Expected output:
[1, 2, 3, 4]
10
examples/corpus/destructura/literal.fab (canonical · existing-home)
JSON-shaped dynamic value literal for open object-shaped data.
# destructura — valor literal expressions (inline JSON)
#
# { "clavis": expr, ... } -- JSON object literal (valor)
# { "clavis": expr, "nidum": { ... } } -- nested JSON objects
#
# Anonymous Faber object literals (`{ key = expr }`) are retired. Bare `{ }`
# now denotes a JSON valor literal: keys are quoted JSON strings separated by
# `:`, values are JSON scalars, arrays, or nested objects. Trailing commas are
# permitted (JSON5-style). Duplicate keys are an error (second occurrence).
#
# GRAMMAR:
# jsonLiteral :← '{' (jsonMember (',' jsonMember)* ','?)? '}'
# jsonMember :← string ':' jsonValue
#
# EXPECTED OUTPUT:
# Empty valor, point coords, keyed fields, nested records.
#
# BACKEND: Go emitter does not lower object `sparge` into maps (whitelist:
# destructura/literal.fab).
incipit {
# --- Empty and simple records ---
fixum _ vacuum ← {}
nota vacuum
fixum _ punctum ← { "x": 10, "y": 20 }
nota punctum
# Text keys and constant values
fixum _ forma ← { "clavis": 42 }
nota forma
# NOTE: JSON valor literals accept only constant values (strings, numbers,
# booleans, null, nested objects/arrays). For variable-backed field
# construction, use genus `Type { field = expr }` or tabula insertion.
# --- Nested valor ---
fixum _ nidum ← { "extra": { "medium": 1 } }
nota nidum
}