fieldCount (schema -- itemCount)
Inputs
schema: Object or Ref whose dereferenced schema is Struct and whose item count is returned.
Outputs
Returns the number of items in the dereferenced Struct schema as a known Int32 object. Only the schema participates.
Duplicate names, unnamed items, static items, and Meta items all count separately. The result therefore counts schema items, not unique names and not runtime storage slots.
The valid selected-item ordinal range of the dereferenced schema is 0 through itemCount - 1.
Behavior
Example
{} 0 {} [
dict: {
x: 1;
virtual y: 2;
z: ();
x: 3;
};
"-- duplicate names still count separately --" printCompilerMessage
dict fieldCount printStack _:;
dict 0 fieldName printStack _:;
dict 1 fieldName printStack _:;
dict 2 fieldName printStack _:;
dict 3 fieldName printStack _:;
"-- Ref to Dict --" printCompilerMessage
@dict fieldCount printStack _:;
"-- List --" printCompilerMessage
(1 2 3) fieldCount printStack _:;
"-- Tuple --" printCompilerMessage
(1 FALSE) fieldCount printStack _:;
"-- empty Tuple --" printCompilerMessage
() fieldCount printStack _:;
0
] "main" exportFunction
Expected Output During Compilation
-- duplicate names still count separately --
4
"x"
"y"
"z"
"x"
-- Ref to Dict --
4
-- List --
3
-- Tuple --
2
-- empty Tuple --
0
See also
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.fieldNamebuiltin(schema ordinal -- itemName)Ordinal-to-name lookup that preserves the stored name at one selected ordinal.hasbuiltin(schema itemName -- hasName)Known-name presence test that does not choose an ordinal.schemaNamebuiltin(schema -- reportedName)Reported name of the dereferenced schema.