1: | {var|const|def} {IDENTIFIER}: {TYPE} {ATTTRIBUTES*} = {EXPRESSION}; |
2: | {var|const|def} {IDENTIFIER} {ATTTRIBUTES*} = {EXPRESSION}; |
Variables in Panther are a mechanism to give a specific value a name. They can be declared in global scope or in local function scope. Syntax 1 creates an explicitly typed variable whereas syntax 2 creates an implicitly typed variable.
Var variables are values that have storage and are mutable. The assignment value may be an initializer value
. The value category of def variables is concrete-mutable
.
If declared: | Value Stage | Value Stage of Assignment Value |
---|---|---|
in global scope | runtime |
constexpr |
in a constexpr function | comptime |
comptime |
in a runtime function | runtime |
runtime |
Const variables are values that have storage and are not mutable. The assignment value may be an initializer value
. The value category of def variables is concrete-const
.
If declared: | Value Stage | Value Stage of Assignment Value |
---|---|---|
in global scope | comptime |
constexpr |
in a constexpr function | comptime |
comptime |
in a runtime function | runtime |
runtime |
Const variables are values that do not have storage and are not mutable. The assignment value must be constexpr
and it may be an initializer value
. The value category of def variables is ephemeral
. If declared without an explicit type and with an assignment value that is fluid
, the def variable is fluid
.
If declared: | Value Stage | Value Stage of Assignment Value |
---|---|---|
anywhere allowed | constexpr |
constexpr |
Make the variable accessable outside this module (such as through intrinsic @import
)
Argument Index | Description | Type | Is Required |
---|---|---|---|
0 | If the attribute is enabled | Bool |
no |
1 2 3 4 5var var_variable: Int = 12; // var variable const const_variable = true; // const variable that's implicitly-typed def DEF_VARIABLE: Int #pub = 12; // def variable with the `#pub` attribute def DEF_VARIABLE_FLUID = 12; // def variable that's fluid