node package manager
Easy sharing. Manage teams and permissions with one click. Create a free org »


bastascript (v0.2)

Bastascript is a language designed to improve JavaScript's ability to serve as a functional programming language with terse, obvious syntax. Bastascript is a subset of JavaScript extended with additional syntax that compiles to JavaScript.

Running Bastascript code

You can compile a BS file with the following command:


The generated code will be piped to stdout.

Adding the --run flag will execute the code after compiling.


Partial Functions/Currying (skinny arrow)

Bastascript makes heavy use of partial functions, which are applied in a manner more similar to currying. This is accomplished via the skinny arrow operator (->).

Some examples:

promise.then(function() {;
}, function(err) {

could be written as

promise.then(>(x), console.error->());

A skinny arrow augmented assignment operator is provided:

x = x->(1, 2, 3);
// equivalent to
x =->(1, 2, 3);

Currying can be simulated like this:

function myfunc(x, y, z) {...;}
var curr = myfunc->();
curr =->(1);
curr = curr->(2);

Creating a partial function preserves the context of members. For instance:

var x =;
// equivalent to
var x =>();

Member Augmented Assignment

x = x.y can be written as x .= y.

Yada Yada Operator

...; will throw a new error named "Not Implemented".

if (someCondition) {

For-In-If Loops

for (var i in foo) {
    if (foo.hasOwnProperty(i)) {

can be written as

for (var i in foo if foo.hasOwnProperty(i)) {

Method Declarations

foo.method = function method() {};

can be written as

function foo.method() {

Note that the method name is preserved.


var myFunc = decorator(function() {
    // ... 
obj.method = decorator(function method() {});

can be written as

function myFunc() {
function obj.method() {

Decorators can be members or call expressions:

@call(foo, bar):, bar):

Decorators can be chained, and will be applied such that the outermost decorator will be applied last.

later Statement

The later statement allows you to defer a statement's execution until after the completion of the remainder of the function.

function test(shouldMock) {
    if (shouldMock) {
        later cleanup();

later statements retain lexical scope and their access to the this identifier. later statements will not presently work with generators.

If an exception is thrown in a function with later statements, none of the deferred statements will be executed. You should catch exceptions with try blocks instead.

return-unless and return-if statements

Return statements support a ruby-like unless clause that expands out to an if (!expr) construct. They may also use if, which expands out to if (expr).

return foo unless bar;
return foo if bar;


if (!bar) {
    return foo;
if (bar) {
    return foo;

Function shorthand

The function keyword can be replaced with the unicode character ƒ. This also works with generators: ƒ*.

ƒ foo() {
function foo() {
    // ...; 

ES6-style Fat Arrow Functions

Fat arrow functions should work as they're documented in the Harmony wiki.

x = () => foo;
y = => e.getAttribute('name'));


x = function() {return foo;};
= {return e.getAttribute('name')});

Arrow functions will bind this lexically (as in ES6) when this is used.

Note that later statements are not bound to arrow functions and instead are bound to the lexical parent. If the arrow function executes after the lexical parent has completed, the later statement will not be run.

Differences from JavaScript

  • There is no with statement.
  • All statements must be followed by a semicolon. There is no automatic semicolon insertion.
  • Only generated identifiers may start with three underscores.
  • Numeric literals may only be written as integers or floats. Octal values are not allowed.