fieldName (schema ordinal -- itemName)
Inputs
schema: Object or Ref whose dereferenced schema is Struct and whose stored item name is returned.ordinal: Known zero-based item ordinal whose name is returned.
Outputs
itemName: KnownTextname stored at the selected item ordinal.
Returns the stored name for one selected item ordinal in the dereferenced Struct schema. Unnamed items return the empty Text "".
The ordinal input is dereferenced and must be known at compile time. fieldName preserves the name at the specified ordinal. Repeated names remain repeated and empty names remain empty.
fieldName is therefore not an inverse of fieldIndex when names repeat or are empty, because fieldIndex collapses all matches to the last matching ordinal.
Behavior
- The
ordinalinput must be a knownInt32in the range0throughitemCount - 1. Out-of-bounds ordinals are invalid. - For Dict, the stored name at that ordinal is returned exactly.
- For List and Tuple, every valid ordinal returns
"".
Example
{} 0 {} [
mixed: { 1 "" def 2 "" def 3 "x" def 4 "x" def };
"-- fieldName keeps each ordinal separate --" printCompilerMessage
mixed 0 fieldName printStack _:;
mixed 1 fieldName printStack _:;
mixed 2 fieldName printStack _:;
mixed 3 fieldName printStack _:;
"-- fieldIndex collapses to the last match --" printCompilerMessage
mixed "" fieldIndex printStack _:;
mixed "x" fieldIndex printStack _:;
"-- Tuple items are unnamed --" printCompilerMessage
(1 FALSE) 0 fieldName printStack _:;
(1 FALSE) 1 fieldName printStack _:;
0
] "main" exportFunction
Expected Output During Compilation
-- fieldName keeps each ordinal separate --
""
""
"x"
"x"
-- fieldIndex collapses to the last match --
1
3
-- Tuple items are unnamed --
""
""
See also
fieldCountbuiltin(schema -- itemCount)Schema item count and valid ordinal-range upper bound.fieldIndexbuiltin(schema itemName -- ordinal)Name-to-ordinal lookup under last-match rules.fieldIsRefbuiltin(schema ordinal -- isRefLike)Ref-like test for one selected item schema.fieldIsVirtualbuiltin(schema ordinal -- hasNoStorage)No-storage test for one selected item.hasbuiltin(schema itemName -- hasName)Known-name presence test that does not choose an ordinal.schemaNamebuiltin(schema -- reportedName)Reported name of the dereferenced schema.