Hi BG and Neale,

Thanks for taking the time to answer my question. Now I can read that code
thanks to you.

These was key to understand what was going on:

*(apply + 1 2 '( 3 4))
 which is equivalent to -* *
(+ 1 2 3 4)*

and

*so the final result is equivalent to*

*((list (first '(1 2)) (first (3 4))) (list (second '(1 2)) (second '(3
4))) *
I knew about map with multiple collections but somehow when combined with
the apply I was unable to read that code, I was lost with to many
parameters to the apply function...

Thanks once again for helping me out with this
Erlis

On Tue, Sep 11, 2012 at 6:19 PM, Neale Swinnerton <ne...@isismanor.com>wrote:

> > > (apply map list (partition 2 [ 1 2 3 4 5 ])) => ((1 3) (2 4))
> >
> > This is equivalent to -
> >
> > (map list '(1 2) '(2 4) '(5))
>
> Actually, since no pad collection is supplied,  the partition call returns
>
> ((1 2) (3 4))
>
> So the apply variant (unwrapping the collection) is equivalent to....
>
> (map list '(1 2) '(3 4))
>
> Which is different to the plain call which looks like:
>
> (map list '((1 2) (3 4)))
>
> Now, map has a cool feature when called with multiple collections. From
> the docs ....
>
> map
> (map f coll)
> (map f c1 c2)
> (map f c1 c2 c3)
> (map f c1 c2 c3 & colls)
>
> Returns a lazy sequence consisting of the result of applying f to the
> set of first items of each coll, followed by applying f to the set
> of second items in each coll, until any one of the colls is
> exhausted. Any remaining items in other colls are ignored. Function
> f should accept number-of-colls arguments.
>
> so the final result is equivalent to
>
> ((list (first '(1 2)) (first (3 4))) (list (second '(1 2)) (second '(3
> 4)))
>
> Which becomes:
>
> ((list 1 3) (list 2 4))
>
> Which is the result you see - hope that helps
>
> Neale
> {t: @sw1nn, w:sw1nn.com <http://sw1nn.com.com>}
>
> --
> 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 - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
>

-- 
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 - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to