Public
Edited
Sep 16, 2023
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function tuple(...args) {
return {class: 'tuple', children: args.map(autoConst)};
}
Insert cell
Insert cell
Insert cell
lambda = native(([arg, body]) => ctx => x => body({...ctx, [arg]: x}))
Insert cell
merge = native(([ctx, name, value]) => ({...ctx, [name]: value}))
Insert cell
lambda.impl = apply(lambda('arg_body', compose(
unset(untuple(setter('arg'), setter('body')), g('arg_body')),
lambda('ctx', lambda('x', S(g('body'), ss(merge.fn, g('ctx'), g('arg'), g('x'))))),
)), cnst({}))
Insert cell
getValue(
apply(
apply(
call(lambda.impl, 'x', g.fn('x')),
cnst({}),
), 22
)
)
Insert cell
getValue(
apply(
apply(
call(lambda.impl, 'x', ss(add.fn, g.fn('x'), K(12))),
cnst({}),
), 22
)
)
Insert cell
getValue(
apply(
apply(
apply(
call(lambda.impl, 'x', call(lambda.impl, 'y', ss(add.fn, g.fn('x'), g.fn('y')))),
cnst({}),
), 22
), 11
)
)
Insert cell
Insert cell
K = native(([x]) => y => x)
Insert cell
K.impl = apply(lambda('x_list', compose(
unset(untuple(setter('x')), g('x_list')),
lambda('y', g('x')),
)), cnst({}))
Insert cell
ctx = native(([pairs]) => ctx => {
let res = {...ctx};
for (const [name, fun] of pairs) {
res = {...res, [name]: fun(res)};
};
return res;
})
Insert cell
getValue(apply(ctx(tuple(tuple('x', g('y')))), cnst({y: 5})))
Insert cell
getValue(apply(call(K.impl, 11), 22))
Insert cell
Insert cell
Insert cell
s = native(([f, arg]) => ctx => f(arg(ctx)))
Insert cell
Insert cell
ss0 = native(([f, args]) => ctx => f(args.map(arg => arg(ctx))))
Insert cell
map = native(fun => arr => arr.map(x => fun(x)))
Insert cell
// ss0.impl = apply(lambda('f_args', compose(
// unset(untuple(setter('f'), setter('args')), g('f_args')),
// lambda('ctx', S(g('f'), g('args'))),
// )), cnst({}))
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
I = native(x => x)
Insert cell
addY = call(
lambda('y', lambda('x', ss(add.fn, g('x'), g('y')))),
cnst({}),
)
Insert cell
getValue(apply(apply(addY, 13), 23))
Insert cell
addX = call(
lambda('args', ss(add.fn, compose(g('args'), g(0)), compose(g('args'), g(1)))),
cnst({}),
)
Insert cell
getValue(call(addX, 10, 12))
Insert cell
addZ = call(
lambda('args', compose(
set('x', compose(g('args'), g(0))),
set('y', compose(g('args'), g(1))),
ss(add.fn, g('x'), g('y')),
)),
cnst({}),
)
Insert cell
getValue(call(addZ, 10, 12))
Insert cell
addT = call(
lambda('args', compose(
unset(untuple(setter('x'), setter('y')), g('args')),
ss(add.fn, g('x'), g('y')),
)),
cnst({}),
)
Insert cell
getValue(call(addT, 10, 12))
Insert cell
addS = call(compose(
set('lambda', lambda('args', compose(
unset(untuple(setter('x'), setter('y')), g('args')),
ss(add.fn, g('x'), g('y')),
))),
SS(g('lambda'), K(11), K(22)),
), cnst({}))
Insert cell
getValue(addS)
Insert cell
addP = call(compose(
set('y', call(K.impl, 10)),
set('lambda', K(lambda('x', ss(add.fn, g('x'), g('y'))))),
set('y', call(K.impl, 30)),
set('lambda2', S(g('lambda'), I.fn)),
set('y', K(50)),
g('lambda2'),
), cnst({}))
Insert cell
getValue(addP)(12)
Insert cell
addQ = lambda('x', ss(add.fn, g('x'), g('x')))
Insert cell
addR = call(lambda.impl, 'x', ss0(add.fn, tuple(g('x'), g('y'))))
Insert cell
getValue(apply(apply(addR, cnst({y: 12})), 10))
Insert cell
addP1 = apply(
g('y'),
apply(
set('y', K(10)),
cnst({}),
),
)
Insert cell
getValue(addP1)
Insert cell
addP2 = apply(g('y'), apply(ctx(tuple(tuple('y', K(12)))), cnst({})))
Insert cell
getValue(addP2)
Insert cell
getValue(apply(apply(lambda('x', g('x')), cnst({})), 1))
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more