mirror of
https://github.com/carp-lang/Carp.git
synced 2024-09-11 05:25:28 +03:00
43 lines
975 B
Plaintext
43 lines
975 B
Plaintext
(load-and-use Test)
|
|
|
|
(defn recursive [x]
|
|
(if (= x 1)
|
|
x
|
|
(* x (recursive (- x 1)))))
|
|
|
|
(defn recursion-test-1 []
|
|
(recursive 5))
|
|
|
|
;; Problems with recursive calls again, fails to qualify at call site
|
|
(use Float)
|
|
(use Double)
|
|
|
|
(defmodule A
|
|
(defn flurb [x y]
|
|
(if (< x y)
|
|
x
|
|
(+ x (flurb (- x 1) y)))))
|
|
|
|
(defn recursion-test-2 []
|
|
(A.flurb 9 6))
|
|
|
|
;; let bindings may be recursive in static contexts (issue #402)
|
|
(defn letrec-test []
|
|
(let [f (fn [x] (if (= x 1) x (f (dec x))))]
|
|
(f 10)))
|
|
|
|
(deftest test
|
|
(assert-equal test
|
|
120
|
|
(recursion-test-1)
|
|
"Ensure that basic recursion works.")
|
|
(assert-equal test
|
|
35
|
|
(recursion-test-2)
|
|
"Ensure that problem with recursion in modules is resolved.")
|
|
(assert-equal test
|
|
1
|
|
(letrec-test)
|
|
"Let bindings bound to lambdas can call themselves ('let-rec' support)")
|
|
)
|