|defsynth macro help (again)||Roger Allen||1/10/13 1:47 PM|
Last night, trying to get my single-string synth running with Leipzig, I realized I forgot to :action FREE the synth, so after a while there are too many synths and the server becomes overloaded.
So, I'm trying to conditionally add this free-ing to the macro that creates the synth & running into my own defmacro-fu limitations. If someone can look this over and help me, I'd really appreciate it...
Instead of trying to show the whole defmacro, I think I've created a smaller snippet that shows the issue.
(defmacro mmx [n t]
`(defsynth ~n 
(let [mxxx# (map #(let [t1# (first %)
t2# ~(if t '(first ~%) '(second ~%))]
(~'* t1# t2#))
[ [100 200] [300 400] ])]
(out 0 (sin-osc mxxx#)))))
this is just a made-up synth, I'm not even sure it will make a sound in the end. The interesting bit here is the my attempt to set t2# to either "(first %)" or "(second %)" based on the macro input t. I can't seem to escape things right to get that "%" to make it through the macro expansion process. Here is the output of (macroexpand-1 '(mmx foo false)):
(let [mxxx__18010__auto__ (map
(second ~p1__18009#)] ;; desire this to be "(second %)]"
[[100 200] [300 400]])]
(out 0 (sin-osc mxxx__18010__auto__))))
I've tried a variety of escapes and nothing seems to help...does anyone understand what I'm doing wrong here?
Thanks in advance!
p.s. On the off chance someone wants to look at the actual code in progress, here is a gist with the code in question highlighted.
|Re: defsynth macro help (again)||Tcepsa||1/10/13 1:51 PM|
This probably reflects my own naivete, but what happens when you take away the tilde from in front of the % symbol?--Joel
|Re: defsynth macro help (again)||Roger Allen||1/10/13 2:33 PM|
line in question changes to (second p1__18009#)]
|Re: defsynth macro help (again)||Sam Aaron||1/10/13 2:56 PM|
does this do what you wanted:
(let [mxxx# (map (fn [params#] (let [t1# (first params#)
t2# (if t (first params#) (second params#))]
(~'* t1# t2#)))
[ [100 200] [300 400] ])]I essentially moved the anonymous fn to the more explicit variant - which allowed me to give it a gensymed arg param.
|Re: defsynth macro help (again)||Roger Allen||1/10/13 3:31 PM|
Yeah, getting rid of the #() reader macro should make this easier...hopefully!
I believe that makes the params# work, but it leaves the if statement wrapper. I'm trying to make that if statement disappear with the ~escape and only leave either (first param#) or (second param#) assigned to t2# depending on the setting of t.
If I add back the ~ before the if, it fails compilation...trying to add more escapes isn't bearing fruit for me...
|Re: defsynth macro help (again)||Roger Allen||1/10/13 7:37 PM|