fakir/examples/closure.fk

46 lines
590 B
Plaintext
Raw Normal View History

2023-09-22 20:04:57 +00:00
($ mk-counter
(-> (init)
($ counter (- init 1))
(-> ()
(! counter (+ counter 1))
counter)))
($ a (mk-counter 5))
($ b (mk-counter 32))
(assert= 5 (a))
(assert= 32 (b))
(assert= 33 (b))
(assert= 6 (a))
(assert= 7 (a))
(assert= 34 (b))
($ (c) 42)
($ (d)
(+ (c) 1))
(assert= 43 (d))
($ hello 34)
($ (i)
($ (j)
($ (k)
(println hello))))
(((i)))
($ @m './mod2')
($ (u)
($ (v)
($ (w)
(assert= 42 m::var)
(assert= 14 (m::fun 7))
259 )))
(assert= 42 ((-> () m::var)))
(assert= 259 (((u))))