3 ms·
I think what the OP meant about nested loops was that you can't directly write an inner loop that conditionally continues with the outer loop. In Scheme you'd w
by abecedarius 6y ago
I think what the OP meant about nested loops was that you can't directly write an inner loop that conditionally continues with the outer loop. In Scheme you'd write a named LET inside a named LET, with the inner one invoking the outer in a branch of an IF. With Clojure's loop/recur, as I understand it, you'd have to make the inner loop return a flag for the outer loop to test again about whether to recur, because the only construct you have for continuing a loop is 'recur'.
This is not a rare situation. Am I missing something about how Clojure does it?
My Lisp dialect (Cant) has a construct like the named LET, but with the name being optional (defaulting to 'loop'). This makes simple loops as concise as Clojure's, and fancier ones as flexible as Scheme's.
- didibus 6y agoYou got the right idea, but in my three years of using Clojure professionally I never ounce needed this, so I feel at least in some cases like mine, this is a pretty rare situation.
- dkersten 6y agoIn my ten years of Clojure, half of them professionally, I can probably count the amount of times I've used recur (outside of playing around) on my fingers. I typically don't need to use it because the sequence functions provide a better, higher level alternative. I see recur as quite a low level building block and the last thing I'll reach for. I'm pretty sure I've never used a nested recur.