Coco 0.6.2

https://github.com/satyr/coco/tree/0.6.2

0.5.2 0.6.2
f(a).p f a .p
f() f!
o{} ^o
{o.p, o.q} o{p, q}
{p, q} = r if r? {p, q}? = r
(r) -> {p, q} = r; ... ({p, q}: r) -> ...
a.b <<< c if a?b? a?b <<< c
this import x import x
"(#{id})" "(#id)"
/\d/source /\d/$
[\A \B \C \D] [\A to \D]
[void void] [,,]
if a < b then a else b a <? b
i for i from x i for i til x
for x of xs
  run = true
  ...
unless run
  ...
for x of xs
  ...
else
  ...

機能のルーツ

ES.next Class, Destructuring, Splat
Perl Conditional Assignment, Implicit Call, Implicit Return, String Interpolation, Post if/for/while, Range, unless/until
Python Chained Comparison, Indented Block, Multiline String
Ruby super, Variable Scope
Groovy Soak (?.)

Ruby ぽいと思われがちの CoffeeScript だが、機能の多くは Ruby を通じて Perl から受け継がれたもの。明確に Ruby 由来と言えるのは変数スコープ*1くらいである。

WeakMap uniq

[http://wiki.ecmascript.org/doku.php?id=harmony:weak_maps:title=WeakMap]uniq を書いて [https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/indexOf:title=indexOf] 版と比較してみた。
Primitive を受け付けない*1ので Object.create(null) と併用する。
https://gist.github.com/1005856

ちゃんと速いようで安心。

*1:WeakMap().set(1) //=> Error: value is not a non-null object

paren-free CoffeeScript

括弧省略言語 CoffeeScript でなるべく負けた気にならないための書法集。

do
Function(js)()
# ↓
do Function js
not in/of/instanceof
not (a instanceof B)
# ↓
a not instanceof B
セミコロン
[f(a), g(h(b), c), d]
# ↓
[f a; g(h b; c); d]
関数呼び出しは右に
f(a) is b
# ↓
b is f a
代入も右に(Ruby と同じ)
(a = b) * c
# ↓
c * a = b
メソッドチェーン時の例外を利用(ブロック+行頭ドット)
f(a, c if b).g d
# ↓
f a, if b
  c
.g d

Coco 0.5.2

https://github.com/satyr/coco/tree/0.5.2

0.4.2 0.5.2
///.../// //...//
if !a? then a else b a !? b
function f(a, b) ->
  ...
function f a, b
  ...
let (a = b) ~>
  ...
let a = b
  ...
new ->
  ...
new
  ...
switch case [a, b] then switch case a, b then
[...a, b] a + [b]
[]join.call a, \- a * \-
String(x)replace /-/g '' x - /-/g
String(x)split \- x / \-
Math.pow(n, m) n ** m