Implemented closures

This commit is contained in:
Nathan Braswell
2020-04-19 21:52:21 -04:00
parent dff7306cc3
commit b505c021f2
2 changed files with 148 additions and 13 deletions

9
bf.kp
View File

@@ -69,7 +69,8 @@
;(def! other 12)
;(def! main (fn* [] (+ other 4)))
(def! fact (fn* [n] (if (<= n 1) 1 (* (fact (- n 1)) n))))
(def! main (fn* [] (let* (to_ret (fact 5))
(do (println to_ret)
to_ret))))
;(def! fact (fn* [n] (if (<= n 1) 1 (* (fact (- n 1)) n))))
;(def! main (fn* [] (let* (to_ret (fact 5)) (do (println to_ret) to_ret))))
(def! ret_with_call (fn* [n] (fn* [x] (+ n x))))
(def! main (fn* [] ((ret_with_call 3) 5)))