Sharing optional arguments among functions

67 views
Skip to first unread message

Adam Krieg

unread,
Mar 17, 2014, 10:41:01 AM3/17/14
to clo...@googlegroups.com
I'm trying to define a couple of functions that support the same options, but return different return types.

I have one function that is the "base" function that provides the most raw access, and some other functions that call this base function and do their thing.

I would like to make these keyword args available to all of these functions, but I'm unsure how to do this.

e.g.

(defn base-fun[& {:keys [num-responses timeout] :or {:num-responses 1 :timeout 5000}}]
  num-responses)

(defn other-fun[required-arg & opts]
  (base-fun opts))


(other-fun "fred" :num-responses 4) ;IllegalArgumentException No value supplied for key: (:num-responses 4) 

Is there a way to define common keyword args among functions? 

Luc Prefontaine

unread,
Mar 17, 2014, 11:08:38 AM3/17/14
to clo...@googlegroups.com
Use (apply base-fun opts)

Luc P.
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clo...@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+u...@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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+u...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>
--
Luc Prefontaine<lprefo...@softaddicts.ca> sent by ibisMail!

Adam Krieg

unread,
Mar 17, 2014, 11:50:56 AM3/17/14
to clo...@googlegroups.com
Thanks, Luc!
> You received this message because you are subscribed to a topic in the Google Groups "Clojure" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/clojure/WGHkr5UvrKQ/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to clojure+u...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages