# 可以不要 let 嗎？

``````let addOne = n => n + 1;
``````

``````console.log(
)(n => n + 1)
);
``````

``````let addOne = n => n + 1;
``````

``````console.log(
)(n => n + 1)
);
``````

``````let fact = n => n < 2 ? 1 : n * fact(n - 1);
console.log(fact(5));
``````

``````console.log(
(fact =>
fact(5)
)(n => n < 2 ? 1 : n * fact(n - 1));
);
``````

`n => n < 2 ? 1 : n * fact(n - 1)` 來說，其中的 `fact` 在變數作用範圍中不存在，為了能解決這個問題，需要〈Y Combinator〉：

``````console.log(
(y =>
(fact =>
fact(5)
)(y(fact =>n => n < 2 ? 1 : n * fact(n - 1)))
)(f => (x => f(n => x(x)(n)))(x => f(n => x(x)(n))))
);
``````

``````console.log(array(

(y =>
(unit =>
(no_use =>
(yes =>
(no =>
(when =>
(not =>
(pair =>
(left =>
(right =>
(nil =>
(con =>
(tail =>
(is_nil =>
(isEmpty =>
(\$0 =>
(\$1 =>
(\$2 =>
(\$3 =>
(is_\$0 =>
(\$\$ =>
(is_\$\$ =>
(succ =>
(pair_succ =>
(prev =>
(sub =>
(len =>
(sum =>
(rcon =>
(rev =>
(reverse =>
(elems =>
(list =>
(map =>

map(list(elems(\$1)(\$2)(\$3)))(elem => sub(elem)(\$1))

)(y(map => l => f => when(isEmpty(l))(_ => nil)(_ => con(f(head(l)))(map(tail(l))(f)))))
)(es => reverse(es(\$\$)))
)(rcon(nil))
)(l => rev(nil)(l))
)(y(rev => r => l => when(isEmpty(l))(_ => r)(_ => rev(con(head(l))(r))(tail(l)))))
)(y(rcon => t => h => when(is_\$\$(h))(_ => t)(_ => rcon(con(h)(t)))))
)(y(sum => l => when(isEmpty(l))(_ => \$0)(_ => add(head(l))(sum(tail(l))))))
)(y(len => l => when(isEmpty(l))(_ => \$0)(_ => add(\$1)(len(tail(l))))))
)(m => n => n(prev)(m))
)(n => left(n(pair_succ)(pair(\$0)(\$0))))
)(p => pair(right(p))(succ(right(p))))
)(m => n => n(succ)(m))
)(n => f => x => f(n(f)(x)))
)(n => n(_ => no)(no))
)(_ => _ => yes)
)(n => n(_ => no)(yes))
)(f => x => f(f(f(x))))
)(f => x => f(f(x)))
)(f => x => f(x))
)(_ => x => x)
)(is_nil)
)(l => l(_ => _ => no))
)(right)
)(left)
)(h => t => pair(h)(t))
)(_ => yes)
)(p => p(_ => r => r))
)(p => p(l => _ => l))
)(l => r => f => f(l)(r))
)(b => b(_ => no)(_ => yes))
)(unit)
)(_ => f => f(no_use))
)(f => _ => f(no_use))
)(unit)
)(_ => _)
)(f => (x => f(n => x(x)(n)))(x => f(n => x(x)(n))))

));

function natural(n) {
return n(i => i + 1)(0);
}

function array(lt) {
let unit = _ => _;
let no_use = unit;

let yes = f => _ => f(no_use);
let no = _ => f => f(no_use);
let when = unit;

let pair = l => r => f => f(l)(r);
let left = p => p(l => _ => l);
let right = p => p(_ => r => r);

let nil = _ => yes;
let con = h => t => pair(h)(t);
let head = left;
let tail = right;

let is_nil = l => l(_ => _ => no);
let isEmpty = is_nil;

function arr(acc, l) {
return when(isEmpty(l))
(() => acc)
(() => arr(acc.concat([natural(head(l))]), tail(l)));
}
return arr([], lt);
}
``````