Re:Reflecting on Transducers in Scheme (2023)
by lkuty on Thursday August 22, 2024 @02:50AM
(#41317512)
It is Clojure right? Does it imply a `recur` in the anonymous function? I don't really understand what the code will do since I only saw examples of `loop` with a condition. Why the `fn` ?
[ Parent
| on HN ]
Re:Reflecting on Transducers in Scheme (2023)
by 0x3444ac53 on Monday August 26, 2024 @10:08AM
(#41357270)
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/ [2] http://www.phyast.pitt.edu/~micheles/scheme/scheme5.html#the...