valeri/test/function.vli

36 lines
544 B
Text
Raw Normal View History

;; -*- mode: lisp; -*-
(fn fact (n)
(if (<= n 0)
1
(* n (fact (- n 1)))))
(assert (= (fact 12) 479001600))
(let ((square (fn (x) (* x x))))
(assert (= (square 4) 16))
)
;; Closures should work at least across one scope
(let ((x 42))
(assert (= ((fn (y) (+ x y) 1)
43)))
)
;; Closures should work across multiple scopes
(let ((x 42))
(assert (=
(((fn (y)
(fn () (+ x y)))
1))
43))
)
(let ((x 42))
(fn foo() x)
)
(assert (= (foo) 42))