has (schema itemName -- hasName)
Inputs
schema: Object or Ref object whose dereferenced schema is searched for the requested name.itemName: Known non-NILTextname being tested for presence.
Outputs
Tests whether the dereferenced schema contains at least one item matching the requested known name.
has uses the same name-matching rules as fieldIndex, but it stops at presence and does not return which ordinal matched.
Behavior
- For Dict, the result is
TRUEif at least one field has the requested name. - For Dict, duplicate matching names still produce only
TRUE; the builtin never reports which ordinal matched. - For Dict, the empty name
""also matches unnamed items. - For List and Tuple, only the empty name
""matches, and it matches only when the Struct object is non-empty. - For all other schemas, the result is
FALSE.
Example
{} () {} [
mixed: { 1 "" def x: 1; y: 2; };
"-- Dict field names --" printCompilerMessage
mixed "x" has printStack _:;
@mixed "x" has printStack _:;
"-- empty name --" printCompilerMessage
mixed "" has printStack _:;
(1 FALSE) "" has printStack _:;
() "" has printStack _:;
"-- missing name --" printCompilerMessage
mixed "z" has printStack _:;
(1 FALSE) "x" has printStack _:;
] "main" exportFunction
Expected Output During Compilation
-- Dict field names --
TRUE
TRUE
-- empty name --
TRUE
TRUE
FALSE
-- missing name --
FALSE
FALSE
See also
fieldCountbuiltin(schema -- itemCount)Schema item count and valid ordinal-range upper bound.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.schemaNamebuiltin(schema -- reportedName)Reported name of the dereferenced schema.