author | Alan Dipert
<alan@dipert.org> 2019-10-26 05:30:20 UTC |
committer | Alan Dipert
<alan@dipert.org> 2019-10-26 05:30:20 UTC |
parent | 8b19975244893d966c76ab94c105d1a3ef0997c7 |
jacl.js | +34 | -0 |
diff --git a/jacl.js b/jacl.js index d6aaf4a..3760f89 100644 --- a/jacl.js +++ b/jacl.js @@ -847,6 +847,40 @@ const analyzeBlock = (env, parent, forms) => { return { statements: stmts, ret: ret }; }; +const parseLambdaList = list => { + const kwNames = new Set(['&KEY', '&OPTIONAL', '&REST']), + arr = Cons.toArray(list); + let sections = { + required: [], + optional: [], + keyword: [], + rest: null + }, + section = 'required'; + scan: for (let i = 0; i < arr.length; i++) { + const x = list[i]; + if (x instanceof LispSymbol) { + switch (x.name) { + case '&OPTIONAL': + case '&KEY': + section = x.name.substring(1).toLowerCase(); + continue scan; + case '&REST': + if (arr.length-i !== 2) + throw new Error(`One argument name must follow &REST`); + sections.rest = arr[i+1]; + break scan; + default: + sections[section].push(x); + } + } else { + sections[section].push(x); + } + } + + return sections; +}; + const stringy = x => x instanceof String || typeof x === 'string' || x instanceof LispString; const isTag = x => x instanceof LispSymbol || typeof x === 'number'