fieldIsRef (schema ordinal -- isRefLike)
Inputs
schema: Object or Ref whose dereferenced schema is Struct and whose selected item is tested.ordinal: Zero-based item ordinal being tested.
Outputs
fieldIsRef is a selected-item schema predicate. It tests whether one selected item of the dereferenced Struct schema is Ref-like.
In this builtin, Ref-like means Ref, Code, or Text. Current field contents, current knownness, and current NIL status do not participate. This is a schema predicate, not a read-result predicate, so a non-static In-place item can make fieldIsRef return FALSE even though reading that item later produces a Ref-like result. A static Ref-like item can make both fieldIsRef and fieldIsVirtual return TRUE, because schema kind and runtime storage are tested separately.
Behavior
ordinalis a zero-based knownInt32selected-item ordinal.- All other item schemas, including In-place and Meta, report
FALSE. - If
ordinalis out of bounds for the Struct schema, the builtin raises a compilation error.
Example
{} 0 {} [
dict: {
ordinaryField: 0;
textField: 0 ("") dynamic @; # an unknown Text
codeField: {} () {} codeRef;
metaField: ();
};
"-- In-place field schema versus read result --" printCompilerMessage
dict 0 fieldIsRef printStack _:;
@dict 0 fieldRead isRef printStack _:; _:;
"-- text field schema versus read result --" printCompilerMessage
dict 1 fieldIsRef printStack _:;
@dict 1 fieldRead isRef printStack _:; _:;
"-- code field schema versus read result --" printCompilerMessage
dict 2 fieldIsRef printStack _:;
@dict 2 fieldRead isRef printStack _:; _:;
"-- meta field schema versus read result --" printCompilerMessage
dict 3 fieldIsRef printStack _:;
@dict 3 fieldRead isRef printStack _:; _:;
tuple: (0 "" {} () {} codeRef);
"-- Tuple item schemas use the same category --" printCompilerMessage
tuple 0 fieldIsRef printStack _:;
tuple 1 fieldIsRef printStack _:;
tuple 2 fieldIsRef printStack _:;
0
] "main" exportFunction
Expected Output During Compilation
-- In-place field schema versus read result --
FALSE
0 Ref
TRUE
-- text field schema versus read result --
TRUE
Text
TRUE
-- code field schema versus read result --
TRUE
{} () {} codeRef CNIL
TRUE
-- meta field schema versus read result --
FALSE
()
FALSE
-- Tuple item schemas use the same category --
FALSE
TRUE
TRUE
See also
@builtin(ordinal structValue -- selectedItem)Ordinal-based one-item read with the ordinal before the Struct object.fieldReadbuiltin(structValue ordinal -- selectedItem)Ordinal-based one-item read with the Struct object before the ordinal.isRefbuiltin(object -- object isRefLike)Current stack object Ref-like predicate that preserves the object.fieldIsPrivatebuiltin(schema ordinal -- isPrivate)Visibility test for one selected Dict field.fieldIsVirtualbuiltin(schema ordinal -- hasNoStorage)No-storage test for one selected item.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.hasbuiltin(schema itemName -- hasName)Schema-level known-name presence test.schemaNamebuiltin(schema -- reportedName)Reported name of the dereferenced schema.