I am curious, what data store are you interacting with?
On Wednesday, April 3, 2013 2:01:33 PM UTC+2, Ryan wrote:
>
> Most SQL Database support array types natively
>
>
> If you are using MySQL unfortunately there isn't and the OP (including
> myself) probably needs this because his RDBMS does not support the array
> type.
>
> On Wednesday, April 3, 2013 2:47:45 PM UTC+3, Thomas Heller wrote:
>>
>> My Question would be: why are you trying to do this? You mentioned you
>> are working with a database, I assume that means SQL (as almost all NoSQL
>> Databases support some kind of JSON which doesnt require your
>> "workarround"). Most SQL Database support array types natively, while
>> support might be a little itchy (at least in JDBC terms) it still beats a
>> comma seperated list.
>>
>> In all other cases just use clojure.core/pr-str and the new
>> clojure.edn/read-string when reading it back.
>>
>> Just my 2 cents,
>> /thomas
>>
>> 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 [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.