npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

milktea

v0.1.3

Published

Functional object-oriented scripting language

Downloads

11

Readme

milktea

The milktea is a functional object-oriented scripting language written in JavaScript.

Features

  • Dynamic typing
  • Prototype-based object-oriented programming
  • Curried functions
  • Custom operators
  • Proper tail calls

How to use

Node.js >= 4.0 or io.js >= 2.0 is strongly recommended.

Install with npm:

$ npm install git://github.com/susisu/milktea.git

or (if you want to install it globally, to use the commands below):

$ npm install -g git://github.com/susisu/milktea.git

To run milktea in your script, like this:

var mlkt = require("milktea");
var res;
try {
    res = mlkt.parser.parse(<filename:string>, <source:string>);
}
catch (err) {
    // parse error
}
if (res) {
    var program = res[0];
    var env = Object.create(mlkt.prelude);
    try {
        program.forEach(function (stmt) {
            // output the result of each statement
            console.log(stmt.run(env));
        });
    }
    catch (err) {
        // runtime error
    }
}

To run a milktea script, use mlkt command:

$ mlkt <file>

If you want to run your script interactively, use mlkti command (a REPL interpreter):

$ mlkti

Examples

Hello, world!

print "Hello, world!";

Data Types

-- Unit ('unit')
-- The Unit type has only one value `()`,
-- sometimes considered as 'nothing'.
();

-- Number ('number')
-- The Number type includes integers and floating point numbers (double).
137;
1.38e-23;

-- String ('string')
-- A value of the String type is a sequence of zero or more characters.
"Hello!";

-- Boolean ('bool')
-- The Boolean type has two values `true` and `false`.
true;
false;

-- Function ('function')
-- The type of all functions is the Function type.
\x -> x;
\x y -> x + y;

-- Reference ('reference')
-- A value of the Reference type stores a reference to a value
-- and the reference can be updated.
ref 0;

-- Array ('array')
-- A value of the Array type contains a sequence of values.
[1, "string", true];

-- Object ('object')
-- A value of the Object type can contain a set of key-value pairs.
-- Plus, an object can have its 'proto' object,
-- which is essential for the prototype-based object-oriented programming.
{ name: "Alice", age: 16 };

Variable and Function Declaration

a = 1;
b = 2;
f x y = x + y;
trace (f a b);

Recursive Function (e.g. Factorial)

factorial n =
    let itr n p =
        if n >= 1 then itr (n - 1) (p * n)
        else p
    in itr n 1
;
trace (factorial 10);

Objects

alice = {
        name : "Alice",
        age  : 16,
        greet: \this -> print ("Hello! I'm " ++ this.name)
    }
;

-- read property
trace alice.name;
trace alice.age;

-- check if the object has property
trace alice?name;
trace alice?familyName;

-- call method of the object
alice:greet;
-- it is the syntax sugar of:
alice.greet alice;

-- update property
alice!age (alice.age + 1);
trace alice.age;

License

MIT License

Author

Susisu (GitHub, Twitter)