Re: multi-arity functions with macros

2015-06-05 Thread Phillip Lord
Interesting -- it's certainly more generic than the solution that I have worked up. I'd need to add something for the variadic fall-back call. Thank you! Francis Avila writes: > This is exactly the approach to take: a macro which expands to a defn with > all your arities filled out. > > Here

Re: multi-arity functions with macros

2015-06-05 Thread Phillip Lord
Fluid Dynamics writes: >> (defn ^:private form-with-arity[n] >> ;; left as an exercise for the reader >> ) >> >> (defmacro ^:private m-default-ontology >> `(defn default-ontology >> ~@(map form-with-arity (range 1 10 >> >> (m-default-ontology) >> >> Or am I missing somethi

Re: multi-arity functions with macros

2015-06-04 Thread Francis Avila
This is exactly the approach to take: a macro which expands to a defn with all your arities filled out. Here's a simple approach which might be enough for your problem: it will splice in argument names whenever some marker symbol is encountered, and repeat for the range of arities you want. (

Re: multi-arity functions with macros

2015-06-04 Thread Fluid Dynamics
On Thursday, June 4, 2015 at 12:55:23 PM UTC-4, Phillip Lord wrote: > > > I have a number of fairly nasty functions with a form that looks like > this: > > (defn default-ontology > ([f] > (dispatch f)) > ([f a] > (dispatch f a)) > ([f a b] > (dispatch f a b)) > ([f a

multi-arity functions with macros

2015-06-04 Thread Phillip Lord
I have a number of fairly nasty functions with a form that looks like this: (defn default-ontology ([f] (dispatch f)) ([f a] (dispatch f a)) ([f a b] (dispatch f a b)) ([f a b c] (dispatch f a b c)) ([f a b c d] (dispatch f a b c d)) ([f a b c d e] (dispa