Patrik,
On Mon, Jun 7, 2010 at 13:00, patrik karlin <[email protected]> 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)
> (recur (assoc my-map kf vf) kr vr)
> my-map)))
So the important bit is wrapping the keys and vals in a sequence. At
my swank prompt in clojure 1.2 I get
user> (seq '())
nil
user> (next '())
nil
user> (rest '())
()
So seq and next return nil if called on an empty collection. What I
don't understand is why seq is being called on something that is
already a collection.
This code seems to work too and doesn't call seq.
(defn my-zipmap [keys vals]
(loop [my-map {}
k keys
v vals]
(if (and k v)
(recur (assoc my-map (first k) (first v))
(next k)
(next v))
my-map)))
I have no problem with calling seq, I just don't understand why I need to.
cheers,
Bruce
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en