Skip to content
This repository has been archived by the owner on Aug 19, 2023. It is now read-only.
/ impulse-js Public archive

A modern dialect of JavaScript with traits, extension methods, operator overloading, range and tuple literals and more.

License

Notifications You must be signed in to change notification settings

mikeaustin/impulse-js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

impulse-js

Impulse-JS is a cleaner, more modern dialect of JavaScript. It moves legacy and low-level features such as binary operators and for loops to library code, and promotes functional programming and the use of immutable data types.

NOTE: This projects was an experiment, and is no longer being maintained. It was an attempty to keep the general syntax of JavaScript, but remove all the legacy cruft and add things like extension methods and immutable data. I've been working on a new language, Kopi, which runs inside JavaScript but has it's only syntax. It's "Simple, Immutable, and 100% Asynchronous".

Check it out at https://github.com/mikeaustin/kopi.

Features include:

  • Extension Methods
  • Traits and Composition
  • Operator Overloading
  • Map, Range and Tuple Literals
  • Async Functions (CPS)
  • [Future] Named Parameters
  • [Future] Functional Loops / TCO
  • [Future] Enhanced Switch
  • [Future] Splat and Splat-Packs

The language lives happily together with existing JavaScript code and libraries. Each feature of the language is implemented as a module, so it can also be used to enhance existing JavaScript.

More details can be found here:

Current Status

Many features are implemented, but there are plenty of holes, edge cases and bugs. See Current Status to find the status of each feature.

To try it out, all you need is Node:

$ bin/impulse-js test/impulse/basics.xjs | node

Working Examples

trait Aggregate (reduce) {

  function max() {
    return Math.max.apply(null, this);
  }

}

extend Array with Aggregate {

  // Can define more functions here

}

console.log("[1, 2, 3].max() ==", [1, 3, 2].max());


//


function loadAvatar(id) {
  var profile <= loadProfile(id);
  
  var avatarImage <= loadImage(profile.avatarUrl),
      defaultImage <= loadImage(0);
  
  console.log(defaultImage, avatarImage);
}

loadAvatar(1000);


//


extend Number {

  function isEven() { return this % 2 == 0; }
  function isOdd() { return !(this.isEven()); }

}

var odds = _.filter(_.isOdd());

console.log("odds([1, 2, 3]) ==", odds([1, 2, 3]));


//


class Point extends Object {

  constructor(x, y) {
    this.x = x;
    this.y = y;
  }

  function _add(that) {
    return new Point(this.x + that.x, this.y + that.y);
  }

}

console.log("new Point(2, 3) + new Point(2, 3) ==", new Point(2, 3) + new Point(2, 3));

About

A modern dialect of JavaScript with traits, extension methods, operator overloading, range and tuple literals and more.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published