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] 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

-- 

Reply via email to