# Overview?

Table of Contents

Terannia sent him books about mathematics and electrical circuits when she could, but they were all mimeographed copies of originals and didnâ€™t tell him what he really needed to know. But they gave him the fundamentals, so code could be written to solve the problems. Code could do anything. Code could save the world.

- Peter F. Hamilton. (2016) Night Without Stars. Pan Books.

This is a high level introductory overview of the Concurnas syntax written to give the reader a basic understanding of the core structure of code which can be written in Concurnas.

Broadly speaking, a Concurnas program consists of one or more .conc source files expressed in a directory structure (the organization of which denotes the 'package' structure of the code). The source code within these source files may be in Unicode format (i.e. permitting non-English/mathematical variable and method names) and consist of the following sorts of entities:

• Functions and methods:

def sum(a int, b int){
return a+b
}

@Annotated(param=2)
def plusTwo(a int) => sum(a, 2)

• Unicode:

  π = Math.PI
πStr = "π=" + π//π=3.141592653589793

• Expressions:

callAFunction()
[1 2 3 4] //an integer array
[1 2 ; 3 4] //an integer matrix definition
[1, 2, 3, 4]//an integer list
2+2
2 if eval() else 15
n+1 for n in [1 2 3]//list comprehension

• Statements. Such as assignments:

a = 8
anint int = 99
var reassignOk = 12//new variable
val nonReassign = 99//new variable cannot reassign

• Control flow statements:

for(a in [1 2 3]){
processIt(a)
}

while(xyz()){
doSomething()
}

if(a){
doThis()
} elif(b){
doAnother()
} else {
another()
}

• Long lines. Code which would otherwise make for a very wide line of code may be split up for aesthetic purposes using a backslash, \:

a = 8 \
+ \
10

• Blocks. A series of entities as par above surrounded by curly braces {}

{
//many lines of code go here...
}

• Exceptions:

try{
something()
}catch(e AnException){
//react as appropriate...
}catch(all){
//catchall
}

• Core object oriented components:

class MyClass
trait MyTrait
annotation MyAnnotation
actor MyActor
actor AnotherActor of MyClass
enum MyEnum{ONE, TWO, THREE}

• Isolates and refs:

aref := 21 //a reference
res = { 'hello' + ' world' }!
//^ string concatenation performed in dedicated thread like isolate, returns ref
res int: = myfunc(12)!
//^ myfunc called in dedicated thread like isolate, returns ref
res = myfunc(12)!//same as above with return type inferred

• Reactive concurrent statements:

onchange(x){ doSomething()}//on change of x, perform an action
every(x){ doSomething(x)}//as above but including initial value
await(x; x > 2)//pause execution until the condition is met
trans{//a transaction acting upon two references
a -= 10
b += 10
}
z <= a+b//shorthand for every
z <- a+b//shorthand for onchange

• Object providers:

provider TestTweeterClient{
provide TweeterClient
Shortener => new TestShortner()
Tweeter => new MockTweeter()
}

• GPU computing:

//a simple kernel for performing matrix multiplication...
gpukernel 2 matMult(wA int, wB int, global in matA float[2], global in matB float[2], global out result float[2]) {
globalRow = get_global_id(0) // Row ID
globalCol = get_global_id(1) // Col ID

value = 0f;
for (k = 0; k < wA; ++k) {
value += matA[globalCol * wA + k] * matB[k * wB + globalRow];
}

// Write element to output matrix
result[globalCol * wA + globalRow] = value;
}

• Comments and documentation blocks:

//This is a one line comment

/* This is a multi-
line Comment */

/**
A documentation block
*/

/*
Comment here
/*
A nested comment
*/
*/


Concurnas is an optionally semicolon terminated/separated language. The newline character operates to signify the end of a line of code. For example, the following function definitions are identical:

def helloWorld1(){
ret = "hello World";
return ret
}

def helloWorld2(){
ret = "hello World"
return ret
}

def helloWorld3(){
ret = "hello World"; return ret
}


Concurnas usually offers a compact version of syntax in cases where it would otherwise be unnecessarily verbose to write (as often seen in older programming languages) for instance, for our hello world example above we could write:

def helloWorld4() => "hello World"


Concurnas runs on the JVM and thus gains access two both the high performance runtime of the JVM as well as the JDK standard library.

## Coding with Concurnas?

The ordinary workflow when building and running programs written in Concurnas is as follows:

1. Setup a project using an IDE - currently Concurnas has support for Atom, Sublime Text and VS Code (coming soon!)

2. Write code as appropriate saved into .conc files within a directory structure appropriately reflective of our desired packaged hierarchy.

3. Debug said code if a debugger is provided in our chosen IDE. (optional step)

4. Compile using the Concurnas command line compiler: concc, or via our IDE if it is integrated as such.

5. Execute the program using the Concurnas command line: conc.

Concurnas also offers the following 'lightweight' approaches.

• Concurnas REPL. The conc program can will spawn an interactive shell. This is discussed in the REPL chapter.

• Jupyter notebooks. Concurnas integrates well with Jupyter (coming soon!)

Both of the lightweight approaches above are great for trying out features of Concurnas in a scriptable manner, and also writing real software.

## Requirements?

Concurnas is a JVM language, as such it requires at least Java 1.8 to be accessible.

## Compatibility?

Concurnas has been verified as compatible with Java 1.8 to 14. Any system upon which these versions of Java runs on, Concurnas can also run on (i.e. Windows and Linux)