author | Alan Dipert
<alan@dipert.org> 2019-11-01 03:21:26 UTC |
committer | Alan Dipert
<alan@dipert.org> 2019-11-01 03:21:26 UTC |
parent | 3121625544cc31afbc6651829effcd9cfa461ec2 |
jacl.js | +19 | -6 |
diff --git a/jacl.js b/jacl.js index 34ccb48..bfbe2f4 100644 --- a/jacl.js +++ b/jacl.js @@ -958,6 +958,7 @@ const parseLambdaList = list => { state = 'aux'; } else if (x instanceof LispSymbol) { sections.key.push({ + key: LispSymbol.intern('KEYWORD', x.name), name: checkValidLocal(x), initform: UNDEFINED, svar: UNDEFINED @@ -1003,8 +1004,7 @@ const parseLambdaList = list => { const analyzeLambdaList = (env, parent, list) => { const sections = parseLambdaList(list); env = env.withLocals(sections.required); - for (let i = 0; i < sections.optional.length; i++) { - const spec = sections.optional[i]; + for (const spec of sections.optional) { if (spec.initform !== UNDEFINED) { spec.initform = analyze(env, parent, spec.initform); } @@ -1013,10 +1013,23 @@ const analyzeLambdaList = (env, parent, list) => { env = env.withLocals([spec.svar]); } } - // TODO: - // rest - // key - // aux + if (sections.rest !== null) + env = env.withLocals([sections.rest]) + for (const spec of sections.key) { + if (spec.initform !== UNDEFINED) { + spec.initform = analyze(env, parent, spec.initform); + } + env = env.withLocals([spec.name]); + if (spec.svar !== UNDEFINED) { + env = env.withLocals([spec.svar]); + } + } + for (const spec of sections.aux) { + if (spec.initform !== UNDEFINED) { + spec.initform = analyze(env, parent, spec.initform); + } + env = env.withLocals([spec.name]); + } return { lambdaList: sections, bodyEnv: env