Hi,

if you recur with "rest", you should use (empty?), if you recur with next,
you can use (nil?)

next is more eager than rest, but in a loop scenario, I generally use next
since we'll test for nil in order to know whether to continue to iterate or
not.

2010/8/10 chepprey <jmess...@cranksters.org>

> Dipping my toes for the first time in Clojure.  Having some beginner
> troubles.
>
> THIS code works (on the repl, if that matters... also, Clojure 1.2):
>
> (defn show [words]
>        (let [word (first words)]
>                (do
>                        (println word)
>                        (if (nil? word)
>                                (println "DONE")
>                                (recur (rest words))))))
>
> (show '("some" "sample" "words"))
>
> ... this shows the 3 words, then DONE, and terminates.
>
> But originally, I was trying to use loop/recur.  If I replace the
> "let" with "loop" in the above code, it goes into an infinite loop.  I
> assume there's something different in the scoping/binding rules with
> loop, but I can't find a good explanation of what.  I read in
> "Programming Clojure", regarding loop, that it "...works like let,
> establishing bindings and then evaluating exprs..."
>
> Noob Q#2: should I (and when) use "next" instead of "rest" on a seq?
> a lazy seq?
>
> Thanks!
>
> --
> 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<clojure%2bunsubscr...@googlegroups.com>
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

-- 
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