ADD: nested function.

ADD: function can returns other function or lambda.
main
bog 2023-09-12 11:16:05 +02:00
parent ea5991732c
commit 29fded5cb9
1 changed files with 21 additions and 0 deletions

View File

@ -29,3 +29,24 @@
(if (eq? x 0) (if (eq? x 0)
1 1
(* x (self (- x 1))))) 6)) (* x (self (- x 1))))) 6))
;; inner functions
($ (f n)
($ (inner n) (+ n 1))
(inner (inner n)))
(assert-eq? 3 (f 1))
;; return function
($ (g)
($ (inner n) (* 7 n))
inner)
(assert-eq? 42 ( (g) 6 ))
;; return lambda
($ (h)
(-> (n)
(* 3 (- n 2))))
(assert-eq? 15 ( (h) 7 ))