From 6a2ae42e5ccee044fbd3ce62cbaa883d4aca5829 Mon Sep 17 00:00:00 2001 From: Fabian Date: Tue, 6 Apr 2021 21:52:26 +0200 Subject: [PATCH] fix defmacro behavior --- impls/sml/step8_macros.sml | 8 ++++---- impls/sml/step9_try.sml | 8 ++++---- impls/sml/stepA_mal.sml | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/impls/sml/step8_macros.sml b/impls/sml/step8_macros.sml index 0077b51528..893bfd59df 100644 --- a/impls/sml/step8_macros.sml +++ b/impls/sml/step8_macros.sml @@ -55,10 +55,10 @@ and expandQuasiquote [LIST ([SYMBOL "unquote", x],_)] = x and quasiFolder (LIST ([SYMBOL "splice-unquote", x],_), acc) = [SYMBOL "concat", x, makeList acc] | quasiFolder (x, acc) = [SYMBOL "cons", expandQuasiquote [x], makeList acc] -and evalDefmacro e [SYMBOL s, LIST ([SYMBOL "fn*", LIST (binds,_), body],_)] = let val m = makeMacro e binds body in (def s m e; m) end - | evalDefmacro e [SYMBOL s, LIST ([SYMBOL "fn*", VECTOR (binds,_), body],_)] = let val m = makeMacro e binds body in (def s m e; m) end - | evalDefmacro _ _ = raise NotApplicable "defmacro! needs a name, a list of bindings, and a body" -and makeMacro e binds body = MACRO (fn (exprs) => eval (bind (interleave binds exprs) (inside e)) body) +and evalDefmacro e [SYMBOL s, ast] = defMacro e s (eval e ast) + | evalDefmacro _ _ = raise NotApplicable "defmacro! needs a name, and a fn*" +and defMacro e s (FN (f,_)) = let val m = MACRO f in (def s m e; m) end + | defMacro _ _ _ = raise NotApplicable "defmacro! needs a name, and a fn*" and expandMacro e [(ast as LIST (SYMBOL s::args, _))] = (case lookup e s of SOME (MACRO m) => m args | _ => ast) | expandMacro _ [ast] = ast diff --git a/impls/sml/step9_try.sml b/impls/sml/step9_try.sml index e6a38a2c80..b3f9f3b259 100644 --- a/impls/sml/step9_try.sml +++ b/impls/sml/step9_try.sml @@ -56,10 +56,10 @@ and expandQuasiquote [LIST ([SYMBOL "unquote", x],_)] = x and quasiFolder (LIST ([SYMBOL "splice-unquote", x],_), acc) = [SYMBOL "concat", x, makeList acc] | quasiFolder (x, acc) = [SYMBOL "cons", expandQuasiquote [x], makeList acc] -and evalDefmacro e [SYMBOL s, LIST ([SYMBOL "fn*", LIST (binds,_), body],_)] = let val m = makeMacro e binds body in (def s m e; m) end - | evalDefmacro e [SYMBOL s, LIST ([SYMBOL "fn*", VECTOR (binds,_), body],_)] = let val m = makeMacro e binds body in (def s m e; m) end - | evalDefmacro _ _ = raise NotApplicable "defmacro! needs a name, a list of bindings, and a body" -and makeMacro e binds body = MACRO (fn (exprs) => eval (bind (interleave binds exprs) (inside e)) body) +and evalDefmacro e [SYMBOL s, ast] = defMacro e s (eval e ast) + | evalDefmacro _ _ = raise NotApplicable "defmacro! needs a name, and a fn*" +and defMacro e s (FN (f,_)) = let val m = MACRO f in (def s m e; m) end + | defMacro _ _ _ = raise NotApplicable "defmacro! needs a name, and a fn*" and expandMacro e [(ast as LIST (SYMBOL s::args, _))] = (case lookup e s of SOME (MACRO m) => m args | _ => ast) | expandMacro _ [ast] = ast diff --git a/impls/sml/stepA_mal.sml b/impls/sml/stepA_mal.sml index 774567db5f..e4c4411a2b 100644 --- a/impls/sml/stepA_mal.sml +++ b/impls/sml/stepA_mal.sml @@ -56,10 +56,10 @@ and expandQuasiquote [LIST ([SYMBOL "unquote", x],_)] = x and quasiFolder (LIST ([SYMBOL "splice-unquote", x],_), acc) = [SYMBOL "concat", x, makeList acc] | quasiFolder (x, acc) = [SYMBOL "cons", expandQuasiquote [x], makeList acc] -and evalDefmacro e [SYMBOL s, LIST ([SYMBOL "fn*", LIST (binds,_), body],_)] = let val m = makeMacro e binds body in (def s m e; m) end - | evalDefmacro e [SYMBOL s, LIST ([SYMBOL "fn*", VECTOR (binds,_), body],_)] = let val m = makeMacro e binds body in (def s m e; m) end - | evalDefmacro _ _ = raise NotApplicable "defmacro! needs a name, a list of bindings, and a body" -and makeMacro e binds body = MACRO (fn (exprs) => eval (bind (interleave binds exprs) (inside e)) body) +and evalDefmacro e [SYMBOL s, ast] = defMacro e s (eval e ast) + | evalDefmacro _ _ = raise NotApplicable "defmacro! needs a name, and a fn*" +and defMacro e s (FN (f,_)) = let val m = MACRO f in (def s m e; m) end + | defMacro _ _ _ = raise NotApplicable "defmacro! needs a name, and a fn*" and expandMacro e [(ast as LIST (SYMBOL s::args, _))] = (case lookup e s of SOME (MACRO m) => m args | _ => ast) | expandMacro _ [ast] = ast