Re: apply madness

2016-05-12 Thread Mike Rodriguez
Vectors are eager. So they'd need to be finite. Varargs/rest args can be 
infinite lazy sequences. So it is appropriate that they are just generic "seq" 
abstractions instead of something specific (and eager) like a vector. 

-- 
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: apply madness

2016-05-12 Thread hiskennyness


On Thursday, May 12, 2016 at 4:10:39 AM UTC-4, Michael Gardner wrote:
>
> There's no need to avoid `apply` altogether, IMO. You could do something 
> like this: 
>
> (let [raw (list :a 1 :b 2 :c 3)] 
> (into {:raw raw} 
> (filter (comp even? second) 
> (apply hash-map raw 
>

Ah, that comp is nice. I'll use that.
 

>
> BTW, `list` is pretty uncommon. Usually you'd just use a vector literal. 
>

Understood, but I am actually working on a function where the values 
originate as a & rest param. 

Hmm, given the oddness of lists in Clojure, I wonder why those aren't 
vectors.

Thx! -kt

-- 
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: apply madness

2016-05-12 Thread hiskennyness


On Thursday, May 12, 2016 at 3:59:10 AM UTC-4, dennis wrote:
>
> A try:
>
> (let [raw (list  :a 1 :b 2 :c 3)]
>   (->> raw
>(partition 2)
>(filter #(even? (second %)))
>(map vec)
>(into {})
>(merge {:raw raw})))
>
> => {:b 2, :raw (:a 1 :b 2 :c 3)}
>

Brilliant. Actually, I had my own spec wrong. Adjusting for that:

(let [raw (list  :a 1 :b 2 :c 3 :d 42)]
>   (merge {:cz (->> raw
>(partition 2)
>(filter #(even? (second %)))
>(map vec)
>(into {}))}
>  (->> raw
>   (partition 2)
>   (map (fn [[k v]] (vector k (when-not (even? v) v
>   (into {}
> ;; => {:cz {:b 2, :d 42}, :a 1, :b nil, :c 3, :d nil}

 
ie, I want the :cz (formerly :raw) key to hold a selective map of the 
inputs, and then all the inputs as key-values but with some values cleared.

Further repairs welcome.

Thx! -kt

-- 
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: apply madness

2016-05-12 Thread Michael Gardner
There's no need to avoid `apply` altogether, IMO. You could do something like 
this:

(let [raw (list :a 1 :b 2 :c 3)]
(into {:raw raw}
(filter (comp even? second)
(apply hash-map raw

BTW, `list` is pretty uncommon. Usually you'd just use a vector literal.

And this is the right place to ask!

> On May 12, 2016, at 00:46, hiskennyness  wrote:
> 
> This does what I want but feels nooby-ish, as in "in a month I will do this 
> without APPLY":
> 
> (let [raw (list  :a 1 :b 2 :c 3)]
>   (apply assoc {}
>  :raw raw
>   (apply concat
>(filter #(even? (second %))
>(apply hash-map raw)
> ;; => {:raw (:a 1 :b 2 :c 3), :b 2}
> 
> Am I being too hard on myself?
> 
> Meta question: is there a better place to ask such questions?
> 
> -kt
> 
> -- 
> 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: apply madness

2016-05-12 Thread dennis zhuang
A try:

(let [raw (list  :a 1 :b 2 :c 3)]
  (->> raw
   (partition 2)
   (filter #(even? (second %)))
   (map vec)
   (into {})
   (merge {:raw raw})))

=> {:b 2, :raw (:a 1 :b 2 :c 3)}



2016-05-12 15:46 GMT+08:00 hiskennyness :

> This does what I want but feels nooby-ish, as in "in a month I will do
> this without APPLY":
>
> (let [raw (list  :a 1 :b 2 :c 3)]
>>   (apply assoc {}
>>  :raw raw
>>   (apply concat
>>(filter #(even? (second %))
>>(apply hash-map raw)
>> ;; => {:raw (:a 1 :b 2 :c 3), :b 2}
>
>
> Am I being too hard on myself?
>
> Meta question: is there a better place to ask such questions?
>
> -kt
>
> --
> 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.
>



-- 
庄晓丹
Email:killme2...@gmail.com xzhu...@avos.com
Site:   http://fnil.net
Twitter:  @killme2008

-- 
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.


apply madness

2016-05-12 Thread hiskennyness
This does what I want but feels nooby-ish, as in "in a month I will do this 
without APPLY":

(let [raw (list  :a 1 :b 2 :c 3)]
>   (apply assoc {}
>  :raw raw
>   (apply concat
>(filter #(even? (second %))
>(apply hash-map raw)
> ;; => {:raw (:a 1 :b 2 :c 3), :b 2}


Am I being too hard on myself?

Meta question: is there a better place to ask such questions?

-kt

-- 
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.