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
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 vals)]
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 subscribed to
Steve and Jon,
On Mon, Jun 7, 2010 at 12:43, Steve Purcell st...@sanityinc.com 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
Steve,
On Mon, Jun 7, 2010 at 12:48, Steve Purcell st...@sanityinc.com 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 '())
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
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 patrik.kar...@gmail.com:
calling rest dosent give you nil it gives you an empty seq
so the if statment never fails
try
(defn
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 st...@sanityinc.com wrote:
Empty seqs are logically true, so your if condition is
Stu,
On Mon, Jun 7, 2010 at 13:08, Stuart Halloway stuart.hallo...@gmail.com 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
On Jun 7, 1:49 pm, Bruce Durling b...@otfrom.com wrote:
Steve and Jon,
On Mon, Jun 7, 2010 at 12:43, Steve Purcell st...@sanityinc.com 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
Melkel,
On Mon, Jun 7, 2010 at 15:55, Meikel Brandmeyer m...@kotka.de wrote:
Hi,
On Jun 7, 4:25 pm, Bruce Durling b...@otfrom.com 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
11 matches
Mail list logo