On Oct 29, 5:40 am, David Sletten <da...@bosatsu.net> wrote:

> You could just bind another local variable in the loop form:
> (loop [ps pairs
>        ret {}
>        ffps (ffirst ps)]
>   (cond (empty? ps) ret
>         (some-test ffps) (recur (rest ps) (add-to-result ret ffps) (ffirst 
> (rest ps)))
>         :true (recur (rest ps) (do-sth-else ret ffps) (ffirst (rest ps)))) )

In this case you have to pass one more parameter to each loop
iteration, and since you actually don't need this param, that breaks
loop's semantics.
Though, I haven't thought about it before, so I will give it a try.

> But you probably want to use 'reduce' instead of 'loop' anyway:
> (reduce (fn [ret [key val]] (if (some-test key) (add-to-result ret key) 
> (do-sth-else ret key))) {} pairs)

Yeah, in 90-95% I use reduce. But in 5-10% function cannot be written
with it, for example, when it uses true recursion, not tail call, so I
showed only very general case I have in my code frequently.

> BTW, do you really mean to call 'add-to-result' and 'do-sth-else' with a map 
> and a key but no value?

Again, just general case. But thank you for caring :)

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to