Constants & Variables
The next building block after types are constants and variables.
#
ConstantsConstants are immutable by design, which means their values cannot be
reassigned. Put in another way, they can be assigned once, at their
declaration. When defining a constant you need to provide a name
,
type
and a value
:
You can evaluate the constant definition above using the following CLI command:
#
VariablesVariables, unlike constants, are mutable. They cannot be declared in a global scope, but they can be declared and used within functions, or as function parameters.
⚠️ Please be wary that mutation only works within the function scope itself, values outside of the function scope will not be affected. In other words, when a function is called, its arguments are copied, as well as the environment. Any side-effect to that environment is therefore lost when the function returns.
⚠️ Notice the assignment operator
:=
forvar
, instead of=
for constants.
You can run the add
function defined above using the LIGO compiler
like this: