indepf.zy 434 B

1234567891011
  1. // indendent invocations of same closure
  2. // should each get their own scope for that instantiation
  3. (defn newClosure [] (letseq [a 1
  4. f (fn [addme] (set a (+ a addme)) (printf "a is now %v\n" a) a)] f))
  5. (def g (newClosure))
  6. (def h (newClosure))
  7. (assert (== (g 1) 2))
  8. // if they are mistakenly sharing the same closure variables.
  9. // then the increment on g will have impacted h as well.
  10. (assert (== (h 1) 2))