Re: create vector from other vector and indices

2018-02-13 Thread Matching Socks
user> (def v [:a :b :c :d])
#'user/v
user> (mapv v [3 1 2 0])
[:d :b :c :a]



-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: create vector from other vector and indices

2018-02-13 Thread Tomasz Sulej
Or even simpler: (map v idx)

On 13 February 2018 at 20:48, Tomasz Sulej  wrote:

> (map #(v %) idx)
>
> or
>
> (map (partial get v) idx))
>
> On 13 February 2018 at 20:10, Andre Bieler 
> wrote:
>
>> Just started with clojure.
>> Lets say I have two vectors, v containing values and another vector idx
>> that contains the indices by which vector v should be ordered (rather a new
>> vector be created, ordered given by idx.
>>
>> (def v [10, 11, 12, 13])
>> (def idx [1 3 0 2])
>>
>> ; goal is a new vector with values [11 13 10 12]
>>
>>
>>
>> I tried combinations of map / apply / nth / get but could not get
>> anything working.
>> Thanks!
>>
>> --
>> 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 unsubscribe from this group and stop receiving emails from it, send an
>> email to clojure+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: create vector from other vector and indices

2018-02-13 Thread Tomasz Sulej
(map #(v %) idx)

or

(map (partial get v) idx))

On 13 February 2018 at 20:10, Andre Bieler  wrote:

> Just started with clojure.
> Lets say I have two vectors, v containing values and another vector idx
> that contains the indices by which vector v should be ordered (rather a new
> vector be created, ordered given by idx.
>
> (def v [10, 11, 12, 13])
> (def idx [1 3 0 2])
>
> ; goal is a new vector with values [11 13 10 12]
>
>
>
> I tried combinations of map / apply / nth / get but could not get anything
> working.
> Thanks!
>
> --
> 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 unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.