2023-07-28 00:33:15 +02:00
# mers
2023-03-08 22:19:51 +01:00
2023-08-14 17:17:08 +02:00
Mers is a high-level programming language.
It is designed to be safe (it doesn't crash at runtime) and as simple as possible.
2023-07-18 18:45:42 +02:00
2023-08-14 17:17:08 +02:00
## what makes it special
2023-04-13 03:04:47 +02:00
2023-07-28 00:33:15 +02:00
### Simplicity
2023-07-18 18:45:42 +02:00
2023-10-19 18:46:15 +02:00
Mers is simple. There are only few expressions:
2023-07-18 18:45:42 +02:00
2023-10-19 18:46:15 +02:00
- Values (`1`, `"my string"` , ...)
- Blocks (`{}`)
- Tuples (`()`)
- Assignments (`=`)
- Variable initializations (`:=`)
- Variables (`my_var`, `&my_var` )
- If statements (`if < condition > < then > [else < else > ]`)
- Functions (`arg -> < do something > `)
- Function calls `arg.function`
2023-07-18 18:45:42 +02:00
2023-10-19 18:47:39 +02:00
Everything else is implemented as a function.
2023-07-18 18:45:42 +02:00
2023-08-14 17:17:08 +02:00
### Types and Safety
2023-07-18 18:45:42 +02:00
2023-07-28 00:33:15 +02:00
Mers is built around a type-system where a value could be one of multiple types.
2023-10-19 18:46:15 +02:00
Dynamic typing allows you to do:
2023-08-14 17:17:08 +02:00
```
x := if condition { 12 } else { "something went wrong" }
```
2023-10-19 18:46:15 +02:00
In mers, the compiler tracks all the types in your program,
2023-07-28 00:33:15 +02:00
and it will catch every possible crash before the program even runs:
2023-10-19 18:46:15 +02:00
If we tried to use `x` as an int, the compiler would complain since it might be a string, so this **does not compile** :
2023-08-14 17:17:08 +02:00
```
list := (1, 2, if true 3 else "not an int")
list.sum.println
```
Type-safety for functions is different from what you might expect.
You don't need to tell mers what type your function's argument has - you just use it however you want as if mers was a dynamically typed language:
```
sum_doubled := iter -> {
one := iter.sum
(one, one).sum
}
(1, 2, 3).sum_doubled.println
```
We could try to use the function improperly by passing a string instead of an int:
```
(1, 2, "3").sum_doubled.println
```
But mers will catch this and show an error, because the call to `sum` inside of `sum_doubled` would fail.
2023-08-14 17:22:55 +02:00
(note: type-checks aren't implemented for all functions yet - some are just `todo!()` s, so mers will crash while checking your program. you may need to use `--check no` to get around this and deal with runtime panics for now)
2023-08-14 17:17:08 +02:00
2023-10-19 18:46:15 +02:00
### Error Handling
Errors in mers are normal values.
For example, `("ls", ("/")).run_command` has the return type `({Int/()}, String, String)/RunCommandError` .
This means it either returns the result of the command (exit code, stdout, stderr) or an error (a value of type `RunCommandError` ).
So, if we want to print the programs stdout, we could try
```
(s, stdout, stderr) := ("ls", ("/")).run_command
stdout.println
```
But if we encountered a `RunCommandError` , mers couldn't assign the value to `(s, stdout, stderr)` , so this doesn't compile.
Instead, we need to handle the error case, using the `try` function:
```
(
("ls", ("/")).run_command,
(
(s, stdout, stderr) -> stdout.println,
error -> error.println,
)
).try
```
2023-08-14 17:17:08 +02:00
## docs
2023-07-18 18:45:42 +02:00
2023-08-14 17:22:55 +02:00
docs will be available in some time. for now, check mers_lib/src/program/configs/*