Greatest common divisor: Difference between revisions

Content added Content deleted
Line 402: Line 402:


<lang lisp>(defn gcd
<lang lisp>(defn gcd
"(gcd a b) computes the greatest common divisor of a and b."
"(gcd a b) computes the greatest common divisor of a and b."
[a b]
[a b]
(if (zero? b)
(if (zero? b)
a
a
(recur b (mod a b)))) ; This is (gcd b (mod a b)), but with explicit tail call optimization.</lang>
(recur b (mod a b))))</lang>

That <code>recur</code> call is the same as <code>(gcd b (mod a b))</code>, but makes use of Clojure's explicit tail call optimization.


=={{header|COBOL}}==
=={{header|COBOL}}==