flan/test/programs/fn-dev-escape.flan

9 lines
451 B
Plaintext

;; [store] only calls what it is handed, so in a release build [go]'s closure
;; stays on go's frame. In a dev build [store] can be redefined to keep it —
;; (set kept (Some f)) — and only [store] is recompiled, so [go] must already
;; have made its closure on the collector's heap.
(defonce kept (Option (Fn [i64] i64)))
(defn store [f (Fn [i64] i64)] () (println (f 0)))
(defn go [n i64] () (store (fn [x] (+ x n))))
(defn main [] i32 (go 5) 0)