Giter Club home page Giter Club logo

doldrums's Introduction

Doldrums

“You can swim all day in the Sea of Knowledge and not get wet.”

– Norton Juster

About the project

  • What?
    • Doldrums is a small, purely functional programming language with an emphasis on ease of top-to-bottom understanding.
  • Why?
    • I've been meaning to play with a more involved language ever since making Pixll. This is a great way for me to learn. It's probably not very useful for anything in practice.
  • Who?
    • Mitchell Vitez
  • When?
    • Summer 2020
  • How?
    • The compiler is written in Haskell. Run stack run test.dol to see an example.

Structure

I wrote the parsing using Megaparsec.

The run function performs each stage of the compilation pipeline. In order, it parses a small prelude (written in Doldrums), reads an input file, parses, evaluates, and shows the program results.

The Doldrums language

Doldrums is purely functional, which means that all values are immutable. It's also lazy, tiny, and pretty useless in the real world.

Comments

-- Line comments look like this
/* Block comments
   look like this */

Writing a program

A program is a list of functions. A function has a name, a list of arguments, and a body.

id x = x;
const x y = x;

You can define constants using a "function" with no arguments.

seven = 7;

Every program has a main function. This is what runs when the program starts.

main = const 6 7;

The $ operator

Because it has the lowest precedence, you can use $ to replace parentheses in certain situations, for cleaner code. For example,

main = f (g (h x));

is equivalent to

main = f $ g $ h x;

Let expressions

You can define variables to be used in an expression with let...in

let n = 0 in n

Multiple definitions should be separated by commas

let a = 1, b = 2, c = 3
in a * b * c

Because Doldrums is lazy, you can define your variables in any order

let x = z
  , y = 7
  , z = y
in
  x

Operator Precedence

Higher numbers mean higher precedence. All operators are binary (they have both a left and a right hand side).

Precedence Associativity Operator
6 left function application
5 right *
5 /
4 right +
4 -
3 ==
3 !=
3 >
3 >=
3 <
3 <=
2 right &&
1 right ||
0 right $

How can I do this?

I learned this material from Implementing Functional Languages: a tutorial with help from a few friends.

I can be your friend if you want help understanding this project: [email protected]

doldrums's People

Contributors

mitchellvitez 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.