Re: options for a function
Jonas, Thanks for pushing this out so quickly. We're using it now and it works fine. On Feb 23, 12:32 am, Jonas jonas.enl...@gmail.com wrote: * Quote only when necessary (this is the default) This default is very handy. Michael -- 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
Re: options for a function
I don't know that there is necessarily a recommended way to offer options. Sometimes people want keyword options, sometime the want to take options as a map, sometimes they need to do it one way or another for various reasons, sometime they do it one way and later learn of a better way. To take options in the way you have specified, you can use destructuring to simplify: (defn write-csv [writer data {:as opts}] ...) - or - (defn write-csv [writer data {:keys [separator quote ...]}] ...) - or - (defn write-csv [writer data {:keys [separator quote ...] :as opts}] ...) On Wed, Feb 22, 2012 at 3:47 PM, Michael michael-a...@db.com wrote: clojure.data.csv has options for the following: (defn write-csv Writes data to writer in CSV-format. Valid options are :separator (Default \\,) :quote (Default \\\) :guote? (A predicate function which determines if a string should be quoted. Defaults to quoting only when necessary.) :newline (:lf (default) or :cr+lf) [writer data options] (let [opts (into {} options) separator (or (:separator opts) \,) quote (or (:quote opts) \) quote? (or (:quote? opts) #(some #{separator quote \return \newline} %)) newline (or (:newline opts) :lf)] snip Since (into {} options) is used to get the options into a map, it seems that you need to specify options in this (write-csv writer data [:separator \;] [:newline :lf+cr]). Is this the recommended way to offer options? I was expecting (write- csv writer data :separator \; :newline :lf+cr). -- 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
Re: options for a function
This seems like a bug in clojure.data.csv and someone should create a JIRA ticket for it, perhaps with a patch? http://dev.clojure.org/jira/browse/DCSV This once again makes me question why this CSV library ended up in contrib (without any discussion) rather than the more actively maintained and widely used clojure-csv library by David Santiago - https://github.com/davidsantiago/clojure-csv On Wed, Feb 22, 2012 at 1:17 PM, Mark Rathwell mark.rathw...@gmail.com wrote: I don't know that there is necessarily a recommended way to offer options. Sometimes people want keyword options, sometime the want to take options as a map, sometimes they need to do it one way or another for various reasons, sometime they do it one way and later learn of a better way. To take options in the way you have specified, you can use destructuring to simplify: (defn write-csv [writer data {:as opts}] ...) - or - (defn write-csv [writer data {:keys [separator quote ...]}] ...) - or - (defn write-csv [writer data {:keys [separator quote ...] :as opts}] ...) On Wed, Feb 22, 2012 at 3:47 PM, Michael michael-a...@db.com wrote: clojure.data.csv has options for the following: (defn write-csv Writes data to writer in CSV-format. Valid options are :separator (Default \\,) :quote (Default \\\) :guote? (A predicate function which determines if a string should be quoted. Defaults to quoting only when necessary.) :newline (:lf (default) or :cr+lf) [writer data options] (let [opts (into {} options) separator (or (:separator opts) \,) quote (or (:quote opts) \) quote? (or (:quote? opts) #(some #{separator quote \return \newline} %)) newline (or (:newline opts) :lf)] snip Since (into {} options) is used to get the options into a map, it seems that you need to specify options in this (write-csv writer data [:separator \;] [:newline :lf+cr]). Is this the recommended way to offer options? I was expecting (write- csv writer data :separator \; :newline :lf+cr). -- 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
Re: options for a function
I'll fix this today. Thanks, Jonas -- 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
Re: options for a function
I just pushed the fix to github and released version 0.1.2. Sorry for the inconvenience. I'm not really happy with the write part of data.csv. In the clojure spirit of simplicity it complects quoting of values with writing to disk. There might be different policies for when an api-user wants there values to be quoted: * Quote everything (this can be done by setting :quote? to (constantly true) * Quote nothing (this can be done by setting :quote? to (constantly false)) * Quote only when necessary (this is the default) * Quote only the first row (i.e,, header) * Quote (for example) the first and third column * etc. I thought about this a couple of days ago and the best I could come up with was to remove quoting from the writing part and have users quote there values as a pre-processing step before writing. If that is the way forward then there is almost nothing more to do in the writing part of the data.csv, e.g., you could just as well write (with-open [w (io/writer some-file)] (with-binding [*out* w] (doseq [row data] (println (string/join , row))) So It's not entirely clear to me if csv-write is needed at all and instead have a few helper functions, for example (quote-string s \'), together with a good description of how to use with-binding, doseq, str/join etc. in the README file. Ideas welcome. Jonas -- 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