Skip to content

Variables

AxelHumeau edited this page Jan 14, 2024 · 2 revisions

How to define

There is two way to define a variable:

  • = : classic define method, take the name of the variable at the left and the value at the left
  • fn : define method use only on functions (more details on the Functions page)

When a variable doesn't exist it is created upon the use of = or fn, if it exist it is updated.

Exemples

bar = 5 #define a variable
bar # returns 5

bar = 9 #update the variable 
bar # returns 9

Scope

Variables are organised in scopes, a new scope is created when a function is called. A varible can only be accessed and modified from it's original scope. When creating a variable outside of a function, the variable is considered global can be accessed from all scopes.

Exemples

bar = 5 # define a variable
bar # returns 5

fn changeGlobal(||) {|
    bar = 7 # define a global variable
    foo = 9
|}

changeGlobal(||)
bar # returns 7
foo # throw an error

Mutability

All variables are mutable and can change type That means a variable can go from an Int to a String to a Function

Exemples

bar = 5 #define a variable
bar # returns 5

bar = "Hello World"
bar # return "Hello World"

bar = true
bar # return true

fn bar(||) {|
    5
|}
bar # return a function

release

Documentation

Tests

Clone this wiki locally