O Language: Exception Management

Exception management is an array that allows you to check whether an error has occurred depending on an object. The content is checked to see if there is an error, or to the end if no error has occurred.

Begin is used to control an object.

begin object{
   ......
}

“Expect” and “recover” are used to debug and print out errors. Automatic “error” identification is done. In this way, we can use this definition as an internal variable.

begin object{
   if (test == "hello"){
     except test "Hello is not usefull. Please use Hi on project."
   }

   recover test{
      println(error)
   }
}

If no errors are received, “final” is used. If there is no error in this way, the values in “final” are automatically executed.

def test = "hello"
begin object{
   if (test == "hello"){
     except test "Hello is not usefull. Please use Hi on project."
   }

   recover object{
     println(error)
   }

   final object{
      println("Hello is not used. Yay!")
   }
}

This is how we debug it. Exception detection can be used in this way.

Web site: http://olang.space/

Source: http://olang.space/begin

O Language: Database Management (and Object Relation Mapper)

O Language, you can write data directly into its own or SQL-based databases. With object-oriented data management, you can easily extract and manipulate your data. I will describe these database features in O Language in detail and with documentation using examples. This will tell you the features and how simple it is to make database management on O Language. This will save you extra time lost.

Continue reading “O Language: Database Management (and Object Relation Mapper)”

O Language: First Router

The router socket structure was created with the intention of creating an API over the HTTP/S protocol and exchanging data through the socket. In web based projects it is possible to write web server quickly and easily. In addition, the API can be created in micro-services.

hello.olm (as hello module):

def hello = fn(name){
 return "Hello, "+name+"! Welcome to Olang"
}

router.ola (as router script):

load "hello.olm"

def config = {
 "GET" : {
 "/" : "Welcome to the O-Lang Router!"
 },
 "POST":{
 "/:name" : hello("{{.name}}")
 }
}

show("Listening 0.0.0.0:8080... Ctrl+C to exit.")
router("8080", config);

GET method test:

~> curl -X GET localhost:8080
Welcome to the O-Lang Router!

POST method test (oytun as parameter value for name [ :name => {{.name}} ]):

~> curl -X POST localhost:8080/oytun
Hello, oytun! Welcome to Olang

As you can see in the example, we wrote a web micro service using port 8080 via get and post methods.

O Language: HTTP Example Socket

The HTTP socket allows the HTTP protocol to be displayed on the web using any port. You can use the http(path, port, response) function to easily create an http socket.

hello.olm:

def hello = fn(name){
 return "Hello, "+name+"! Welcome to Olang"
}

httptest.ol:

load "hello.olm"
show("Listening 0.0.0.0:8080... Ctrl+C to exit.")
http("/", "8080", hello("Oytun"));

First we loaded our “hello” module with load. Later in the hello() function on the 8080 port to provide this output. When we enter port localhost:8080 from our browser or curl, the result will be;

~> curl localhost:8080
 Hello, Oytun! Welcome to Olang

Now we can display the socket by connecting to 8080 port via HTTP. In the following lessons we will learn how to create routers and render pages on them.

O Language: Scopes or Classes

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

Scope definition:

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

Scope call:

def hello = example::hello("Oytun")
def number = example::subone(1)
show(hello)
show(number)

Scope output:

Hello Oytun
2

Great now you are ready to write a simple web socket.