Play with circular refs around closures
This commit is contained in:
parent
f419c390af
commit
959927f7ce
|
@ -405,37 +405,9 @@
|
||||||
|
|
||||||
(def source "
|
(def source "
|
||||||
|
|
||||||
fn swap! (rf, f) -> {
|
let foo = :bar
|
||||||
let val = deref (rf)
|
|
||||||
let new = f (val)
|
|
||||||
set! (rf, new)
|
|
||||||
}
|
|
||||||
|
|
||||||
let counter = {
|
fn foof () -> panic! (:oops)
|
||||||
ref i = 0
|
|
||||||
|
|
||||||
fn next () -> {
|
|
||||||
let n = deref (i)
|
|
||||||
if eq (n, 3)
|
|
||||||
then (:done, nil)
|
|
||||||
else {
|
|
||||||
swap! (i, inc)
|
|
||||||
(:value, n)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ns Counter {next}
|
|
||||||
}
|
|
||||||
|
|
||||||
print (counter :next ())
|
|
||||||
print (counter :next ())
|
|
||||||
print (counter :next ())
|
|
||||||
print (counter :next ())
|
|
||||||
print (counter :next ())
|
|
||||||
|
|
||||||
let foo = nil
|
|
||||||
|
|
||||||
counter
|
|
||||||
|
|
||||||
")
|
")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user