On Wednesday, June 4, 2014, Robert Feldt <[email protected]> wrote:
>
> Maybe something like Match.jl can be applied to match/transform Expr
> object ( http://matchjl.readthedocs.org/en/latest/ ) but I think there
> was something more adapted to Expr's...
>

FWIW, I was just wanting to use Match.jl for a similar purpose, and spent a
little time cleaning up the code and removing some silly inefficiencies.
It's about 10x faster at code generation now, and generates slightly
tighter code.

I'll try to add an example to the docs on matching Exprs.

I think I remember seeing a package with some metaprogramming tools (beyond
what's in Base.Meta), but I'm not in front of a computer relight now, so
it's a little hard to find.

Cheers,
   Kevin



>
>
>
>
>
> On Wed, Jun 4, 2014 at 1:33 PM, Ivar Nesje <[email protected]
> <javascript:_e(%7B%7D,'cvml','[email protected]');>> wrote:
>
>> @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] 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
>>>
>>> --
>>>
>>>
>
>
> --
> Best regards,
>
> /Robert Feldt
> --
> Tech. Dr. (PhD), Professor of Software Engineering
> Blekinge Institute of Technology, Software Engineering Research Lab, and
> Chalmers, Software Engineering Dept
> Explanea.com - Igniting your Software innovation
> robert.feldt (a) bth.se    or    robert.feldt (a) chalmers.se    or
>  robert.feldt (a) gmail.com
> Mobile phone: +46 (0) 733 580 580
> http://www.robertfeldt.net <http://www.cse.chalmers.se/~feldt>
>

Reply via email to