Friday, September 11, 2009

MoisUnn An Introduction

MoisUnn is a groundbreaking programming language that has just recently been launched. So not many people know about it. It is very similar to Java/C++ in some of its syntax and borrows some from Python.

The main features of MoisUnn are the ability to do concurrent assignments, powerfull list operations and multiple returns.

Concurrent Assignments:
Originally to get some thing like:
int a=5; int b=0;
int a_old=a;
a= a+5; b=a_old;
//a=10, b=5

In this better way:
int a=5; int b=0;
a,b=a+5,a;
//a=10, b=5

So the ability to write less code that is more powerful becomes evident.

List Operations:
There are some math operations you should be familiar with: +,-,/,*,%. MoisUnn introduces ^ as the exponent operator.
You can apply a single arithmetic operation on a list, or use a list to do math on another list.
EX:
to add 1 to every element in a list:
int list=[1,2,3,4,5];
for(int i=0; i less than list.size(); i++)
{ list[i]=list[i] +1; }
//list=[2,3,4,5,6]

But in MoisUnn, it is:
array of int x: [1,2,3,4,5];
x=x+1;
//x=[2,3,4,5,6]

Also to use a list on a list:
array of int x: [1,2,3] +[4,5,6];
//x=[5,7,9]

This can be applied to doubles/floats.

Boolean Operators can be applied as well (<,<=, ==,!=,=>,>)
array of boolean x: [1,2,3,4,5] less than 3;
//x=[true,true,false, false,false]

And logical operators can be applied as well (!, &&, )
array of boolean x: [true,false,true] && [false,true,true]
//x = [false, false, true].

Now the fun stuff with lists begins:
The operator ".:" will append an element to the beginning of a list. The operator "`" will pop off the first element of a list. The operator ":." will append an element to the end of a list. The operator "++" will combine two lists. The operator $ returns the size of a list.
EX:
array of int x: [1,2,3,4]; int y;
y=`x;
//y=1, x=[2,3,4]
x=x :. y;
//y=1, x=[2,3,4,1]
x= 5 .: x;
//x=[5,2,3,4,1]
x= x ++ [34,4];
//x= [5,2,3,4,1,34,4]
int b= $x;
//b=7

You can also access individual elements of a list and get values from it or put values in it.
It also allows list operations like in python.
array of int x: [1,2,3,4,5]
array of int y: x[0:2]
//y=[1,2]

There are no lists of Chars available in MoisUnn because then that would be a string.

Also the operator "in" can be applied to lists or strings like in python to see if something is in a list or a string. While the "#in" operator returns a integer with the number of occurences of some element.
EX:
array of int x :[1,2,3,4,5,5]
boolean t = 4 in x;
//t=true
t = 46 in x;
//t= false;
int y = 5 #in x;
//y=2

It can also be applied to lists as well.
array of boolean b: ([1, 2, 3] in [3,5,6,1]);
//b=[true, false, true];


Multiple Returns:

Normally do find the min and max of two elements you would have to do:
int max(int x, int y)
{ if (x greater than y) return x;
return y;
}

int min(int x, int y)
{ if (x less than y) return x;
return y;
}

int mi=min(5,2);
int ma=max(5,2);
//mi=2, ma=5

In MoisUnn:
int, int MM(int x , int y)
{ if (x greater than y)
return x,y;
else
return y,x;
}
int max, min;
max,min=MM(5,2);
//max=5,min = 2

Of course, multiple returns can make code far more powerfull and far more complex.
int ba()
int, int, fool(int x, int)
int,bool foo()
float, bool, int, int foo2(int, bool, int, int)

And then :
foo2(foo(),fool(ba(),5))

Is completely runnable.

This concludes the introduction to MoisUn. The language is still not finished and I/O and objects are being added in the near future.



MoisUnn is copyrighted by Stephen Moist and Varun Unnikrishnan.