Not sure if the OP will see this thread because I was the one that dig it 
up since I had a similar problem :)

user=> (apply pr-str (interpose \, (list "jim" "jon" "chris")))
> "\"jim\" \\, \"jon\" \\, \"chris\""


I am not sure if that's correct. I think that the final string should look 
like this:

"\"jim\",\"jon\",\"chris\""


Ryan 

On Wednesday, April 3, 2013 2:33:22 AM UTC+3, Jim foo.bar wrote:
>
>  I'm sorry, I've not followed this discussion - what is wrong with 
>
> user=>(apply str (interpose \, (list 1 2 3 4 5)))
> "1,2,3,4,5"
>
> the problem is strings where you want to preserve each string...you can 
> special case that and avoid the (apply str...) bit..
> user=> (interpose \, (list "jim" "jon" "chris"))
> ("jim" \, "jon" \, "chris")...
>
> once you have that pr-str is your friend...
>
> =>(apply pr-str (interpose \, (list "jim" "jon" "chris")))
> "\"jim\" \\, \"he\" \\, \"dan\""  
>
> Is this not exactly what you want and fast enough?
>
> Jim
>
>
> On 02/04/13 23:49, Max Penet wrote:
>  
> Using a protocol fn to do the encoding of the values according to the 
> rules you set per type then using clj.string/join should be quite fast and 
> not so horrible.  
>
>  
> On Thursday, October 28, 2010 2:18:08 AM UTC+2, andrei wrote: 
>>
>> Hi all, 
>>
>> I work with a database and need a function, that will convert Clojure 
>> sequence to a string with a comma-separated elements. E.g., 
>>
>>   (comma-separated (list 1 2 3 4 5))  ==>  "1, 2, 3, 4, 5" 
>>
>> It must work with any data type - ints, strings, other lists, etc. 
>> E.g. for a list of strings it must generate 
>>
>>   (comma-separated (list "1" "2" "3" "4" "5"))  ==>  "\"1\", \"2\", 
>> \"3\", \"4\", \"5\"" 
>>
>> I tried `cl-format` function from clojure.contrib.pprint package: 
>>
>>   (cl-format nil "~{~S~^, ~}" lst) 
>>
>> It works fine, but is too slow. Next, I tried such function: 
>>
>>   (defn comma-separated [s] 
>>       (if (= (type (first s)) String) 
>>          (chop (chop (chop (str "\" (apply str (interleave s 
>> (repeatedly (fn [] "\", \""))))))) 
>>          (chop (chop (apply str (interleave s (repeatedly (fn [] ", 
>> "))))))))) 
>>
>> This one works much faster (~20 times), but it is ugly and still 
>> doesn't cover all cases. 
>>
>> So, what is the fastest way to generate such list?
>
>  -- 
> -- 
> 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 <javascript:>
> 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 <javascript:>
> 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+u...@googlegroups.com <javascript:>.
> For more options, visit https://groups.google.com/groups/opt_out.
>  
>  
>
>
>  

-- 
-- 
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/groups/opt_out.


Reply via email to