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 e2fe85e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions impls/scala/step8_macros.scala
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ object step8_macros {
ast = quasiquote(a1) // continue loop (TCO)
}
case Symbol("defmacro!") :: a1 :: a2 :: Nil => {
val f = EVAL(a2, env)
f.asInstanceOf[MalFunction].ismacro = true
val f = EVAL(a2, env).asInstanceOf[MalFunction].clone()
f.ismacro = true
return env.set(a1.asInstanceOf[Symbol], f)
}
case Symbol("do") :: rest => {
Expand Down
4 changes: 2 additions & 2 deletions impls/scala/step9_try.scala
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ object step9_try {
ast = quasiquote(a1) // continue loop (TCO)
}
case Symbol("defmacro!") :: a1 :: a2 :: Nil => {
val f = EVAL(a2, env)
f.asInstanceOf[MalFunction].ismacro = true
val f = EVAL(a2, env).asInstanceOf[MalFunction].clone()
f.ismacro = true
return env.set(a1.asInstanceOf[Symbol], f)
}
case Symbol("try*") :: a1 :: rest => {
Expand Down
4 changes: 2 additions & 2 deletions impls/scala/stepA_mal.scala
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ object stepA_mal {
ast = quasiquote(a1) // continue loop (TCO)
}
case Symbol("defmacro!") :: a1 :: a2 :: Nil => {
val f = EVAL(a2, env)
f.asInstanceOf[MalFunction].ismacro = true
val f = EVAL(a2, env).asInstanceOf[MalFunction].clone()
f.ismacro = true
return env.set(a1.asInstanceOf[Symbol], f)
}
case Symbol("try*") :: a1 :: rest => {
Expand Down

0 comments on commit e2fe85e

Please sign in to comment.