Functions

From Onix OS Wiki
Jump to: navigation, search

In this section we will see how to define and use functions. If you looked at the Definitions section, you've learned how to define it. A function can be defined as a function. And it should not be confused with "Literals".

Definition

def object = fn(args...){
...other lines...
}

Here, your object is now a function and is defined in the function. To use this function, simply call it with the name of the function.

object(arg1, arg2....)
# => ...results...

Example

def sayname = fn(name){
   println(name)
}

Here we define the function "sayname ()". In this case, you can use the function "println ()" to print the contents of the "name" field.

sayname("Oytun")
#=> "Oytun"

As you can see, simply called the name "println()" function has worked.