isRef (object -- object isRefLike)
Inputs
object: Current stack object whose Ref-like kind is tested.
Outputs
object: Preserved current stack object.isRefLike: KnownCondresult that isTRUEwhen the current stack object is Ref-like.
isRef is the current stack-object Ref-like predicate. It preserves the current stack object and reports whether that object is Ref-like.
In this builtin, Ref-like means Ref, Code, or Text. Current knownness, mutability, and NIL status do not change that category, so a known NIL Code object and an unknown Ref object are still Ref-like.
It answers the current stack-object question. The selected-item schema question is answered by fieldIsRef. A non-static In-place field can therefore make fieldIsRef return FALSE while a later read of that field makes isRef return TRUE.
Behavior
- In-place objects and Meta objects report
FALSE. - Changing only In-place object contents, for example with
dynamic, does not make that object Ref-like. NAMEon a non-static, non-callable In-place local produces a Ref-like object, while a plain literal of the same schema does not; see selection.
Example
{} 0 {} [
plain: 7;
unknownText: 0 ("") dynamic @; # an unknown Text
dict: { ordinaryField: 8; };
"-- field schema versus read result --" printCompilerMessage
dict 0 fieldIsRef printStack _:;
0 @dict @ isRef printStack _:; _:;
"-- In-place values --" printCompilerMessage
7 isRef printStack _:; _:;
0 dynamic isRef printStack _:; _:;
plain isRef printStack _:; _:;
@plain isRef printStack _:; _:;
"-- Ref-like also includes Text and Code --" printCompilerMessage
"hi" isRef printStack _:; _:;
unknownText isRef printStack _:; _:;
{} () {} codeRef isRef printStack _:; _:;
"-- meta value --" printCompilerMessage
() isRef printStack _:; _:;
0
] "main" exportFunction
Expected Output During Compilation
-- field schema versus read result --
FALSE
8 Ref
TRUE
-- In-place values --
7
FALSE
Int32
FALSE
7 Cref
TRUE
7 Ref
TRUE
-- Ref-like also includes Text and Code --
"hi"
TRUE
Text
TRUE
{} () {} codeRef CNIL
TRUE
-- meta value --
()
FALSE
See also
constbuiltin(object -- immutableView)Immutable view conversion for the current stack object.fieldIsRefbuiltin(schema ordinal -- isRefLike)Ref-like test for one selected item schema.isConstbuiltin(object -- isConst)Current stack-object immutability test.managed?builtin(schema -- isManaged)Managed-lifetime schema test.unconstbuiltin(object -- mutableView)Mutable view conversion for the current stack object.