Mooncake is a functional, dynamic programming language.
Data types
let number = 1
let boolean = True
let string = "Hello there!"
let function = (a, b) do
a + b
end
# Lists are heterogenous i.e. can contain elements of different types. It's a comment btw
let list = [number, boolean, string, function]
Operators
# Algebra
let sum = 4 + 2
let sub = 4 - 2
let div = 4 / 2
let mul = 4 * 2
let mod = 4 % 2
# Comparison
let eq = 2 == 2
let gt = 4 > 2
let gte = 4 >= 2
let lt = 2 < 4
let lte = 2 <= 4
# Boolean logic
let false = !True
let and = True && False
let or = True || False
# Lists/strings
let list = [1, 2, 3]
let firstElem = list(0)
let listLen = len([1, 2, 3])
let strLen = len("Mooncake")
let listConcat = [1, 2, 3] ++ ["Ready", "or", "not", "here", "I", "come"]
let strConcat = "Hello" ++ " there"
let strListConcat = "Hi" ++ [1, 2, 3] # will result in ["H", "i", 1, 2, 3]
let listStrConcat = [1, 2, 3] ++ "Hi" # will result in [1, 2, 3, "H", "i"]
Conditional expressions
# Conditional expressions are expressions, not statements i.e. they return something
let truth1 =
if 4 >= 2 then
"4 is greater or equal than 2"
else
"4 is smaller than 2"
end
# No elseif yet
let truth2 =
if !(2 == 2) then
"2 is not equal to 2"
else
if 3 == 2 then
"3 is equal to 2"
else
"3 is not equal to 2"
end
end
Functions
# The last statement of a function body is what the function returns
let add = (x, y) do
let sum = x + y
sum
end
let three = add(1, 2)
# Recursion
let fib = (n) do
if n < 3 then
1
else
fib(n - 1) + fib(n - 2)
end
end
# Higher order functions
let mul = (x) do
(y) do x * y end
end
let apply = (f, val) do
f(val)
end
let eight = apply(mul(4), 2)
Install Stack
curl -sSL https://get.haskellstack.org/ | sh
or
wget -qO- https://get.haskellstack.org/ | sh
Clone the repo
git clone https://github.com/yurtsiv/mooncake.git && cd mooncake
Build and install executable
stack install
Run a programm
mooncake hello.mc
Short-term
or
& and
list(0)
)print
function/=
operatorLong-term
Feel free to create an issue or submit a PR (check out the development guide below). You can get in touch with me via E-mail yurtsiv.stepan@gmail.com
curl -sSL https://get.haskellstack.org/ | sh
or
wget -qO- https://get.haskellstack.org/ | sh
Fork the repo
Make changes in the forked repo on a separate branch (name of the branch should briefly describe the issue)
Play around with your changes
stack run programm.mc
stack test
Detailed explanation of how to create a Pull Request.