Might need some super-secret trickery https://github.com/JuliaLang/julia/issues/5276 https://github.com/JuliaLang/julia/issues/1639
On Wednesday, January 29, 2014 4:28:26 PM UTC-6, Mauro wrote: > > Good catch! But a quote-block and :() should be equivalent, right? Is > this a bug? > > The trouble is that my use-case, I have two lines of code and then the > :()-trick doesn't work anymore because it get translated into a > quote-block: > > julia> eval(:(x=1; module MO end)) > ERROR: invalid method definition: not a generic function > > On Wed, 2014-01-29 at 21:08, [email protected] <javascript:> wrote: > > The problem seems to have to do with it getting wrapped in a quote > block. > > > > ~~~ > > julia> quote module MO end end > > quote # none, line 1: > > $(Expr(:module, true, :MO, quote > > eval(x) = top(Core).eval(MO,x) > > eval(m,x) = top(Core).eval(m,x) > > end)) > > end > > > > julia> :(module MO end) > > :($(Expr(:module, true, :MO, quote > > eval(x) = top(Core).eval(MO,x) > > eval(m,x) = top(Core).eval(m,x) > > end))) > > > > julia> eval(quote module MO end end) > > ERROR: invalid method definition: not a generic function > > > > julia> eval(:(module MO end)) > > Warning: replacing module MO > > ~~~ > > > > > > On Wed, Jan 29, 2014 at 2:13 PM, Mauro <[email protected] <javascript:>> > wrote: > > > >> As far as I can tell, below macro is the identity-macro and works for > >> everything I tried but for module definitions. Why? In fact, I > >> struggle to get a module definition working within a macro. > >> > >> julia> macro id(ex) > >> :($(esc(ex))) > >> end > >> > >> julia> @id x=5 > >> 5 > >> julia> @id type MT end > >> > >> julia> @id module MO end > >> ERROR: invalid method definition: not a generic function > >> > >> Second example: > >> > >> macro typ(ex) # this works and produces type TY > >> :(esc(type TY end)) > >> end > >> > >> macro mod(ex) # this doesn't > >> :(esc(module MO end)) > >> end > >> > >> ERROR: syntax: malformed module expression > >> > >> Is there a way to define modules within macros? > >> > > -- > Sent with my mu4e > >
