Higher order proxy abuse
<p>Javascript is claimed to be a functional language, but it certainly doesn't feel like one. It lacks most of the things that make functional languages neat, one of those things being point free style. 
Fortunately we got arrow functions and proxies in ES6, so I took it upon myself to implement point free style with proxies:</p>

<pre><code>let pfree = ctx =&gt; f =&gt; new Proxy (f, {
  has: (t, p) =&gt; p in t || p in ctx
, get: (t, p) =&gt; {
    let k = p in t? t[p]: ctx[p];

    if (k instanceof Function) return (
      function fetch (_k) {
        return pfree (ctx) ( x =&gt; ( q =&gt; q instanceof Function
                                       ? fetch (q)
                                       : t (q)
                                  ) ( _k(x) )
                           )
      })(k);

    return k;
  }
});
</code></pre>

<p>Quite the headace, but it does the job- in nodejs you can use it like this:</p>

<pre><code>let p = pfree (global) (x =&gt; x)

with (p) {
  add  = x =&gt; y =&gt; x + y
  succ = add (1)
  five = succ . add (2) . succ (1)
}

console.log(five) // 5
</code></pre>

<p>The problem arise when you make higher order functions:</p>

<pre><code>with (p) {
  flip  = f =&gt; x =&gt; y =&gt; f (y) (x)
  Const = a =&gt; b =&gt; a
  dot   = f =&gt; a =&gt; b =&gt; f(a(b))
  ap    = f =&gt; g =&gt; x =&gt; f (x) (g (x))

  zero  = flip (Const)
  succ  = ap (dot) 

  num   = n =&gt; n (x =&gt; x + 1) (0) // The number n is represented by running a function n times over some input

  console.log ( num ( succ ( succ ( succ (zero) )))) // 3
  console.log ( num . succ . succ . succ (zero) )    // [Function]
}
</code></pre>

<p>And I can't really wrap my head around why ..</p>

<p>ideas?</p>