const

const (value -- immutableView)

Inputs

Outputs

const is a current stack-value immutable-view conversion builtin. It converts the current stack value to an immutable view where valid.

For Ref inputs, only the current stack value changes. The referenced storage and any other references remain unchanged.

Code, Text, and Meta inputs are accepted and returned unchanged. This includes callable non-NIL Code values. No fresh value is created from dereferenced schema or contents. In-place values are invalid. Because only Ref inputs change view, only Ref inputs can change their isConst result under const. Accepted unchanged Meta inputs still make isConst report FALSE.

Behavior

Example

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

  "-- current Ref view only --" printCompilerMessage
  @value printStack _:;
  @value const printStack _:;
  @value printStack _:;
  value printStack _:;
  value const printStack _:;
  @value isConst printStack _:;
  @value const isConst printStack _:;
  value const isConst printStack _:;

  "-- accepted non-Ref inputs are unchanged --" printCompilerMessage
  "hi" const printStack _:;
  unknownText const isConst printStack _:;
  {} () {} codeRef const isConst printStack _:;
  @codeLocal const isConst printStack _:;
  () const isConst printStack _:;

  0
] "main" exportFunction

Expected Output During Compilation

-- current Ref view only --
7 Ref
7 Cref
7 Ref
7 Cref
7 Cref
FALSE
TRUE
TRUE
-- accepted non-Ref inputs are unchanged --
"hi"
TRUE
TRUE
TRUE
FALSE

See also