DEV Community

Cover image for Kinx v1.0.0, Officially Released!
Kray-G
Kray-G

Posted on • Updated on

Kinx v1.0.0, Officially Released!

Hi everyone!

I released Kinx v1.0.0 officially! Please see Release Page of Kinx

Introduction

The Kinx v1.0.0 is a 1st official release version including all features developed from the beginning of this project.

By the way, this is a top secret but the next goal is a syntax highlight on GitHub. It's so hard because I hear one of the criteria is that the Kinx is used in hundreds of repository...

...I hope a little you will create a repository which using Kinx if possible.

Small Description About Kinx

The Concept

The concept is, "Looks like JavaScript, feels like Ruby, and it is a script language fitting in C programmers."

  • Looks like JavaScript ... It provides C family syntax.
  • Feels like Ruby ... Enjoy programming.
  • Fitting in C programmers ... It is easy to use for many programmers.

"C programmers" in this context means "almost all programmers." Because I think almost all programmers have used or known C language at least. And "Providing C Like Syntax" as well also means "friendly for almost all programmers."

Features

Mainly there are features below.

  • Dynamic typing and Object-Oriented programming.
  • Classes and inheritance, Higher order functions, Lexical scoping, Closures, Fiber, Garbage Collection, and so on.
  • Native function by JIT compiling supported with some limitations. Very fast.
  • Useful libraries are provided as All-In-One.

Libraries

Kinx is including useful libraries below in the standard package as All-In-One.

  • Zip ... Zip/Unzip with not only zip password but also AES password.
  • Xml ... Supporting XML as DOM structure.
  • libCurl ... Only HTTP has been already implemented.
  • SSH ... SSH login and you can execute commands.
  • Socket ... Supporting a simple TCP/UDP socket.
  • Iconv ... Converting between text encodings.
  • SQLite3 ... Database class as a useful library wrapping SQLite3.
  • Regular Expression ... Regular expression is of course supported.
  • Parser Combinator ... Exactly original implementation of Parser Combinator named as Parsek like Parsec.
  • PDF ... PDF core library based on HaruPDF.
  • JIT ... JIT library for various platforms by an abstracted assembler library.

Installation

Windows/Linux

You can download an installer from Releases page.

Scoop (for Windows)

Or you can also install it by scoop.
Type the following.

# scoop bucket add is needed only at the first time.
scoop bucket add kinx https://github.com/Kray-G/kinx
scoop install kinx
Enter fullscreen mode Exit fullscreen mode

How To Run

After confirming the command path of kinx or kinx.exe, run your script as follows.

# For Windows
$ kinx.exe [options] [<script-file>]

# For Linux
$ kinx [options] [<script-file>]
Enter fullscreen mode Exit fullscreen mode

Specification

Specification will be mostly completed so far for v1.0.0. Please look at this and try to use Kinx.

Examples

There are a lot of examples in the document on the repository, but I will only show a small example in this section. Please see the document.

hello, world.

Here is the 1st script that everyone should write.

System.println("hello, world.");
Enter fullscreen mode Exit fullscreen mode

Fibonacci

You will think it seems to be a JavaScript.

function fib(n) {
    if (n < 3) return n;
    return fib(n-2) + fib(n-1);
}

System.println("fib(34) = ", fib(34));
Enter fullscreen mode Exit fullscreen mode

Fibonacci in native

Replacing function by native, that makes faster. Please try it now.

native fib(n) {
    if (n < 3) return n;
    return fib(n-2) + fib(n-1);
}

System.println("fib(34) = ", fib(34));
Enter fullscreen mode Exit fullscreen mode

Closure

The function object has a lexical scope and you can use a closure.

function newCounter() {
    var i = 0;          // a lexical variable.
    return function() { // an anonymous function.
        ++i;            // a reference to a lexical variable.
        return i;
    };
}

var c1 = newCounter();
System.println(c1()); // 1
System.println(c1()); // 2
System.println(c1()); // 3
System.println(c1()); // 4
System.println(c1()); // 5
Enter fullscreen mode Exit fullscreen mode

Lambda

Anonymous function is easy to be written.

