For whoever stumbles upon this issue: I "solved it" by escaping the whole expression
esc(:(function ...)) and manually gensym'ing in whatever I needed. Cédric On Monday, August 3, 2015 at 11:11:21 PM UTC-4, Cedric St-Jean wrote: > > Thank you for helping out again. > > It does work for $(map(esc, body)...), so it's probably a bug. I'll file > an issue if no one comes up with something better. > > On Monday, August 3, 2015 at 11:03:47 PM UTC-4, Yichao Yu wrote: >> >> On Mon, Aug 3, 2015 at 10:47 PM, Cedric St-Jean <[email protected]> >> wrote: >> > I'm trying to write a macro that takes up a function definition and >> outputs >> > another one. It starts like: >> > >> > macro mac(fdef) >> > @capture(fdef, begin function fname_ (args__) body__ end end) >> > :(function $(esc(fname)) ($(args...)) >> > ... end) >> > end >> > >> > Macrotools are very convenient for getting the args, but I have issues >> > putting them back into place. I thought it wouldn't matter if they were >> > gensym'ed, but it turns out that arguments like (x::SomeType) will have >> > SomeType resolved in the macro's environment, which is obviously wrong. >> > >> > So I need to escape hygiene. Something like $(esc(args)...), but that >> does >> > not work, as esc returns an Expr. I thought that $(map(esc, args)...) >> could >> > make sense, but it's complaining that: >> > >> > :($(Expr(:error, "\"(escape x)\" is not a valid function argument >> name"))) >> > >> > Enter code here... >> >> Seems that escape is not accepted in function arguments. Possibly a >> bug... >> >> > >> > which makes little sense to me. Any ideas? >> > >> > Cédric >> >
