fieldIsPrivate (schema ordinal -- isPrivate)
Inputs
schema: Object or Ref whose dereferenced schema is Struct and whose selected item is tested.ordinal: Zero-based item ordinal being tested.
Outputs
fieldIsPrivate is a selected-item visibility predicate. It tests whether one selected item of the dereferenced Struct schema was created with the private specifier.
Only Dict fields can be private. The private mark belongs to the Dict schema: two Dict schemas that differ only in the private mark of one field are not same, and the formatted schema name shows private after each private field. Current field contents do not participate, so a known or unknown value of the Dict produces the same result.
A private field is still a full schema item. It counts in fieldCount, is found by fieldIndex, fieldName, and has, and can be read by ordinal through @ and fieldRead. Known-name data selection through callField calls callable fields and reads non-callable fields. Source-text selection from outside the Dict remains invalid; see selection. Scope lookup inside the fields of that Dict, including through self, remains available.
Behavior
ordinalis a zero-based knownInt32selected-item ordinal.TRUEmeans that the selected item is aDictfield created with theprivatespecifier, throughNAME: ...;ordef.ListandTupleitems reportFALSE; unnamed items cannot carry the private mark.- If
ordinalis out of bounds for the Struct schema, the builtin raises a compilation error.
Example
{} 0 {} [
dict: {
publicField: 0;
private privateField: 1;
private staticField: 2n8 virtual;
3 "publicByDef" def
private 4 "privateByDef" def
};
"-- per-ordinal results --" printCompilerMessage
dict 0 fieldIsPrivate printStack _:;
dict 1 fieldIsPrivate printStack _:;
dict 2 fieldIsPrivate printStack _:;
dict 3 fieldIsPrivate printStack _:;
dict 4 fieldIsPrivate printStack _:;
"-- private marks are part of the Dict schema --" printCompilerMessage
dict schemaName printStack _:;
{x: 0; private y: 1;} {x: 0; y: 1;} same printStack _:;
"-- private fields stay visible to schema queries and ordinal reads --" printCompilerMessage
dict "privateField" has printStack _:;
dict "privateField" fieldIndex printStack _:;
dict 1 fieldName printStack _:;
dict 1 fieldRead printStack _:;
"-- private fields are reachable inside the Dict --" printCompilerMessage
holder: {
private secret: 5;
reveal: [secret printStack _:;];
};
holder.reveal
"-- Ref input and unknown contents do not matter --" printCompilerMessage
unknownDict: {x: 0; private y: 1;} dynamic;
@unknownDict 1 fieldIsPrivate printStack _:;
"-- List and Tuple items are never private --" printCompilerMessage
(1 2 3) 0 fieldIsPrivate printStack _:;
(1 FALSE) 1 fieldIsPrivate printStack _:;
0
] "main" exportFunction
Expected Output During Compilation
-- per-ordinal results --
FALSE
TRUE
TRUE
FALSE
TRUE
-- private marks are part of the Dict schema --
"{publicField: Int32; privateField: Int32 private; staticField: 2n8 virtual private; publicByDef: Int32; privateByDef: Int32 private;}"
FALSE
-- private fields stay visible to schema queries and ordinal reads --
TRUE
1
"privateField"
1 Cref
-- private fields are reachable inside the Dict --
5 Cref
-- Ref input and unknown contents do not matter --
TRUE
-- List and Tuple items are never private --
FALSE
FALSE
See also
privatebuiltin(--)Pending visibility specifier for the next successful name creation.fieldIsRefbuiltin(schema ordinal -- isRefLike)Ref-like test for one selected item schema.fieldIsVirtualbuiltin(schema ordinal -- hasNoStorage)Storage test for one selected item schema.fieldCountbuiltin(schema -- itemCount)Item count of the Struct schema.fieldIndexbuiltin(schema itemName -- ordinal)Selected item ordinal from item name under last-match rules.fieldNamebuiltin(schema ordinal -- itemName)Stored item name at one selected item ordinal.fieldReadbuiltin(structValue ordinal -- selectedItem)Ordinal-based one-item read with the Struct object before the ordinal.callFieldbuiltin(inputs... dict name -- outputs...)Known-name data-input field selection.hasbuiltin(schema itemName -- hasName)Schema-level known-name presence test.samebuiltin(leftSchema rightSchema -- isSameSchema)Exact schema equality test.schemaNamebuiltin(schema -- reportedName)Reported name of the dereferenced schema.