@mauro I think there is a single function that combines map and reduce <http://docs.julialang.org/en/release-0.2/stdlib/base/#Base.mapreduce>. Also it seems like parse(string(ex_funcs...)) would do the same job.
What about instead enclosing them in a block expression? I'm not sure I understand what you try to do, but this seems to work: *eval(Expr(:block, ex_funcs[1:2]...))* *eval(Expr(:block, ex_funcs...))* Ivar kl. 13:14:09 UTC+2 onsdag 4. juni 2014 skrev Mauro følgende: > > This works: > parse(reduce(*, map(string, ex_funcs))) > > as was suggested in this thread for symbols: > https://groups.google.com/d/msg/julia-dev/KJNOrV45sZo/zE2_fVzQrS4J > > Still seems a bit ugly. Any better ways? > > On Wed, 2014-06-04 at 08:58, [email protected] <javascript:> wrote: > > In a macro I need to first define a large number of functions and then > > merge them into one block and return that as the code from the macro. Is > > there a simpler/smarter way than what I currently do, which is based on > > explicitly adding > > > > using Base.Test > > > > # We want to find a way to merge the definition of two (or more) quoted > > function > > # bodies into one quoted expression. > > > > ex_a = quote > > function a() > > b() > > end > > end > > > > ex_b = quote > > function b() > > 2 > > end > > end > > > > ex_c = quote > > function b() > > c() > > end > > function c() > > 3 > > end > > end > > > > ex_funcs = [ex_a, ex_b, ex_c] > > > > function concat_expr_blocks(a, b) > > args = a.args > > for barg in b.args > > push!(a.args, barg) > > end > > a > > end > > > > function concat_expr_blocks(blocks) > > ex = blocks[1] > > for i in 2:length(blocks) > > ex = concat_expr_blocks(ex, blocks[i]) > > end > > ex > > end > > > > eval(concat_expr_blocks(ex_funcs[1:2])) > > @test a() == 2 > > eval(concat_expr_blocks(ex_funcs)) > > @test a() == 3 > > > > Thanks for any pointers. I'm sure there is an obvious way but I can't > see > > it right now... ;) > > > > Regards, > > > > Robert > > -- > >
