Variable and Constant Declarations
Constant Declaration
Whenever declaring a new constant, you must specify the type of the constant and then use =
operator to assign values:
Constants forbidden reassignment:
The sample code above throws error:
Variable Declaration
Wyrd introduce a keyword mutable
in order to declare variables:
It will compiled into JavaScript with let
variable declaration:
Hence, reassignment is now permitted:
And of course, if you already declared a constant, redeclared as mutable variable throws error:
"maybe" Types Declaration
There are cases where you might need a variable to assign value represents the concept of empty. In Wyrd, everything about empty is represented as a primitive type of value Null
.
On the other hand, Wyrd introduced maybe
types which can store either Null
value or declared type. However, since the declared variable should have mutability, not only the keyword maybe
involves, but also mutable
keyword as well:
Since mutable variables can also be assigned Null
, instead of directly assigned with Null
, we can just omit the assignment and skip to next line, it will automatically assign the maybe
type with Null
value.
Last updated
Was this helpful?