function calc(x, y, func) {
    return func(x, y);
}

System.println("add = " + calc(10, 2, { => _1 + _2 }));
System.println("sub = " + calc(10, 2, { => _1 - _2 }));
System.println("mul = " + calc(10, 2, { => _1 * _2 }));
System.println("div = " + calc(10, 2, { => _1 / _2 }));
// add = 12
// sub = 8
// mul = 20
// div = 5
Enter fullscreen mode Exit fullscreen mode

Class

Of course, a class is available.

class A {
    var flag_ = false;  // a local private variable.
    public flagOn() {
        @flagOnActual();
    }
    public flagOnActual() {
        @flag = true;   // a public variable.
    }
}

var a = new A();
a.flagOn();
System.println(a.flag ? "true" : "false");  // => true
Enter fullscreen mode Exit fullscreen mode

Module

Module can mixin into a class.

module M {
    public method1() {
        System.println("This is a method1");
    }
}

class A {
    mixin M;
}

new A().method1();  // => This is a method1
Enter fullscreen mode Exit fullscreen mode

Fiber

You can use Fiber.

var fiber = new Fiber {
    System.println("fiber 1");
    yield;
    System.println("fiber 2");
};

System.println("main 1");
fiber.resume();
System.println("main 2");
fiber.resume();
System.println("main 3");
// main 1
// fiber 1
// main 2
// fiber 2
// main 3
Enter fullscreen mode Exit fullscreen mode

Spread/Rest Operator

It was introduced by ES6 of JavaScript. I wanted it so much, and it is so useful. There's a lot of use cases, but here is a simple example.

function sample(a1, a2, ...a3) {
    // a1 = 1
    // a2 = 2
    // a3 = [3, 4, 5]
}

sample(1, 2, 3, 4, 5);
Enter fullscreen mode Exit fullscreen mode

Pattern Matching

It supports an assignment by pattern matching. Of course it can be also used in declaration and a function argument.

[a, b, , ...c] = [1, 2, 3, 4, 5, 6];
{ x, y } = { x: 20, y: { a: 30, b: 300 } };
{ x: d, y: { a: e, b: 300 } } = { x: 20, y: { a: 30, b: 300 } };

System.println("a = ", a);
System.println("b = ", b);
System.println("c = ", c);
System.println("d = ", d);
System.println("e = ", e);
System.println("x = ", x);
System.println("y = ", y);

// => .y.b requires 300, but it is 3 in actual.
{ x: d, y: { a: e, b: 300 } } = { x: 20, y: { a: 30, b: 3 } };

// a = 1
// b = 2
// c = [4, 5, 6]
// d = 20
// e = 30
// x = 20
// y = {"a":30,"b":300}
// Uncaught exception: No one catch the exception.
// NoMatchingPatternException: Pattern not matched
// Stack Trace Information:
//         at <main-block>(test.kx:14)
Enter fullscreen mode Exit fullscreen mode

Pipeline Operator

Pipeline operator is also supported.

function doubleSay(str) {
    return "%{str}, %{str}";
}
function capitalize(str) {
    return str.toUpper(0, 1);
}
function exclaim(str) {
    return str + '!';
}

var result = exclaim(capitalize(doubleSay("hello")));
System.println(result); // => "Hello, hello!"

var result = "hello"
  |> doubleSay
  |> capitalize
  |> exclaim;

System.println(result); // => "Hello, hello!"
Enter fullscreen mode Exit fullscreen mode

Function Composition Operator

You can also composite functions!

const double = &(n) => n * 2;
const increment = &(n) => n + 1;

// Normal case.
var r1 = double(increment(double(double(5)))); // 42
System.println(r1);

// Function composition operator is higher priority than a pipeline operator.
var r2 = 5 |> double +> double +> increment +> double; // 42
System.println(r2);
Enter fullscreen mode Exit fullscreen mode

Conclusion

I finally release it officially, but of course there may be a bug or some unexpected behavior.

If you try to use it, I am very appreciated. When you faced a problem, please let me know via Issues in the repository. I will welcome any report.

Again, please see Kinx specification for details.

Many thanks.

Top comments (0)