A fast, powerful, expressive and typesafe language.
Note: The language is still WIP but its pretty functional now.
To install dyc
(dynamik compiler) make sure cargo
is installed and run the following command:
$ cargo install --git https://github.com/dynamik-lang/Dynamik
And there you go!
There's no standard library right now, so we have to use printf from libc.
File: hello_world.dy
extern "C" let printf(string, ...) -> int;
printf("Hello, World!\n");
$ dyc compile hello_world.dy # to compile
$ ./hello_world # to run the executable
Hello, World!
$ dyc run hello_world.dy
Hello, World!
This is what the language supports so far. Note: Since the language is work in progress everything in this section is the subject to change.
In Dynamik, like any other language, comments are used to add notes or describe functionality in the code. They are not executed as part of the program, but provide valuable context and explanation to developers reading the code.
Dynamik uses single-line comments which start with --. Here's an example:
-- This is a comment in Dynamik
let a: int = 1; -- You can also write comments after code
Dynamik supports the following data types:
string
: A sequence of characters.int
: A 64-bit signed integer.float
: A 64-bit floating-point number.
To define a variable use the let name: type = value;
syntax. For example:
let a: int = 1;
let b: int = a + 10;
Dynamik supports the following basic math operators:
Operator | Description | Example |
---|---|---|
+ | Addition: This operator adds two numbers together. | let a: int = 1 + 2; sets a to 3 . |
- | Subtraction: This operator subtracts the second number from the first. | let a: int = 5 - 2; sets a to 3 . |
* | Multiplication: This operator multiplies two numbers together. | let a: int = 2 * 3; sets a to 6 . |
/ | Division: This operator divides the first number by the second. | let a: int = 6 / 2; sets a to 3 . |
% | Modulus: This operator returns the remainder of the first number divided by the second. | let a: int = 5 % 2; sets a to 1 . |
! | Logical NOT: This operator inverts the value of a boolean. | let a: bool = !true; sets a to false . |
- | Negation: This operator changes the sign of a number. | let a: int = -3; sets a to -3 . |
You can define functions in Dynamik using the following syntax:
fn print_hello() {
printf("Hello World");
}
Functions can also accept arguments:
fn add(v1: int, v2: int) -> int {
return v1 + v2;
}
In the above example, the add
function takes two int
arguments and returns an int
value.
Dynamik allows you to use external functions from the C library. To use an external function, you can declare it as follows:
extern "C" fn puts(string) -> int;
extern "C" fn printf(string, ...) -> int;
The ...
at the end indicates that the function can accept a variable number of arguments, making it variadic.
Dynamik supports if-else statements for controlling program flow. For example: Note: Dynamik doesn't supports
let a: int = 3;
let b: int = a + 1;
if a != b {
printf("A is not equal to B");
} else {
printf("A is equal to B");
}
In the above code, the if-else statement checks whether a
is equal to b
or not, in each case, it prints a message.
Dynamik also supports while loops. For example:
let x: int = 0;
while x < 5 {
printf("%d\n", x);
x = x + 1;
}
In the above code, the while loop prints the value of x
while it is less than 5.
Dynamik allows you to create modules to organize your code and create namespaces. For example:
mod math {
fn add(v1: int, v2: int) -> int {
return v1 + v2;
}
}
In this example, we create a module named math
. The module contains a function add
adds two values and returns the result. Using the math
module, you can call the add
function as follows:
printf("1 + 2 = %d\n", math::add(1, 2));
- Add more types
- Add pointers
- Add fixed size arrays
- Add structs
- Add traits and impl blocks
- Add dependent typing
- Create std library
- Work on the package manager