isConst (object -- isConst)
Inputs
object: Current stack view whose immutability is tested.
Outputs
It tests only the current stack view. The result depends on the object 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.
Behavior
- Immutable Ref views report
TRUE. - Mutable Ref views report
FALSE. - Text objects report
TRUE, regardless of whether their contents are known at compile time. - Code objects report
TRUE, including known non-NIL, knownNIL, and unknownCodeobjects. - In-place objects, Block, and Meta objects report
FALSE. NAMEon a non-static, non-callable In-place local produces an immutableRefview, while@NAMEproduces a mutable view; see selection.
Example
{} 0 {} [
value: 7;
codeLocal: {} () {} codeRef;
unknownText: 0 ("") dynamic @; # an unknown Text
[] !codeLocal # a non-NIL Code
"-- 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
constbuiltin(object -- immutableView)Immutable view conversion for the current stack object.fieldIsRefbuiltin(schema ordinal -- isRefLike)Ref-like test for one selected item schema.isRefbuiltin(object -- object isRefLike)Current stack-object Ref-like test.managed?builtin(schema -- isManaged)Managed-lifetime schema test.unconstbuiltin(object -- mutableView)Mutable view conversion for the current stack object.