Eia64

Eia64 syntax is heavily inspired by simplicity of Kotlin.

Binary Operators

Equals ==, NotEqual !=
GreaterThan >, LesserThan <
GreaterThanEquals >=, LesserThanEquals <=
Plus +, MinusOrNegate -, * Times, Division /
And &&, Or ||, Bitwise And &, Bitwise Or |
BooleanNot !
Increment ++, Decrement --
Assignment =, AddAssign +=, ReduceAssign -=, TimesAssign *=, DivideAssign /=

Data types

Integer Int
Boolean Bool
String String
Character Char
Array Array
Unit (code blocks) Unit
Any Any

Variables

let define a constant immutable variable.

let x = 5
println(x * 5)

var define a variable mutable to any value or type.

var y = "25"
println(y * 5)
 
y = "hello world"
println(y)
println(y = 5)

Defining a type explicitly.

let a: Int = 5 * 2
let name: String = "melon"
let aUnit: Unit = { println("hello world") }
let anArray: Array = arrayOf("hello", "world")
println(anArray[0] == "hello")
let someValue: Any = "Hello " + 5

If expression

let x = true
if (condition) { .. } else { .. }
if (condition { .. } else if { .. }
if (5 * 5 == 25) { println("Yep!") }

As expressions

let a = 5
let b = 7
println(if (a > b) a else b)

Loops

Eia supports three kinds of loops, an until loop, an itr each and a for loop. continue and break statements are supported.

Until Loop

var i = 0
until (i++ < 5) {
  if (i == 5) break
  println("I is " + i)
}
I is 1
I is 2
I is 3
I is 4

For each loop

For each loop can be applied on a String and Array type

Iterating through every Char of a String

let text = "cat"
var reconstruct = ""
itr (letter in text) {
  reconstruct += letter
}
cat

Iterating on an Array

let names = arrayOf("France", "Italy", "Germany")
itr (name in names) {
  println(name)
}
France
Italy
Germany

For Loop

Similar to most programming languages, you can declare a for loop with syntax using
for (initializer, coniditonal, operational) syntax

let letters = arrayOf('H', 'A', 'C', 'K', ' ', 'C', 'L', 'U', 'B', '!')
 
for (var i = 1, i < 11, i++) {
  var tillN = ""
  for (var j = 0, j < i, j++)
    tillN += letters[j]
  println(tillN)
}

This would output:

H
HA
HAC
HACK
HACK
HACK C
HACK CL
HACK CLU
HACK CLUB
HACK CLUB!

Expressions can be empty, e.g.for (,,) { ... }

Native methods

Primitive Conversion

int(String) String type to Int bool(String) String type to Boolean str(Any) Any type to String

I/O

Print

print(Any...) println(Any...

println("Hello", " World")
Read

You can use read() and readln() to read user inputs.

let aLine = readln()
println("Read line: " + line)

I put my best effort into the language, hope you like it :)

General Purpose

time() returns time since program startup
rand(from Int, to Int) returns a random number from the range provided
len(Any) returns length of an entity, can be applied on String type, Array type and Unit type.
sleep(Int) sleeps for n millis
copy(Any) creates a copy of that object, only supports String, Int, Bool and Char type.

String formatting

You can use format(String, Any args...) native method to format your Strings. This is entirely same as String.format() in Java.

let day = 5
println(format("Today is June %dth", day))

Prints Today is June 5th

Including Std Libs

Eia64 provides a standard library, that is written in Eia itself. Check it out (opens in a new tab).

You can include them using stdlib(Names...)

Available classes: string, array, math

stdlib(array, math)
 
let nums = arrayOf(2, 4, 6, 8)
println("Average of numbers: " + math.avg(nums))
 
println(nums.indexOf(4))

Output:

Average of numbers: 5
1

Array Operations

You can allocate an array using arralloc(Int)

A code demonstrating taking a person's name through readln() then converting the read input string into an array of characters.

print("Enter your name: ")
 
let personName = readln()
let nameLength = len(personName)
 
let charactersOfName = arralloc(nameLength)
 
for (var i = 0, i < nameLength, i++) {
  charactersOfName[i] = personName[i]
}
 
println(charactersOfName)
Enter your name: Melon
EArray([M, e, l, o, n])

Similarly, you can also change an element in an array e.g. myArray[xIndex] = 7

Functions

Eia functions are declared using the fn keyword.
By default, return type is Any.

fn sayHello(name: String) {
  println(format("Hello %s!", name))
}
sayHello("Melon")

Function usage

Functions are called using the standard approach:

fn square(x: Int) {
  return x * 2
}
println(square(5))
Parameters

Function parameters are defined in the format - name: type.

fn powerOf(number: Int, exponent: Int): Int { .. }
Assignment style

Eia64 supports an inline assignment style body

fn square(n: Int) = n * n
println(square(5))
Returning

You can simply use the return keyword followed by an expression

fn calculate(x: Int, y: Int) {
 ...
 return result
}

Units

In most modern languages, you can pass a code block as an argument or store it in a variable.
You can do that in Eia too! They are called Unit types.

let printRandomNumbers: Unit = {
  let n = rand(0, 9999)
  println("A random number: " + n)
}
printRandomNumbers()
printRandomNumbers()

Output:

A random number: 5260
A random number: 6186

A more complex example:

var square_result = 0
var n = 0
fn square(upto: Int, callback: Unit) {
  for (n = 0, n < upto, n++) {
    square_result = n * n
    callback()
  }
}
 
let callback = { println(n + " squared is " + square_result) }
square(5, callback)

Output:

0 squared is 0
1 squared is 1
2 squared is 4
3 squared is 9
4 squared is 16

What if you wanted to pass arguments to Units?

Did you know that in recent update Eia supports shado units 👀
They are special form of Units that support arguments!
You can define it same way as Units but using the shado keyword.

let plus = shado(x, y) = x + y
println(plus(2, 3))

This prints out 5.

Passing in arguments"

let parrot = shado(name) {
  println(format("Hello %s!", name))
  := len(name)
}
println(parrot("Melon"))

This outputs:

Hello Melon!
5

Guideline(s)

  1. Eia64 operates on the principle of referencing, ensuring that data or values are not duplicated unless explicitly requested via the copy(Any) method. Consider this example:
fn loop(from: Int) {
  for (var i = from, i < 5, i++) { println(i) }
}
 
let myVariable = 2
loop(myVariable)
 
println(myVariable == 5)

In the example above, function loop() takes in an Int, and performs iteration. When i was assigned to from, the value want copied! It was referenced.

So the output would be true.

Standard Library

Eia standard library consists of String, Array and Math classes. Codes for standard library is written in Eia64 itself. Check it out (opens in a new tab).

String

Note that all the functions below when called, do not change the original value, rather creates a new copy.

Array

stdlib(array)
 
let x = arrayOf(1, 2, 3, arrayOf(4, 5))
println(x.recursiveLen())

The output would be 5.

E.g.

stdlib(array)
 
let x = arrayOf(1, 2, 3, arrayOf(4, 5))
println(x.flatten())

It would print EArray([1, 2, 3, 4, 5])

Math

stdlib(math)
 
let x = arrayOf(2, 4, 6, 8)
println(math.avg(x))

Cool Stuff

  1. Taking in user input and checking if it's admin!

This also demonstrates using the := operator! That helps to return value when there are multiple expressions.

stdlib(string)
 
let name = readln()
let admin = if (name.startsWith("Admin")) {
  println("Admin just logged in!")
  := true
} else {
  println("Its just another normal user")
  := false
}
 
println(admin)

Output:

> AdminMelon
Admin just logged in!
true
  1. Creating a function that calculates powers and a result callback. In the code below, a function pow() iterates till upto from 0 and powers each n to the power given.
    After powering, a callback is invoked with the results.
fn pow(upto: Int, power: Int, callback: Unit) {
    power = copy(power) - 1
 
    var n_result = 0
    var n = 0
    for (n = 0, n < upto, n++) {
        n_result = copy(n)
        let nCopy = copy(n)
 
        for (var i = 0, i < power, i++)
          n_result *= nCopy
        callback(n, n_result)
    }
}
 
let power = 3
let callback = shado(n, result){
  println(format("%d^%d is %d", n, power, result))
}
pow(5, power, callback)

This would output:

0^3 is 0
1^3 is 1
2^3 is 8
3^3 is 27
4^3 is 64

Examples

:D Hope you liked it!
16-year-old high school programmer,
Kumaraswamy

© Kumaraswamy.