What I tend to do when I run into this situation is to split my function in
two and provide:
1. an API function that accepts the key/value pairs as named arguments -
per the library coding guidelines
2. an implementation function that accepts a map of args as its last
argument (and destructures it)
then the API function delegates to the implementation function:
(defn foo* "Do something" [a b {:keys [c d] :or {c 1 d "two"}}] ...)
(defn foo "Do something" {:arglists '([a b :c 1 :d "two"])} [a b & args]
(foo* a b args))
Internal functions call whichever version is easiest to use. The arglists
metadata on foo assists users of the library:
user=> (doc foo)
-------------------------
user/foo
([a b :c 1 :d "two"])
Do something
Sean
On Tue, Jun 18, 2013 at 3:52 AM, James Reeves <[email protected]> wrote:
> I somewhat disagree with the coding standards in certain cases. If you
> have a large number of options, you may find yourself creating the option
> map programmatically. In which case:
>
> (release-sharks 2 options)
>
> Is preferable to:
>
> (apply release-sharks 2 (apply concat options))
>
> - James
>
>
> On 18 June 2013 06:32, dmirylenka <[email protected]> wrote:
>
>> According, to the library coding standards, the first is better:
>>
>> (release-sharks 2 :laser-beams true) ; good
>> (release-sharks 2 {:laser-beams true}) ; bad
>>
>> http://dev.clojure.org/display/design/Library+Coding+Standards
>>
>>
>> On Tuesday, June 18, 2013 5:26:15 PM UTC+12, Omer Iqbal wrote:
>>>
>>> Hey folks,
>>>
>>> What'c considered more idiomatic when having multiple, optional
>>> arguments?
>>>
>>> (defn foo1 [a b & args]
>>> (let [opts (apply hash-map args]
>>> ...))
>>>
>>> or
>>>
>>> (defn foo2 [a b opts]
>>> ...)
>>>
>>>
>>> Cheers,
>>> Omer
>>>
>>>
>>> --
>> --
>> 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.
>>
>>
>>
>
> --
> --
> 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.
>
>
>
--
Sean A Corfield -- (904) 302-SEAN
An Architect's View -- http://corfield.org/
World Singles, LLC. -- http://worldsingles.com/
"Perfection is the enemy of the good."
-- Gustave Flaubert, French realist novelist (1821-1880)
--
--
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.