Skip to content

Commit 71978d9

Browse files
fix step8 macro
1 parent 3d9bf79 commit 71978d9

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

impls/lean/LeanMal/step8_macros.lean

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ mutual
134134
| _ => throw (IO.userError s!"def! unexpected token, expected: symbol")
135135

136136
partial def evalDefMacro (env: Env) (args : List Types) : IO (Env × Types) := do
137-
if args.length < 2 then throw (IO.userError "def! unexpected syntax")
137+
if args.length < 2 then throw (IO.userError "defmacro! unexpected syntax")
138138
else
139139
let key := args[0]!
140140
let body := args[1]!
@@ -148,8 +148,9 @@ mutual
148148
let refResult := newEnv.add (KeyType.strKey v) env.getLevel value
149149
return (refResult, value)
150150
| Fun.userDefined fref params body =>
151-
let refResult := newEnv.add (KeyType.strKey v) env.getLevel (Types.funcVal (Fun.macroFn fref params body))
152-
return (refResult, value)
151+
let res := (Types.funcVal (Fun.macroFn fref params body))
152+
let refResult := newEnv.add (KeyType.strKey v) env.getLevel res
153+
return (refResult, res)
153154
| _ => throw (IO.userError s!"defmacro!: unexpected builtin function")
154155
| x => throw (IO.userError s!"unexpected token type: {x.toString true}, expected: function")
155156
| _ => throw (IO.userError s!"def! unexpected token, expected: symbol")
@@ -308,6 +309,17 @@ mutual
308309
| Types.atomVal _ => match name with
309310
| "atom?" => return (env, Types.boolVal true)
310311
| _ => return (env, Types.boolVal false)
312+
| Types.funcVal func =>
313+
match name with
314+
| "fn?" => match func with
315+
| Fun.builtin _ => return (env, Types.boolVal true)
316+
| Fun.userDefined _ _ _ => return (env, Types.boolVal true)
317+
| Fun.macroFn _ _ _ => return (env, Types.boolVal false)
318+
| "macro?" => match func with
319+
| Fun.builtin _ => return (env, Types.boolVal false)
320+
| Fun.userDefined _ _ _ => return (env, Types.boolVal false)
321+
| Fun.macroFn _ _ _ => return (env, Types.boolVal true)
322+
| _ => return (env, Types.boolVal false)
311323
| _ => return (env, Types.boolVal false)
312324
| _ => throw (IO.userError s!"'{name}' not found")
313325

0 commit comments

Comments
 (0)