Skip to content

Commit eccffcb

Browse files
committed
Refactor expand()
1 parent 43d04e8 commit eccffcb

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

encoding/generic.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -150,35 +150,35 @@ function alpha(obj, bv, lvl)
150150

151151
function expand(dict)
152152
{
153-
const macros = dict.macros;
154-
const mlen = macros.length;
155-
let term = dict.term;
156-
let fv = getfv(term);
157-
158-
for (let i = 0; i < mlen; i++) {
159-
const macro = macros[i];
153+
const orig = dict.term;
154+
const term = dict.macros.reduce((acc, macro) => {
155+
const fv = acc.fv;
160156
const id = macro.id;
161157
const def = macro.def;
162158

163159
if (!fv.has(id))
164-
continue;
160+
return acc;
165161

166162
fv.delete(id);
167163

168164
getfv(def).forEach(atom => {
169165
fv.add(atom);
170166
});
171167

172-
term = {
168+
acc.term = {
173169
node: "appl",
174170
left: {
175171
node: "abst",
176172
var: id,
177-
body: term
173+
body: acc.term
178174
},
179175
right: def
180176
};
181-
}
177+
return acc;
178+
}, {
179+
term: orig,
180+
fv: getfv(orig)
181+
}).term;
182182

183183
dict.expanded = term;
184184
lastwire = 0;

0 commit comments

Comments
 (0)