{{< table_of_contents >}}
ReGIna’s syntax is an amalgamation of kotlin and python.
Essentially, file is a set of classes, objects, functions and
imports. Executable and importable files have .rgn
format.
Class declaration should satisfy following format:
class ClassName : SuperClassName {
...
}
where : SuperClassName
is optional.
Class contains properties and functions.
Similar syntax to type, although it cannot be inherited.
object ObjectName {
...
}
Object is a singleton that is lazily initialized (when a property is called, it is initialized and everything needed for its initialization).
object Lazy {
= b
a = 1
b = 2
c }
fun main() {
// here nothing in Lazy is initialized
(Lazy.a)
log// here Lazy.a and Lazy.b are initialized, c is not
}
Function has non-default parameters and default parameters. Default parameters go after other ones.
fun functionName(param0, param1, ..., default_param0 = defaultValue, ...) {
functionBody}
{{< refer “regina/scopes/#using-functions-with-same-signature” “Accessing functions with same signature” >}}.
[!warning] Warning
Do not use following file names: Global.rgn, this.rgn
Imports are declarations that allow to use objects, classes and functions from an imported file.
Take a look at a table of operator precedence
+
non commutative addition with implicit type
conversion. All use cases:
// List + Any <=> List.add(Any)
[1, 2] + 3 // == [1,2,3]
// String + Any <=> String + Any.toString()
"Hello, " + "Alex" // == "Hello, Alex"
// Int + Double or Double + Int <=> double(Int) + Double
1 + 3.2 = 4.2
if(...) .. else ..
- ternary operator is
kotlin-like.
Boolean operators return 0 and 1 respectively (non-)equality:
==
, !=
Comparison: >
, <
, >=
,
<=
Logical operators: &&
, ||
. As in
other languages, if left operand is enough to resolve an operator, right
operator is not evaluated
!
: not prefix operator. Inverts expression.
true
is 1, false
is 0. {{< refer
“regina/types/#boolean” “Boolean is Int.” >}}
Examples:
// true and false are 1 and 0 respectfully.
// There is no boolean type, only keywords,
// that are changed to numbers during runtime
true // == 1
false // == 0
!true // == 0
[!note] Notes
In the future,
&
and|
operators might be added.
= ...
variableName .PropertyName = ... className
Variables and properties are dynamic, meaning they are type
independent. a
can be String and in the next line it can be
Int or class instance.
References are expressions of form a.b.c
. They serve 3
purposes:
while is a cycle which body executes until the condition is false.
= 1
condition while(condition) {
}
foreach has:
Foreach will run the body for all the elements of collection.
= [1, [], 3, [], 5]
arr (i in arr) {
foreachif(i is List)
.add("a")
ielse i = i + 1
}
// arr == [1, ["a"], 3, ["a"], 5]
(i in arr) {
foreach.remove(i)
arr}
// arr == [["a"], ["a"]]
// this happens because foreach internally
// iterates over a collection by an index.
// t
// it is very unadvisable to modify collection's size inside foreach.
Similar to list, but all iterable elements are not changeable
// range is a unique function used only inside foreach
// it has 3 arguments, where third is optional: step
= []
li (i in range(0, 10, 2))
foreach.add(i)
li// li == [0, 2, 4, 6, 8, 10]
// if step is not specified, it equals to 1 or -1,
// depending on start and end
(i in range(1, 3))
foreach.add(i + 10)
li// li == [0, 2, 4, 6, 8, 10, 11, 12, 13]
(i in range(3, 0)) {
foreach.removeAt(i)
li}
// li == [8, 10, 11, 12, 13]
Camel case is used.
Variables, functions start with a lowercase letter.
= [] // create empty list
empty = [1, "2", [3, 4], {5:6}] // create list with elements filled
= {1:2} // dict key value pair is created with a colon
dict [1] // accessing value by dict key
dict["key"] = "value" // assigning value to key
dict["not found"] dict