OXPL
Ontology-assisted Experimental Programming Language

Welcome to the OXPL homepage!

OXPL is a programming language under development.

Example

Fibonacci

fn fib(n: uint) -> result: uint {
    if n == 0 {
        return 0;
    } else if n == 1 {
        return 1;
    } else {
        return fib(n - 1) + fib(n - 2);
    }
}

fn main() {
    println(fib(5));
}

Data import

import dapro; /* data processor */

use std::sourcesFrom;

use dapro::csv;
use dapro::json;
use dapro::isDataModel;
use dapro::compare::compare;
use dapro::compare::CompareResult;

class City {
    /* This is our relevant information */
    prop name;
    prop inhabitants;

    isDataModel.
}

fn cities_from_csv(file) -> cities: list {
.   <City.name> sourcesFrom <( CsvColumn("name") )>.
.   <City.name> sourcesFrom <( CsvColumn("inh") )>.
.   <file> csv::hasHeaderLineCount 1.

    return csv::import(City, file);
}

fn cities_from_json(file) -> cities: list {
.   <City.name> sourcesFrom <( JsonField("cityName") )>.
.   <City.name> sourcesFrom <( JsonField("cityInhabs") )>.

    return json::import(City, file);
}

fn main() {
    var csv_file: File = File("cities.csv", File::READ);
    var json_file: File = File("cities.json", File::READ);

    var csv_cities = cities_from_csv(csv_file);
    var json_cities = cities_from_json(json_file);

    /* Work with data */
    if (compare(csv_cities, json_cities) == CompareResult::Same) {
        println("Both files contain the same relevant information");
    }
}
        

Web server

import std::net::server;

use server::webserver::WebServer;
use server::listensOnTcpPort.
use server::webserver::routes;

instance WebServer {
    listensOnTcpPort 8080. /* this is a fact */

    /* this facts states a binary relation
       and says that the: <WebServer> listensOnTcpPort 8080. */

    routes "/" to <index>.

    /* this is a ternary relation between the WebServer,
       a string (representing a URL) and a handler function. */
}

fn index() -> result: string {
    var text: string = "Hello world!";

    /* facts can also be queried */
    if ?(<WebServer> listensOnTcpPort 8080) {
        string.append("\nServer listens on port 8080!");
    }

    for route, handler in @(<WebServer> routes <route> to <handler>) {
        string.append("\nRoutes " + route + " to " + handler);
    }

    return text;
}

fn main() {
$   runsForever. /* This is an inline fact. */
    WebServer.start();
}