fieldCount

fieldCount (schema -- itemCount)

Inputs

Outputs

Returns the number of items in the dereferenced Struct schema as a known Int32 value. Only the schema participates. Current value contents do not participate.

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