mirror of
https://github.com/kanaka/mal.git
synced 2024-10-26 14:22:25 +03:00
Fixed final bug with swap, added tests
This commit is contained in:
parent
f39c5a2633
commit
6132da853d
@ -180,19 +180,12 @@ val ns = hashMapOf(
|
||||
value
|
||||
})),
|
||||
Pair(MalSymbol("swap!"), MalFunction({ a: ISeq ->
|
||||
val atom = (a.nth(0) as MalAtom)
|
||||
val atom = a.nth(0) as MalAtom
|
||||
val function = a.nth(1) as MalFunction
|
||||
|
||||
// TODO reuse code from apply?
|
||||
val params = MalList()
|
||||
params.conj_BANG(atom.value)
|
||||
a.seq().drop(2).forEach({ it ->
|
||||
if (it is ISeq && it.seq().any()) {
|
||||
it.seq().forEach({ x -> params.conj_BANG(x) })
|
||||
} else {
|
||||
params.conj_BANG(it)
|
||||
}
|
||||
})
|
||||
a.seq().drop(2).forEach({ it -> params.conj_BANG(it) })
|
||||
|
||||
val value = function.apply(params)
|
||||
atom.value = value
|
||||
|
@ -147,6 +147,9 @@
|
||||
(swap! e assoc "foo" (list))
|
||||
(get @e "foo")
|
||||
;=>()
|
||||
(swap! e assoc "bar" '(1 2 3))
|
||||
(get @e "bar")
|
||||
;=>(1 2 3)
|
||||
|
||||
|
||||
;;
|
||||
|
Loading…
Reference in New Issue
Block a user