isConst

isConst (value -- isConst)

Inputs

Outputs

isConst is the current stack-value immutability predicate. It tests whether the current stack value itself is immutable.

It tests only the current stack view. The result depends on the value on the stack, not on whether the same underlying storage is also reachable through another Ref with different mutability. The view-changing builtins const and unconst can therefore change this result only for Ref inputs. For Code values, isConst depends only on the current stack value being Code, not on whether that Code value is known, unknown, NIL, or non-NIL.

Behavior

Example

{} 0 {} [
  value: 7;
  codeLocal: {} () {} codeRef;
  unknownText: 0 ("") dynamic @;
  [] !codeLocal

  "-- mutable versus immutable Ref views --" printCompilerMessage
  @value isConst printStack _:;
  value isConst printStack _:;
  @value const isConst printStack _:;
  value unconst isConst printStack _:;

  "-- In-place values --" printCompilerMessage
  7 isConst printStack _:;
  0 dynamic isConst printStack _:;

  "-- Text and Code are const stack values --" printCompilerMessage
  "hi" isConst printStack _:;
  unknownText isConst printStack _:;
  {} () {} codeRef isConst printStack _:;
  {} () {} codeRef dynamic isConst printStack _:;
  @codeLocal isConst printStack _:;

  "-- Block and meta are not const stack values --" printCompilerMessage
  [] isConst printStack _:;
  () isConst printStack _:;

  0
] "main" exportFunction

Expected Output During Compilation

-- mutable versus immutable Ref views --
FALSE
TRUE
TRUE
FALSE
-- In-place values --
FALSE
FALSE
-- Text and Code are const stack values --
TRUE
TRUE
TRUE
TRUE
TRUE
-- Block and meta are not const stack values --
FALSE
FALSE

See also