3 ms·
it's a scheme thing, not necessarily clojure. (def foo '(1 2 3 4 5 6 7 8 9 10)) (let [loop (fn [x] (if (empty? x) '() (cons
by 0x3444ac53 2y ago
it's a scheme thing, not necessarily clojure.
(def foo '(1 2 3 4 5 6 7 8 9 10))
(let [loop (fn [x]
(if (empty? x) '()
(cons (+ 1 (car x)) (loop (cdr x)))))]
(loop foo)) ;=> (2 3 4 5 6 7 8 9 10 11)
It's just a way of simulating a loop with a recursive anonymous function within a let binding. As far as the fn, it's because lately I've been programming quite a lot in fennel[1] that borrows syntax from clojure. Although it should be said that this also isn't valid fennel code unless it's in a macro, but that's beside the pont.
the (let [loop (fn ...)]) is something I learned here[2]
[1] https://fennel-lang.org/ https://fennel-lang.org/
[2] http://www.phyast.pitt.edu/~micheles/scheme/scheme5.html#there-are-no-for-loops-in-scheme http://www.phyast.pitt.edu/~micheles/scheme/scheme5.html#the...