Scopes

From Onix OS Wiki
Jump to: navigation, search

The scope structure is similar to class structures. All the functions defined in scope form sub functions of a scope. In this way you can clustering by writing functions in the main scope.

Definition

scope name{
...other definitions...
}

It must always be written separately because it represents a scope. Connects to all the definitions and functions within the scope name. Functions within the scope can be used repeatedly each time a call is made.

name->somefunction()
name->somedefinition

When using it, you can always call the line and the right arrow and the functions or definitions within the scope.

Example

example.ola

scope example { 
  def hello = fn(x){ 
    return ("Hello "+x)
  }; 
  def subone = fn(x){ 
    return (x + 1)
  }; 
}

main.ola

load "example.ola"
def hello = example->hello("Oytun")
def number = example->subone(1)
show(hello)
show(number)

# => Hello Oytun
# => 2

After we created a sample module, we created the sample scope and placed the functions "hello()" and "subone()" into it. Then we took the results of the output and asked "show()" to show us the results. As a result, we have tested the scope and definitions within it.