ELV Lang REPL

ELV is a high level, dynamic and functional programming language built as a hobby project to understand the internals of programming languages. The features of the language are inspired from various programming languages

Language Features

Semicolon

; is used to denote end of expressions and variable declarations

; a+b; var a = 10;

Variables

Use var keyword to define a variable

var a = 10; var a; ## nil will be assigned by default #/ var a, b = 1; ## 1 will be assigned to a and b #/

Primitives

There are 4 primitive types

var a = 10; ## number #/ var a = "name"; ## string #/ var a = true; ## boolean (true/false) #/ var a = nil; ## nil #/

Comment

Anything specified inside ## and #/ are considered as comments

## a(); This is a comment. Function will not be executed. #/

Loop

Only for loop is supported in ELV lang

for(var i = 0; i < 10; i = i + 1) [  print(i + 1); ]

Condition

The language supports only if/if-else condition

var a = 10; if (a > 5) [ ## do something #/ ] else [ ## do something #/ ]

Operators

The language supports 2 types of operators. Binary operators and Unary operators. Using the below operators, we can do arithmetic, logical and comparison operations.

a + b; ## addition #/ a - b; ## subtraction #/ a * b; ## multiplication #/ a / b; ## division #/ a > b; ## greater than #/ a < b; ## lesser than #/ a == b; ## equals #/ a >= b; ## greater than equals #/ a <= b; ## lesser than equals #/ a != b; ## not equals #/ a & b; ## logical AND #/ a | b; ## logical OR #/ !a; ## not #/ -a; ## minus #/

Function

Functions are first class citizens in ELV lang. we can pass functions as arguments and return a function. Functions are defined using def keyword. To return a value, use ret keyword.

def sum(a, b) [  ret a + b; ]
def sumBy(a) [  def sumByFn(b) [   ret sum(a, b);  ]  ret sumByFn; ]
var sumBy2 = sumBy(2); sumBy2(4);

Closure

ELV has closures

var name = "elv"; def isAwesomeLanguage() [  ## name is a closure variable from outer scope #/  ret name == "elv"; ] isAwesomeLanguage();

Recursion

ELV has very good support for recursion

def factorial(n) [  if (n <= 1) [ ret 1; ];  ret n * factorial(n - 1); ] factorial(5);