O Language: Tokens

From Onix OS

fn

Function: def object = fn(...){....}

def

def object = something

true

Boolean: true

false

Boolean: false

if

if(...boolean){ .... }

else

else{ .... }

return

def pi = fn(x){** return "3.14" **}

show

show(object)

println

println(object)

loop

loop(condition){...result}
 def result = (loop(condition){return ...result})
 ....results array or object

Example;

def i = 0;
 loop(i>100){
   println(i);
   def i = (i+1);
 }
 ...results...

for

For loop generates results from loops

def arr = [1,2,3,4,5]
 for(arr in k,v){
   println(v)
 }
 def arrtwo = {"one":1, "two":2};
 for(arrtwo in k,v){
   println(k)
   println(v)
 }
 ...results...

load

Load some olang module, file etc:

load "filename"

scope

Create scope for functions or variables:

scope scopename {
   def scopevar = somevariable;
   def scopefn = fn(....){....}
 }
 scopename->scopevar
 scopename->scopefn(....)

proc

Create system process;

proc procname "command" "work path" ["arg1","arg2"]
 ....process result

sock

Create system socket;

sock socketname "type" "port" "ip"
 ...sock result

env

Create system environment value or change;

env "type" "value"
 getenv(result)
 ....value


begin/expect/recover/final

It is the most effective way to debug by performing some tests.

begin testname{

    expect testname <condition> {
       return "Error String..."
    }

    recover testname{
       .......Methods that will work if there is an error....
    }

    final testname{
      ......If everything is successful, the methods and functions in the final work...
   }
}

async/wait

It is a secure method for making asynchronous definitions. After defining a variable asynchronously, multiple wait operations can be performed according to the result, waiting for the variable's result.

async <variable>{
    wait <variable> {
        .....
    };

    wait <variable> {
        .....
    };
}

For example, we wrote a sum function and asked it to return the variable in 3 different ways, and we got what the last variable was as a result.

def sum = fn(x){
    return x+x;
}

async x{
    wait x {
        return "1";
    };

    wait x {
        return 2
    };

    wait x {
        return (sum(2));
    };
}

show(output("%s",x))
=> 4