Re: Loop and Recur

2010-06-07 Thread Bruce Durling
Melkel, On Mon, Jun 7, 2010 at 15:55, Meikel Brandmeyer wrote: > Hi, > > On Jun 7, 4:25 pm, Bruce Durling wrote: > >> I have no problem with calling seq, I just don't understand why I need to. > > Because the initial collections might be empty. > > (my-zipmap [] []) => {} I see, where as the ve

Re: Loop and Recur

2010-06-07 Thread Joost
On Jun 7, 1:49 pm, Bruce Durling wrote: > Steve and Jon, > > On Mon, Jun 7, 2010 at 12:43, Steve Purcell wrote: > > Empty seqs are logically true, so your "if" condition is always true. > > I was looking at that today too. I did (> 0 (count my-list)) in my if > statement to fix it. Be aware that

Re: Loop and Recur

2010-06-07 Thread Meikel Brandmeyer
Hi, On Jun 7, 4:25 pm, Bruce Durling wrote: > I have no problem with calling seq, I just don't understand why I need to. Because the initial collections might be empty. (my-zipmap [] []) => {} Sincerely Meikel -- You received this message because you are subscribed to the Google Groups "Clo

Re: Loop and Recur

2010-06-07 Thread Bruce Durling
Patrik, On Mon, Jun 7, 2010 at 13:00, patrik karlin wrote: > calling rest dosent give you nil it gives you an empty seq > so the if statment never fails > > try > > (defn my-zipmap [keys vals] >  (loop [my-map {} >        [kf & kr] (seq keys) >        [vf & vr] (seq vals)] >   (if (and kf vf) >  

Re: Loop and Recur

2010-06-07 Thread Bruce Durling
Stu, On Mon, Jun 7, 2010 at 13:08, Stuart Halloway wrote: > That doc page used pre-1.0 Clojure code, which, as you saw, doesn't work. > Thanks for the catch, I have fixed the docs on the site. Thanks. I think my mistake was mixing up rest (which always returns a sequence even if empty) and next

Re: Loop and Recur

2010-06-07 Thread Stuart Halloway
Hi Bruce, That doc page used pre-1.0 Clojure code, which, as you saw, doesn't work. Thanks for the catch, I have fixed the docs on the site. Stu > Steve and Jon, > > On Mon, Jun 7, 2010 at 12:43, Steve Purcell wrote: >> Empty seqs are logically true, so your "if" condition is always true. >>

Re: Loop and Recur

2010-06-07 Thread patrik karlin
So its the calling of first that gives you nil here is some example code user=> (rest '(2)) () user=> (rest '()) () user=> (first '()) nil 2010/6/7 patrik karlin : > calling rest dosent give you nil it gives you an empty seq > so the if statment never fails > > try > > (defn my-zipmap [keys val

Re: Loop and Recur

2010-06-07 Thread patrik karlin
calling rest dosent give you nil it gives you an empty seq so the if statment never fails try (defn my-zipmap [keys vals] (loop [my-map {} [kf & kr] (seq keys) [vf & vr] (seq vals)] (if (and kf vf) (recur (assoc my-map kf vf) kr vr) my-map))) 2010/6/6 Jon Seltzer

Re: Loop and Recur

2010-06-07 Thread Bruce Durling
Steve, On Mon, Jun 7, 2010 at 12:48, Steve Purcell wrote: > On 7 Jun 2010, at 12:43, Steve Purcell wrote: > >> Empty seqs are logically true, so your "if" condition is always true. > > > Apologies; I'm talking rubbish: > > user=> (if '() (println "truthy")) > truthy > nil > user=> (if (seq '()) (

Re: Loop and Recur

2010-06-07 Thread Bruce Durling
Steve and Jon, On Mon, Jun 7, 2010 at 12:43, Steve Purcell wrote: > Empty seqs are logically true, so your "if" condition is always true. > I was looking at that today too. I did (> 0 (count my-list)) in my if statement to fix it. Is the Recursive Looping example on http://clojure.org/function

Re: Loop and Recur

2010-06-07 Thread Steve Purcell
On 7 Jun 2010, at 12:43, Steve Purcell wrote: > Empty seqs are logically true, so your "if" condition is always true. Apologies; I'm talking rubbish: user=> (if '() (println "truthy")) truthy nil user=> (if (seq '()) (println "truthy")) nil -- You received this message because you are subscr

Re: Loop and Recur

2010-06-07 Thread Steve Purcell
On 6 Jun 2010, at 15:30, Jon Seltzer wrote: > I'm still learning Clojure and doing so by reading everything on > clojure.org. I ran across this example in the Functional Programming > section: > > (defn my-zipmap [keys vals] > (loop [my-map {} > my-keys (seq keys) > my-vals (seq

Loop and Recur

2010-06-07 Thread Jon Seltzer
I'm still learning Clojure and doing so by reading everything on clojure.org. I ran across this example in the Functional Programming section: (defn my-zipmap [keys vals] (loop [my-map {} my-keys (seq keys) my-vals (seq vals)] (if (and my-keys my-vals) (recur (assoc