What is Uni ? The programming language

I’ve lost the implementation, sadly, so no Github link for you

Uni the language

To recap, Uni is a low-level language that has an identity crisis.

It has no garbage collector, don’t panic, you just have to remove things once used !

C++’s power

You can set types for your variables, and technically, only simple operations are allowed on variables.

Python’s nice appearence

Uni tries to not have billions of curly braces all over the place.
It also removes as much boilerplate as possible.

Javascript’s Sugar

Javascript is weak, but really cool to code in !
Uni keeps the great array management, anonymous functions, etc.

Go’s routines

Just like in Golang, routines are an essential part of Union.

Unique Features

  • Very versatile arrow synthax
  • More loops
  • Coroutines
  • Better removing
  • Pointers
  • more explanations coming…

Practical examples

These won’t have perfect synthax highlighting, sorry about that

Hello World

1
print("Hello World !")

Main Routine

1
2
3
//Imports here
func: int main(args: string[]):
return EXIT_CODE

Variables & Pointers

Here are most variable types:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
x: int = 0
y: any = 0.f
z: double = 0.
w: float = 0.f
hello: string = "Hello World !"
hi: char[] = "Hi people !"
vector: int[2](4, 2)
binary: bytes("01001010")
cond: bool = true
null: ? = undefined
pointer: ptr<int>(x)
func: int main -> 0
main: func: int = ()-> 0
time: routine<any>()

If the type has a constructor, you can initialize the variable while creating it.
x: int(0) is the same as x: int; x = 0
While not initialized, a variable defaults to the type’s default value

You can find the object the pointer refers to using: pointer::value

Imports

Import a main class / function / Namespace from a file using:

1
2
|Time|
Time.sleep(1000) //sleeps for 1 second

Import the whole file and namespace using:

1
2
|~Time|
sleep(1000)

Conditions & Loops

A If statement evaluates an expression, and runs the code below if true.
Else does the opposite.
We also have elif, which is a combo of the two

1
2
3
4
5
6
7
8
9
count:int[3](0, 15, 300)
if count[0] > 10:
print(count[0]) // doesn't print
if count[1] > 10:
print(count[1]) // 15
if count[2] > 10:
print(count[2]) // 300
else:
print("300 is supposed to be greater than 10 !") // doesn't print

A while loop starts over until the condition is false

1
2
3
4
5
//Prints all numbers up to 100
count: int
while count < 100:
++count
print(count)

A for loop will iterate over elements. Here are a few types of for loops

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
for i in int[5](12, 155, 78, 48, 92):
print(i) // 12, 155, 78, 48, 92

for i in range(5):
print(i) // 0, 1, 2, 3, 4, 5

for i to 5:
print(i) // 0, 1, 2, 3, 4, 5

for i of int[5](12, 155, 78, 48, 92):
print(i) // 0, 1, 2, 3, 4, 5

for i of ?[2], j of ?[2]:
print(i, j) // 0 0, 1 1

for j of any[2] for i of any[2]:
print(i, j) // 0 0, 0 1, 1 0, 1 1

print(
[i+3 for i to 3]
) // 3, 4, 5
print(
int[3](0, 1, 2).map(i->i+3)
) // 3, 4, 5

New Threads / Coroutines

The Routine will run on a separate thread

1
2
3
4
5
6
7
8
9
10
11
12
13
|Time|
func: int main(args: string[]):
countState = count()
Time.sleep(3000)
print(countState) // 3
-> 0

func: routine<int> count:
count: int
while true:
print(count)
yield count++ // or -> count++
Time.sleep(1000)

Get the time. Time.chrono() is a func: routine<double>.

1
2
3
4
5
6
7
8
|Time|
func: int main(args: string[]):
chrono = Time.chrono()
Time.sleep(3000)
print(chrono) // 3000.0
Time.sleep(3000)
print(chrono) // 6000.0
chrono.stop()

Structs (Custom Types)

1
2
3
4
5
6
struct Vector:
x: float,
y: float,
z: float = 0,

v: Vector(100, 100)

Classes

1
2
3
4
5
6
7
8
9
10
11
|~Math|
class Vector:
x: float
y: float
z: float
Vector(x, y, z){x, y, z}

func: float getMagnitude => sqrt(this.x**2, this.y**2)

v: Vector(100, 100)
print(v.getMagnitude())

Arrow Operators

The -> and <- operators deal with anything that has to do with sending data to an object, or appending to it.
Here are a few examples:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
indices: int[](1, 2, 3)
indices <- 4
0 -> indices
print(indices) // [0, 1, 2, 3, 4]

func: int[] fewIndices:
-> 0
-> 1, 2
-> 3
-> 4
indices = fewIndices()
print(indices) // [0, 1, 2, 3, 4]

print("Hello" -> " " <- "World !") // "Hello World !"

|~Math|
v: Vector(100, 100)
func: float getMagnitude: return sqrt(this.x**2, this.y**2) -> v
v.getMagnitude()
z: int = 100
v <- z
print(v.z) // 100

// Overwriting return value
func: bool collider(body1: Vector, body2: Vector):
-> false // sets the default return to false without returning
doThings()
if bodiesCollideInFirstWay: //totally made that up
-> true
doStuff()
if bodiesCollideInOtherWay:
-> true

// Or even smarter
func: bool collider(body1: Vector, body2: Vector):
-> false // sets the default return to false without returning
doThings()
-> bodiesCollideInFirstWay or collider::value
doStuff()
-> bodiesCollideInOtherWay or collider::value // Compares to old return value
// Optional: return collider::value

More coming soon