/chocochips.js

lispy macros for sweet.js

Primary LanguageJavaScript

chocochips.js

fn

fn param_1 ... param_n [option_1 = init_1 ... option_n = init_n] -> body

Equivalent to:

(function (param_1, ..., param_n, option_1, ..., option_n) {
  if (option_1 == null) {
    option_1 = init_1 ;
  }
          :
  if (option_n == null) {
    option_n = init_n ;
  }
  return ( body );
})

proc

proc param_1 ... param_n [option_1 = init_1 ... option_n = init_n] {
  stat_1 ;
  stat_2 ;
  :
  stat_n ;
}

Equivalent to:

(function (param_1, ..., param_n, option_1, ..., option_n) {
  if (option_1 == null) {
    option_1 = init_1 ;
  }
          :
  if (option_n == null) {
    option_n = init_n ;
  }

  stat_1 ;
  stat_2 ;
    :
  stat_n ;
})

section

section {
  stat_1 ;
  stat_2 ;
  :
  stat_n ;
}

Equivalent to:

(function () {
  stat_1 ;
  stat_2 ;
  :
  stat_n ;
})();

Be careful. the section macro complements a semicolon.

when

when cond {
  stat_1 ;
  stat_2 ;
  :
  stat_n ;
}

Equivalent to:

if (cond) {
  stat_1 ;
  stat_2 ;
  :
  stat_n ;
}

Multimethods

A port of Clojure's Multimethods See source code.

foreach

foreach i <- things {
  console.log(i);
}

do notation

Using multimethods. see source code.

do Array {
  i <- [1,2,3] ;
  j <- [4,5,6] ;
  return [i,j] ;
}