ramda#zipWith TypeScript Examples
The following examples show how to use
ramda#zipWith.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: L3-ast.ts From interpreters with MIT License | 6 votes |
parseLetExp = (bindings: Sexp, body: Sexp[]): Result<LetExp> => {
if (!isGoodBindings(bindings)) {
return makeFailure('Malformed bindings in "let" expression');
}
// Given (letrec ( (var <val>) ...) <cexp> ...)
// Return makeLetExp( [makeBinding(var, parse(<val>)) ...], [ parse(<cexp>) ...] )
// After isGoodBindings, bindings has type [string, Sexp][]
const vars = map(b => b[0], bindings);
const valsResult = mapResult(parseL3CExp, map(second, bindings));
const bindingsResult = mapv(valsResult, (vals: CExp[]) => zipWith(makeBinding, vars, vals));
return bind(bindingsResult, (bindings: Binding[]) =>
mapv(mapResult(parseL3CExp, body), (body: CExp[]) =>
makeLetExp(bindings, body)));
}
Example #2
Source File: L4-ast.ts From interpreters with MIT License | 6 votes |
parseBindings = (bindings: Sexp): Result<Binding[]> => {
if (!isGoodBindings(bindings)) {
return makeFailure(`Invalid bindings: ${JSON.stringify(bindings, null, 2)}`);
}
const vars = map(b => b[0], bindings);
const valsResult = mapResult(binding => parseL4CExp(second(binding)), bindings);
return bind(valsResult,
(vals: CExp[]) => makeOk(zipWith(makeBinding, vars, vals)));
}
Example #3
Source File: L4-eval-box.ts From interpreters with MIT License | 6 votes |
evalLetrec = (exp: LetrecExp, env: Env): Result<Value> => {
const vars = map((b: Binding) => b.var.var, exp.bindings);
const vals = map((b: Binding) => b.val, exp.bindings);
const extEnv = makeExtEnv(vars, repeat(undefined, vars.length), env);
// @@ Compute the vals in the extended env
const cvalsResult = mapResult((v: CExp) => applicativeEval(v, extEnv), vals);
const result = mapv(cvalsResult, (cvals: Value[]) =>
zipWith((bdg, cval) => setFBinding(bdg, cval), extEnv.frame.fbindings, cvals));
return bind(result, _ => evalSequence(exp.body, extEnv));
}
Example #4
Source File: L5-eval.ts From interpreters with MIT License | 6 votes |
evalLetrec = (exp: LetrecExp, env: Env): Result<Value> => {
const vars = map((b) => b.var.var, exp.bindings);
const vals = map((b) => b.val, exp.bindings);
const extEnv = makeExtEnv(vars, repeat(undefined, vars.length), env);
// @@ Compute the vals in the extended env
const cvalsResult = mapResult((v: CExp) => applicativeEval(v, extEnv), vals);
const result = mapv(cvalsResult, (cvals: Value[]) =>
zipWith((bdg, cval) => setFBinding(bdg, cval), extEnv.frame.fbindings, cvals));
return bind(result, _ => evalSequence(exp.body, extEnv));
}
Example #5
Source File: L5-typecheck.ts From interpreters with MIT License | 6 votes |
typeofLetrec = (exp: LetrecExp, tenv: TEnv): Result<TExp> => {
const ps = map((b) => b.var.var, exp.bindings);
const procs = map((b) => b.val, exp.bindings);
if (! allT(isProcExp, procs))
return makeFailure(`letrec - only support binding of procedures - ${JSON.stringify(exp, null, 2)}`);
const paramss = map((p) => p.args, procs);
const bodies = map((p) => p.body, procs);
const tijs = map((params) => map((p) => p.texp, params), paramss);
const tis = map((proc) => proc.returnTE, procs);
const tenvBody = makeExtendTEnv(ps, zipWith((tij, ti) => makeProcTExp(tij, ti), tijs, tis), tenv);
const tenvIs = zipWith((params, tij) => makeExtendTEnv(map((p) => p.var, params), tij, tenvBody),
paramss, tijs);
const types = zipWithResult((bodyI, tenvI) => typeofExps(bodyI, tenvI), bodies, tenvIs)
const constraints = bind(types, (types: TExp[]) =>
zipWithResult((typeI, ti) => checkEqualType(typeI, ti, exp), types, tis));
return bind(constraints, _ => typeofExps(exp.body, tenvBody));
}
Example #6
Source File: L6-eval.ts From interpreters with MIT License | 6 votes |
evalLetrec = (exp: LetrecExp, env: Env, cont: Cont): Result<Value> => {
const vars = letVars(exp);
const vals = letVals(exp);
const extEnv = makeExtEnv(vars, repeat(undefined, vars.length), env);
// Compute the vals in the extended env
return evalExps(vals, extEnv,
(cvals: Result<Value[]>) => bind(cvals, (values: Value[]) => { zipWith((bdg, cval) => setFBinding(bdg, cval), extEnv.frame.fbindings, values);
return evalSequence(exp.body, extEnv, cont); }));
}
Example #7
Source File: L7c-eval.ts From interpreters with MIT License | 6 votes |
applyLetrecCont = (): void => {
dumpREG();
if (isLetrecCont(contArrayREG)) {
const cont = contArrayREG;
if (valsREG === undefined) {
console.log(`Empty valsREG in applyLetrecCont`);
return;
}
either(valsREG,
vals => {
zipWith((bdg, cval) => setFBinding(bdg, cval), cont.env.frame.fbindings, vals);
expsREG = cont.exp.body;
envREG = cont.env;
contREG = cont.cont;
pcREG = "evalSequence";
},
message => {
valREG = makeFailure(message);
contREG = cont.cont;
pcREG = "applyCont";
});
} else {
console.error(`Unknown cont ${JSON.stringify(contArrayREG)}`);
pcREG = 'halt';
}
}
Example #8
Source File: L4-env-box.ts From interpreters with MIT License | 5 votes |
makeFrame = (vars: string[], vals: Value[]): Frame =>
({tag: "Frame", fbindings: zipWith(makeFBinding, vars, vals)})
Example #9
Source File: L5-ast.ts From interpreters with MIT License | 5 votes |
parseBindings = (bindings: [Sexp, Sexp][]): Result<Binding[]> =>
bind(mapResult(parseVarDecl, map(b => b[0], bindings)), (vds: VarDecl[]) =>
mapv(mapResult(parseL5CExp, map(b => b[1], bindings)), (vals: CExp[]) =>
zipWith(makeBinding, vds, vals)))
Example #10
Source File: L5-env.ts From interpreters with MIT License | 5 votes |
makeFrame = (vars: string[], vals: Value[]): Frame =>
({tag: "Frame", fbindings: zipWith(makeFBinding, vars, vals)})
Example #11
Source File: L7-eval.ts From interpreters with MIT License | 5 votes |
makeLetrecCont = (exp: LetrecExp, extEnv: ExtEnv, cont: Cont): ContArray =>
(cvals: Result<Value[]>) =>
bind(cvals, vals => { zipWith((bdg, val) => setFBinding(bdg, val), extEnv.frame.fbindings, vals);
return evalSequence(exp.body, extEnv, cont); })
Example #12
Source File: L7a-eval.ts From interpreters with MIT License | 5 votes |
makeLetrecCont = (exp: LetrecExp, extEnv: ExtEnv, cont: Cont): ContArray =>
(cvals: Result<Value[]>) =>
bind(cvals, (vals: Value[]) => { zipWith((bdg, cval) => setFBinding(bdg, cval), extEnv.frame.fbindings, vals);
return evalSequence(exp.body, extEnv, cont); })
Example #13
Source File: L7b-eval.ts From interpreters with MIT License | 5 votes |
applyLetrecCont = (cont: LetrecCont, cvals: Result<Value[]>): Result<Value> =>
bind(cvals, (cvals: Value[]) => { zipWith((bdg, cval) => setFBinding(bdg, cval), cont.env.frame.fbindings, cvals);
return evalSequence(cont.exp.body, cont.env, cont.cont); })
Example #14
Source File: useNextQuestion.tsx From nosgestesclimat-site with MIT License | 5 votes |
questionDifference = (rule1 = '', rule2 = '') =>
1 /
(1 +
pipe(
zipWith(equals),
takeWhile(Boolean),
length
)(rule1.split(' . '), rule2.split(' . ')))