fieldIsPrivate (schema ordinal -- isPrivate)

Inputs

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

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