lambdas and application now in AST, types and interpreter

This commit is contained in:
Dustin Swan 2026-01-30 21:31:06 -07:00
parent d60e5aa29f
commit 920151f49c
No known key found for this signature in database
GPG key ID: 30D46587E2100467
4 changed files with 102 additions and 4 deletions

View file

@ -28,3 +28,47 @@ const env: Env = new Map();
const res = evaluate(ast, env);
console.log(res);
const ast2: AST = {
kind: 'let',
name: 'add',
value: {
kind: 'lambda',
params: ['x', 'y'],
body: {
kind: 'binaryop',
operator: '+',
left: {
kind: 'variable',
name: 'x',
},
right: {
kind: 'variable',
name: 'y',
}
}
},
body: {
kind: 'apply',
func: {
kind: 'variable',
name: 'add'
},
args: [
{
kind: 'literal',
value: { kind: 'int', value: 2 }
},
{
kind: 'literal',
value: { kind: 'int', value: 3 }
},
]
}
};
const env2: Env = new Map();
const res2 = evaluate(ast2, env2);
console.log(res2);