Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikibooksThe Free Textbook Project
Search

Clojure Programming/Examples/API Examples/Recursion Tools

From Wikibooks, open books for an open world
<Clojure Programming |Examples |API Examples

loop

[edit |edit source]

Seerecur

recur

[edit |edit source]
; compute the factorial of 5, establishes two 'variables' cnt and acc; cnt is decremented every call until it reaches 0; acc stores the result of multiplying each value cnt took(loop [cnt 5,       acc 1]  (if (zero? cnt)    acc    (recur (dec cnt) (* acc cnt))))

lazy-cons

[edit |edit source]
(defn fib-seq []  ((fn rfib [a b]        (lazy-cons a (rfib b (+ a b))))     0 1)) user> (take 20 (fib-seq))(0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181)
Retrieved from "https://en.wikibooks.org/w/index.php?title=Clojure_Programming/Examples/API_Examples/Recursion_Tools&oldid=3230482"
Category:

[8]ページ先頭

©2009-2025 Movatter.jp