Declarations and types
Declarations
Section titled “Declarations”Declaration of variables
Section titled “Declaration of variables”// Local variableslet name = "Alpha"
// Global (public) variablespub meaning_of_life = 42
// Reassignmentname = "blade"
// Multiple variable declarations in onelet x, y, z = 1, 2, 3
// Multiple reassignments in onex, y, z = 4, 5, 6Typed declarations
Section titled “Typed declarations”Types allow you to explicitly describe a variable’s type. In Hybroid Live, types are not always necessary. Types might be necessary when you want to describe a complex type variable, or if the variable is left undefined. Types are what allows Hybroid Live to make sure you can write valid code without much headache and without the need to debug a lot.
number a // local variable uninitialized, type requiredlet num = 1 // local variable initialized, type inferredpub fn(text, bool) callback // global function uninitialized, type requiredpub b = true // global variable initialized, type inferredlet number c // illegal syntax!If a variable is uninitialized, Hybroid Live initializes it behind the scene with a default value for the given type. If it was a number, for example, that value would be 0. For a string, it would be an empty string and for a function, the same thing. Only variables with the basic types can be left uninitialized by the user, otherwise Hybroid Live will tell you to give the variable an explicit value.
Declaration of constants
Section titled “Declaration of constants”const PI = 3.14fType aliases
Section titled “Type aliases”Type aliases let you create reusable names for types. See the full Type aliases page for details.
alias ID = numberpub alias Config = struct{ number hp, fixed speed }Basic types
Section titled “Basic types”number // numberfixed // fixedpoint numbertext // stringbool // booleanentity // entityfn(T) -> T // functionlist<T> // listmap<T> // map