Map vs For

閲覧: 943 回
最初の未読メッセージにスキップ

Oleg

未読、
2010/06/28 14:48:592010/06/28
To: Clojure
I will show example based on hiccup library:

For version: [:ol (for [x coll] [:li x])]
Map version: [:ol (map (fn [x] [:li x]) coll)]

What's the difference between them? What is better for performance?

Cheers, Oleg

Moritz Ulrich

未読、
2010/06/28 15:26:082010/06/28
To: clo...@googlegroups.com
I'd prefer the for-version in this case.

You see the differences if you try `for` and `map` with multiple collections.
`for` is a traditional list-comprehension (1).
`map` iterates over many sequences at once, `for` does "nested" iteration.

(1): http://en.wikipedia.org/wiki/List_comprehension#Clojure

> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clo...@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+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

--
Moritz Ulrich
Programmer, Student, Almost normal Guy

http://www.google.com/profiles/ulrich.moritz

ataggart

未読、
2010/06/28 21:20:412010/06/28
To: Clojure
I prefer map for turning one sequence into another sequence of equal
length. I generally only use for when I need a cartesian product of
multiple sequences, or am going to leverage :let, :when, or :while in
the binding.
全員に返信
投稿者に返信
転送
新着メール 0 件