File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
288291function 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
359364function main ( ) {
360365 console . log ( evalSchemeString ( "(+ (* 2 3) 2)" ) ) ; // Should output 3
You can’t perform that action at this time.
0 commit comments