Skip to content

Commit

Permalink
scala: prevent defmacro! from mutating its argument
Browse files Browse the repository at this point in the history
  • Loading branch information
asarhaddon committed Oct 10, 2024
1 parent 17193d3 commit 5064a79
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion impls/scala/step8_macros.scala
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ object step8_macros {
ast = quasiquote(a1) // continue loop (TCO)
}
case Symbol("defmacro!") :: a1 :: a2 :: Nil => {
val f = EVAL(a2, env)
val f = EVAL(a2, env).clone()
f.asInstanceOf[MalFunction].ismacro = true
return env.set(a1.asInstanceOf[Symbol], f)
}
Expand Down
2 changes: 1 addition & 1 deletion impls/scala/step9_try.scala
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ object step9_try {
ast = quasiquote(a1) // continue loop (TCO)
}
case Symbol("defmacro!") :: a1 :: a2 :: Nil => {
val f = EVAL(a2, env)
val f = EVAL(a2, env).clone()
f.asInstanceOf[MalFunction].ismacro = true
return env.set(a1.asInstanceOf[Symbol], f)
}
Expand Down
2 changes: 1 addition & 1 deletion impls/scala/stepA_mal.scala
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ object stepA_mal {
ast = quasiquote(a1) // continue loop (TCO)
}
case Symbol("defmacro!") :: a1 :: a2 :: Nil => {
val f = EVAL(a2, env)
val f = EVAL(a2, env).clone()
f.asInstanceOf[MalFunction].ismacro = true
return env.set(a1.asInstanceOf[Symbol], f)
}
Expand Down

0 comments on commit 5064a79

Please sign in to comment.