Skip to content

Commit 87f609c

Browse files
committed
most things work scheme js
1 parent 9a8b262 commit 87f609c

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

ports-js/scheme.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,12 @@ function expand(x, toplevel = false) {
203203
require(x, x.length === 2);
204204
return expand_quasiquote(x[1]);
205205
} else if (typeof x[0] === 'symbol' && macro_table.has(x[0])) {
206-
return expand(macro_table.get(x[0]).call(...x.slice(1)), toplevel); // (m arg...)
206+
var proc = macro_table.get(x[0])
207+
if (proc instanceof Procedure) {
208+
return expand(proc.call(...x.slice(1)), toplevel); // (m arg...)
209+
} else {
210+
return expand(proc(...x.slice(1)), toplevel); // (m arg...)
211+
}
207212
} else { // => macroexpand if m is a macro
208213
return x.map(ea => expand(ea)); // (f arg...) => expand each
209214
}
@@ -282,8 +287,6 @@ function addGlobals(env) {
282287
return env;
283288
}
284289

285-
addGlobals(globalEnv);
286-
287290
// Evaluation function
288291
function evaluate(x, env = globalEnv) {
289292
while (true) {
@@ -355,6 +358,8 @@ export function evalScheme(list) {
355358
return evaluate(expand(list, true));
356359
}
357360

361+
addGlobals(globalEnv);
362+
358363

359364
function main() {
360365
console.log(evalSchemeString("(+ (* 2 3) 2)")); // Should output 3

0 commit comments

Comments
 (0)