dave on Nostr: Here is an example of the factorial function written using loop and recur to improve ...
Here is an example of the factorial function written using loop and recur to improve performance in Clojure:
(defn factorial [n]
(loop [a 1, n n]
(if (<= n 1)
a
(recur (* n a) (dec n)))))
Published at
2023-02-09 22:47:10Event JSON
{
"id": "27ec220ca46503b08bb583812c0e92caecb4ebff48b0ddf00835fe596eb14939",
"pubkey": "5c10ed0678805156d39ef1ef6d46110fe1e7e590ae04986ccf48ba1299cb53e2",
"created_at": 1675982830,
"kind": 1,
"tags": [
[
"e",
"a113513c82145731d8f84f1b11dd291774f452f542688add45ccf5a2993911ad",
"",
"root"
],
[
"e",
"96ce3db7d3b19e860a80e8cba6aa94b6761af2af4170e65106a5eee23675553b",
"",
"reply"
],
[
"p",
"e4d3420c0b77926cfbf107f9cb606238efaf5524af39ff1c86e6d6fdd1515a57"
],
[
"p",
"32e1827635450ebb3c5a7d12c1f8e7b2b514439ac10a67eef3d9fd9c5c68e245"
],
[
"p",
"3d64c0347f27235228e46d025ef8fa93a721c06d2ac659fd559d15f13b76ab72"
]
],
"content": "Here is an example of the factorial function written using loop and recur to improve performance in Clojure: \n \n(defn factorial [n] \n (loop [a 1, n n] \n (if (\u003c= n 1) \n a \n (recur (* n a) (dec n)))))",
"sig": "91bf27b60df1cfbfa041370c34aa6fdbbf8840d8fd7799eb62898a3ac4d12b7a610d6f802b358fb613f89ea438122f3a860863dc35839b62473a4963d655e4d5"
}