Giter Club home page Giter Club logo

mooncake's Introduction



Mooncake is a functional, dynamic programming language.

โ— In early development. Any kind of proposals are welcome since there's nothing to break :)

Tutorial

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)

Installation

Build from source

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

TODO

Short-term

  • Floating point numbers
  • Character type
  • Boolean or & and
  • List elements access (list(0))
  • Built-in print function
  • /= operator
  • Higher order functions
  • Better error reporting
  • Automatic function currying
  • Documentation

Long-term

  • CLI
  • REPL
  • Module system
  • Virtual machine
  • Static type system (?)

Contributing

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 [email protected]

Development

  1. Install Stack
curl -sSL https://get.haskellstack.org/ | sh

or

wget -qO- https://get.haskellstack.org/ | sh
  1. Fork the repo

  2. Make changes in the forked repo on a separate branch (name of the branch should briefly describe the issue)

  3. Play around with your changes

stack run programm.mc
  1. Run tests
stack test
  1. If tests succeed, create a PR

Detailed explanation of how to create a Pull Request.

mooncake's People

Contributors

yurtsiv avatar aitorres avatar mateidanut avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.