On Jul 9, 2011, at 6:16 PM, Sean Corfield wrote:

> If I need a function to have something like the following signatures,
> what's the most idiomatic way to do it:
> 
> ([fn-arg str-arg vec-arg & others] ...)
> ([str-arg vec-arg & others] ...)
> 
> Background: several functions in clojure.java.jdbc are already
> variadic but as part of JDBC-6 I want to enable users to pass in an
> optional function to tweak the PreparedStatement before it is
> executed. My options seem to be ugly code to test types at the start
> of the argument lists or to add in optional keyword arguments at the
> end of the argument list (which still means processing the arguments
> and doing sort of type testing but which feels a bit cleaner).

Keywords args are a viable option, and they don't necessarily have to come at 
the end of the varargs. Type-testing feels really ugly and Perlish to me.

The only other options I see are to wrap the varargs in a vector, or to create 
two functions with different names. I don't think there's one "idiomatic" way 
to do it; it depends on your constraints and preferences.

-- 
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

Reply via email to