Working around var-args with keywords

I’m working with incanter, but the pattern I’m concerned with is more general. Incanter has macros that takes args like this:

(charts/function-plot fn 0 num-points
                            :legend true
                            :series-label "Good conversations"
                            :x-label "Conversation Turn"
                            :y-label "Distance")

The problem is those keyword-value pairs, which are not encoded as a map. I can’t wrap this structure in a function that could optionally take a map of args like that (with ;legend, :x-label, etc). Is there some way I COULD transform a map into an unwrapped bunch of keyword/val like that? I’ve been hoping to get at it with combination of partial and eval, but that is further stopped by the fact that function-plot is a macro, not a function, so it can’t play with some higher-level functions.

For functions:

(apply f (apply concat {:a 1 :b 2}))
(apply f (into [] cat {:a 1 :b 2}))

For macros… without introducing another macro, you’re out of luck (though I guess I see no reason not to introduce one). You’ll have to write something like :legend (:legend m) for every kwarg. Are you sure the same interface isn’t exposed as functions somewhere? Incanter does provide the corresponding function-plot* fn (to which the macro expands to), though I don’t know the details of exactly how you have to invoke it

1 Like

Would medley's mapply work for you?

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.