Dynamik is a toy, dynamically-typed language, written in Kotlin.
- Expressions with Strings and Integers. (At present, the result of an operation with Integers is implicitly converted to a Double.)
- (Im)mutable variable bindings with val/var
- If/Else statements
- For/While loops
- Functions
- Comments
- Memoization builtin
- Collections (list, map)
- Classes
- Builtin timer
- Repl
git clone https://github.com/NavyaZaveri/dynamik
./gradlew build
java -jar build/libs/dynamik-1.0-SNAPSHOT-all.jar --file=<filename>
java -jar build/libs/dynamik-1.0-SNAPSHOT-all.jar --repl
//the @memo annotation caches the output of fib against its input and uses it
//when needed
@memo
fn fib(n) {
if (n<2) { return n;}
return fib(n-1) + fib(n-2);
}
val res = fib(100);
print(res);
//create a "final" variable
val hello = "world";
// can't do this (throws ValError)
// hello = "world";
var foo = 1;
foo = 2; //works
class Animal(name) {
fn change_name(new_name) {
this.name = new_name;
}
}
val dog = Animal("foo");
dog.change_name("bar");
print(dog.name);
//initialzie a list with one value.
val my_list = list(0);
for (var i=1;i<=10;i = i+1) {
my_list.add(i);
}
val my_map = map();
my_map.insert("hello", my_list.get(1));
assert(my_map.get("hello") == 1);