2023-07-28 00:33:15 +02:00
|
|
|
# mers
|
2023-03-08 22:19:51 +01:00
|
|
|
|
2023-07-28 00:33:15 +02:00
|
|
|
Mers is getting a rewrite!
|
2023-07-18 18:45:42 +02:00
|
|
|
|
2023-07-28 00:33:15 +02:00
|
|
|
This means that this README isn't complete,
|
|
|
|
many things will change,
|
|
|
|
and the docs/ are for a completely different language.
|
2023-03-08 22:19:51 +01:00
|
|
|
|
2023-07-28 00:33:15 +02:00
|
|
|
## why mers?
|
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-07-28 00:33:15 +02:00
|
|
|
Mers aims to be very simple, as in, having very few "special" things.
|
|
|
|
But this means that many things you may be familiar with simply don't exist in mers,
|
|
|
|
because they aren't actually needed.
|
|
|
|
This includes:
|
2023-07-18 18:45:42 +02:00
|
|
|
|
2023-07-28 00:33:15 +02:00
|
|
|
**Exceptions**, because errors in mers are values just like any other.
|
|
|
|
A function to read a UTF-8 text file from disk could have a return type like `String/IOError/UTF8DecodeError`,
|
|
|
|
which tells you exactly what errors can happen and also forces you to handle them (see later for mers' type-system).
|
2023-07-18 18:45:42 +02:00
|
|
|
|
2023-07-28 00:33:15 +02:00
|
|
|
**Loops**, because, as it turns out, a function which takes an iterable and a function can do this just fine.
|
|
|
|
Javascript has `forEach`, Rust `for_each`, C# `Each`, and Java has `forEach`.
|
|
|
|
At first, it seemed stupid to have a function that does the same thing a `for` or `foreach` loop can already do,
|
|
|
|
but if a function can do the job, why do we even need a special language construct to do this for us?
|
|
|
|
To keep it simple, mers doesn't have any loops except for `loop`.
|
|
|
|
`loop` simply repeats until the inner expression returns `(T)`, which causes loop to return `T`.
|
2023-07-18 18:45:42 +02:00
|
|
|
|
2023-07-28 00:33:15 +02:00
|
|
|
**Breaks** aren't necessary, since this can be achieved using iterator magic or by returning `(T)` in a `loop`.
|
|
|
|
It is also similar to `goto`, because it makes control flow less obvious, so it had to go.
|
2023-07-18 18:45:42 +02:00
|
|
|
|
2023-07-28 00:33:15 +02:00
|
|
|
The same control flow obfuscation issue exists for **returns**, so these also aren't a thing.
|
|
|
|
A function simply returns the value created by its expression.
|
2023-07-18 18:45:42 +02:00
|
|
|
|
2023-07-28 00:33:15 +02:00
|
|
|
**Functions** do exist, but they have one key difference: They take exactly one argument. Always.
|
|
|
|
Why? Because we don't need anything else.
|
|
|
|
A function with no arguments now takes an empty tuple `()`,
|
|
|
|
a function with two arguments now takes a two-length tuple `(a, b)`,
|
|
|
|
a function with either zero, one, or three arguments now takes a `()/(a)/(a, b, c)`,
|
|
|
|
and a function with n args takes a list, or a list as part of a tuple, or an optional list via `()/<the list>`.
|
2023-07-18 18:45:42 +02:00
|
|
|
|
2023-07-28 00:33:15 +02:00
|
|
|
### Types
|
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.
|
|
|
|
This is basically what dynamic typing allows you to do:
|
2023-07-18 18:45:42 +02:00
|
|
|
|
2023-07-28 00:33:15 +02:00
|
|
|
x := if condition { 12 } else { "something went wrong" }
|
2023-07-18 18:45:42 +02:00
|
|
|
|
2023-07-28 00:33:15 +02:00
|
|
|
This would be valid code.
|
|
|
|
However, in mers, the compiler still tracks all the types in your program,
|
|
|
|
and it will catch every possible crash before the program even runs:
|
|
|
|
If we tried to use `x` as an Int, the compiler would complain since it might be a string.
|
2023-07-18 18:45:42 +02:00
|
|
|
|
2023-07-28 00:33:15 +02:00
|
|
|
(note: type-checks aren't implemented since the rewrite is just barely functional, but they will be there and fully working soon)
|