isRef

isRef (value -- value isRefLike)

Inputs

Outputs

isRef is the current stack-value Ref-like predicate. It preserves the current stack value and reports whether that value 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 value and an unknown Ref value are still Ref-like.

It answers the current stack-value 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

Example

{} 0 {} [
  plain: 7;
  unknownText: 0 ("") dynamic @;
  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
0
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