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 <[email protected]> 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 [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 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