noob q: infinite loop recur

2010-08-10 Thread chepprey
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?

Re: noob q: infinite loop recur

2010-08-10 Thread Laurent PETIT
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

Re: noob q: infinite loop recur

2010-08-10 Thread Meikel Brandmeyer
Hi, On Aug 10, 3:13 pm, Laurent PETIT laurent.pe...@gmail.com wrote: 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. I generally use next when I know that I need to realise anyway

Re: noob q: infinite loop recur

2010-08-10 Thread David Sletten
On Aug 9, 2010, at 11:52 PM, chepprey wrote: (defn show [words] (let [word (first words)] (do (println word) (if (nil? word) (println DONE) (recur (rest words))

Re: noob q: infinite loop recur

2010-08-10 Thread Meikel Brandmeyer
Hi, On Aug 10, 3:48 pm, David Sletten da...@bosatsu.net wrote: Notice how Clojure returns two different values here. Other Lisps (such as Common Lisp) define FIRST/REST of the empty list to both be NIL (i.e., the empty list itself). So it is common in other Lisps to test for the end of a

Re: noob q: infinite loop recur

2010-08-10 Thread chepprey
To all - THANKS (especially David Sletten) for the excellent responses! Very helpful. -- 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 -