kinx

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

This project is maintained by Kray-G

Postfix Operator

Overview

Postfix operator is below.

And also the operator of . and [] can be l-value like this.

a.prop = 100;
b[1] = 20;

Examples

Example 1. Simple use of .

Code

var obj = { a: 100, b: 200, c: 300, d: 400 };
System.println(obj.a);
System.println(obj.b);
System.println(obj.c);
System.println(obj.d);

Result

100
200
300
400

Example 2. Simple use of [] for array

Code

var ary = [1000, 2000, 3000, 4000];
System.println(ary[0]);
System.println(ary[1]);
System.println(ary[2]);
System.println(ary[3]);

Result

1000
2000
3000
4000

Example 3. Simple use of [] for object

Code

var obj = { a: 100, b: 200, c: 300, d: 400 };
System.println(obj["a"]);
System.println(obj["b"]);
System.println(obj["c"]);
System.println(obj["d"]);

Result

100
200
300
400

Example 4. Function call

Code

function f(...arg) {
    System.println("f was called with ", arg);
}
f(1, 2, 3, 4, 5, 6, 7, 8);

Result

f was called with [1, 2, 3, 4, 5, 6, 7, 8]

Example 5. Simple use of postfix ++

Code

function test(a) {
    var b = a;
    System.print([b, a++]);
    System.println(" => ", a);
}
test(97);
test(2 ** 70);
test(-(2 ** 70));

Result

[97, 97] => 98
[1180591620717411303424, 1180591620717411303424] => 1180591620717411303425
[-1180591620717411303424, -1180591620717411303424] => -1180591620717411303423

Example 6. Simple use of postfix --

Code

function test(a) {
    var b = a;
    System.print([b, a--]);
    System.println(" => ", a);
}
test(97);
test(2 ** 70);
test(-(2 ** 70));

Result

[97, 97] => 96
[1180591620717411303424, 1180591620717411303424] => 1180591620717411303423
[-1180591620717411303424, -1180591620717411303424] => -1180591620717411303425