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